[RESOLVED] [2008] Show symbol for USB Num-Pad
Hi,
I bought an usb num-pad for my notebook. The problem is that I don't see if I have activated/deactivated the numlock. Where do I have to start to get the information that the numlock of that usb num-pad was pressed? Better would be how do I get the information which keys are pressed?
Thanks
Philx
Re: [2008] Show symbol for USB Num-Pad
Ahh, so your numpad has a Numlock key and your laptop has no light/indicator to show it on/off?
I assume you want this program to be something that quietly runs in the background, perhaps in the system tray and changes maybe the tray-icon and/or pop a notification when the status changes?
Re: [2008] Show symbol for USB Num-Pad
Yes, the nor the numpad and the laptop have a light to show it numlock is activated or not.
Quote:
I assume you want this program to be something that quietly runs in the background, perhaps in the system tray and changes maybe the tray-icon and/or pop a notification when the status changes?
exactly! :)
Re: [2008] Show symbol for USB Num-Pad
It's a trickier problem than you may think since you're asking a program to intercept the keyboard. Windows only ever sees one keyboard. Even if you physically have 3 USB keyboards plugged into a computer, if you type "hello" on all three, you'd get three "hello"s on the screen, but as far as Windows is concerned, they all came from "THE Keyboard". It makes no distinction as to which one.
That said, it's entirely possible to do in VB.NET. The first thing you'd need to do is set up a low-level keyboard hook. This is done with some Windows API manipulation. Basically, this is the part that is intercepting the keypresses.
Next, you tie it into your program and have it check what keys are being pressed. When a certain key (like the NumLock) key is hit, you trigger an event that gives the notification you want.
First step is to establish the keyboard hook. Once you have got that working and maybe something simple like a messagebox is popping up, then you worry about giving it a fancy, unobtrusive notification. :)
That's "how" you'd do it anyways. Any questions? :)
Re: [2008] Show symbol for USB Num-Pad
So windows sees all connected keyboards as one, no matter what it is.
Thanks :D
Re: [2008] Show symbol for USB Num-Pad
Okay. I got that:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim value As Boolean = My.Computer.Keyboard.NumLock
If value = True Then
NotifyIcon1.Visible = True
NotifyIcon2.Visible = False
Else
NotifyIcon1.Visible = False
NotifyIcon2.Visible = True
End If
End Sub
But how to refresh when the key is pressed?
Thanks
Re: [2008] Show symbol for USB Num-Pad
You could start a timer and check it on an interval... or better yet, start a loop and sleep for a half-second or so between checks.
Actually, you are lucky, I forgot that you could report status of the three togglekeys like that. It'll work for the numlock and be much easier than a keyboard hook. :D
Re: [2008] Show symbol for USB Num-Pad
Okay. I completed it :D
And it is so simple :thumb:
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim value As Boolean = My.Computer.Keyboard.NumLock
If value = True Then
NotifyIcon1.Visible = True
NotifyIcon2.Visible = False
Else
NotifyIcon1.Visible = False
NotifyIcon2.Visible = True
End If
End Sub
I added a timer with Interval = 100 and created 2 icons. One for each state (On/Off). For the Form one: Show in Taskbar = False
That's all !!
Thanks to Jenner :D
Greetz PhilX
Re: [RESOLVED] [2008] Show symbol for USB Num-Pad
I wonder if that works on xp too, because I tried it on my XP and it didn't work. (I have a modified XP to work fast on an Acer Aspire 110, maybe that's the reason why it didn't work...)
Edit:
It doesn't work on Vista too. It shows the status of the Numlock when I use they key on the keyboard or on the notebook, but nothing happens when I use the USB Numpad... :-(
Re: [RESOLVED] [2008] Show symbol for USB Num-Pad
No prob! Be sure to mark the thread RESOLVED in the "Thread Tools" menu at the top and click "Rate" in the bottom left of any posters who you thought were useful to add to their rep. It's standard courtesy on these forums. :)
It should work on XP. Just make sure you have the .NET framework installed.