How to differentiate between specific keys?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adwenger0066
    New Member
    • Aug 2010
    • 4

    How to differentiate between specific keys?

    I'm trying to find out methods on how to figure out which key was pressed. For Windows forms, the KeyDown event is what I am looking at, but there is a problem.

    When a user presses the number 4 on the number pad, it can return either NumPad4 or Left. Normally, I could just listen for either, but I also want the Left Arrow to function differently.

    Is there a way I can just tell which key was pressed without having to resort to Invokes or Visual Basic code?
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    Try looking at the KeyUp event instead, you may find it behaves more to what your looking for.

    Aimee.

    Comment

    • MrMancunian
      Recognized Expert Contributor
      • Jul 2008
      • 569

      #3
      Perhaps you can use the GetKeyState Function to check if NumLock is active? If so, 4 was pressed, if not, Left Arrow was pressed :-)

      Steven

      Comment

      • carolyny476
        New Member
        • Aug 2010
        • 1

        #4
        Such a very amazing link!
        Thanks MrMancunian for the post.

        _______________ ___
        <link removed>
        Last edited by Frinavale; Aug 31 '10, 06:35 PM. Reason: Link removed: Spam is not tolerated on this forum.

        Comment

        • adwenger0066
          New Member
          • Aug 2010
          • 4

          #5
          I will take a look at the KeyUp event, but I think it operates the same way.

          The problem with checking the KeyState on numlock is that I also want to use the arrow keys for some in the form. So if the numlock is off, I still need to know whether the user pressed the arrow key, or the numpad arrow key.

          For now, I've decided to use a different control method, using the WASD keys and the arrow keys.

          Comment

          Working...