Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What is the code for the AsyncKeyState function?

What is the code for the AsyncKeyState function?

Scheduled Pinned Locked Moved C / C++ / MFC
questionjson
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Coolarj10
    wrote on last edited by
    #1

    In the Win32 API (or atleast I think it's in the Win32 API), the AsyncKeyState function can be used to see if a keyboard button is pressed. Does anyone know the code for the buttons on the keyboard? I arleady know that the arrow keys are VK_UP, VK_DOWN, VK_LEFT, and VK_RIGHT, and the "Enter" button is VK_RETURN. Thanks!

    H 1 Reply Last reply
    0
    • C Coolarj10

      In the Win32 API (or atleast I think it's in the Win32 API), the AsyncKeyState function can be used to see if a keyboard button is pressed. Does anyone know the code for the buttons on the keyboard? I arleady know that the arrow keys are VK_UP, VK_DOWN, VK_LEFT, and VK_RIGHT, and the "Enter" button is VK_RETURN. Thanks!

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Constants like these are defined in the headers that are installed with VC++. If you find, for example, VK_UP then you can see all the others. They are defined in winuser.h and documented at http://msdn.microsoft.com/library/en-us/winui/winui/WindowsUserInterface/UserInput/VirtualKeyCodes.asp[^]. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

      C 1 Reply Last reply
      0
      • H Heath Stewart

        Constants like these are defined in the headers that are installed with VC++. If you find, for example, VK_UP then you can see all the others. They are defined in winuser.h and documented at http://msdn.microsoft.com/library/en-us/winui/winui/WindowsUserInterface/UserInput/VirtualKeyCodes.asp[^]. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

        C Offline
        C Offline
        Coolarj10
        wrote on last edited by
        #3

        I see. But what about the letter keys. All the list says is, for example: (48) H Key; (4D) M Key How would you use that in code when trying to do something like this: if (GetAsyncKeyState(VK_LEFT) < 0) { //result of key press here } Instead of using VK_LEFT, how would I use the letter "M" or the letter "H"? Thanks again!

        H 1 Reply Last reply
        0
        • C Coolarj10

          I see. But what about the letter keys. All the list says is, for example: (48) H Key; (4D) M Key How would you use that in code when trying to do something like this: if (GetAsyncKeyState(VK_LEFT) < 0) { //result of key press here } Instead of using VK_LEFT, how would I use the letter "M" or the letter "H"? Thanks again!

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          (48) H is an example of the value of the constant. All the VK_* are is constants defined for a particular value. I suppose Microsoft didn't think it was necessary to define VK constants for printable ASCII characters, especially since the values are the same as the ASCII character code. So, the key constant for "A" is 0x41 (65), as well as the ASCII value. This makes it easy to translate key codes to printable ASCII characters. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups