Results 1 to 10 of 10

Thread: [RESOLVED] [2008] Show symbol for USB Num-Pad

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    16

    Resolved [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

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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?
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    16

    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!

  4. #4
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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?
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    16

    Re: [2008] Show symbol for USB Num-Pad

    So windows sees all connected keyboards as one, no matter what it is.
    Thanks

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    16

    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.

  7. #7
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    16

    Re: [2008] Show symbol for USB Num-Pad

    Okay. I completed it

    And it is so simple
    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

    Greetz PhilX

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    16

    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.

  10. #10
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width