|
-
Sep 24th, 2008, 12:52 PM
#1
Thread Starter
Junior Member
[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
-
Sep 24th, 2008, 12:57 PM
#2
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?
-
Sep 24th, 2008, 01:01 PM
#3
Thread Starter
Junior Member
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.
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!
-
Sep 24th, 2008, 01:15 PM
#4
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?
-
Sep 24th, 2008, 01:28 PM
#5
Thread Starter
Junior Member
Re: [2008] Show symbol for USB Num-Pad
So windows sees all connected keyboards as one, no matter what it is.
Thanks
-
Sep 24th, 2008, 02:47 PM
#6
Thread Starter
Junior Member
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
Last edited by PhilX; Sep 24th, 2008 at 02:52 PM.
-
Sep 24th, 2008, 04:08 PM
#7
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.
-
Sep 25th, 2008, 06:45 AM
#8
Thread Starter
Junior Member
Re: [2008] Show symbol for USB Num-Pad
-
Sep 25th, 2008, 07:25 AM
#9
Thread Starter
Junior Member
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... :-(
Last edited by PhilX; Sep 25th, 2008 at 07:33 AM.
-
Sep 25th, 2008, 07:27 AM
#10
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|