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. C++ Arrow Keys

C++ Arrow Keys

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
4 Posts 3 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
    c s
    wrote on last edited by
    #1

    For a windows program I am making I need to detect arrow key presses. Now I have a switch statement: switch(nChar) { case VK_DOWN: // do stuff break; case VK_RIGHT ... } but I need to detect if multiple arrow keys are being pressed at once, how can I do this? (my OnKeyDown handler no longer does anything when a key is pressed. I'm not sure but it might be it doesn't have the focus, though I actually have no idea. Any ideas on that?) Any help is greatly appreciated. Thanks.

    P R 2 Replies Last reply
    0
    • C c s

      For a windows program I am making I need to detect arrow key presses. Now I have a switch statement: switch(nChar) { case VK_DOWN: // do stuff break; case VK_RIGHT ... } but I need to detect if multiple arrow keys are being pressed at once, how can I do this? (my OnKeyDown handler no longer does anything when a key is pressed. I'm not sure but it might be it doesn't have the focus, though I actually have no idea. Any ideas on that?) Any help is greatly appreciated. Thanks.

      P Offline
      P Offline
      palbano
      wrote on last edited by
      #2

      >> I need to detect if multiple arrow keys are being pressed at once, how can I do this? Reading the documentation is always the place to start http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/KeyboardInput/KeyboardInputReference/KeyboardInputMessages/WM_KEYDOWN.asp[^]

      "No matter where you go, there your are." - Buckaroo Banzai

      -pete

      C 1 Reply Last reply
      0
      • P palbano

        >> I need to detect if multiple arrow keys are being pressed at once, how can I do this? Reading the documentation is always the place to start http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/KeyboardInput/KeyboardInputReference/KeyboardInputMessages/WM_KEYDOWN.asp[^]

        "No matter where you go, there your are." - Buckaroo Banzai

        -pete

        C Offline
        C Offline
        c s
        wrote on last edited by
        #3

        I have taken a look at that, but this time I noticed I need to give my view the keyboard focus (how can I do this?). Thanks. Though I'm still not sure how to detect multiple arrow key presses at once, I tried getting the flags with "ah 12h, int 16h" but that only returns flags that hold shift,ctrl,insert,etc. So how do I detect that two (or more) arrow keys are being pressed at once?

        1 Reply Last reply
        0
        • C c s

          For a windows program I am making I need to detect arrow key presses. Now I have a switch statement: switch(nChar) { case VK_DOWN: // do stuff break; case VK_RIGHT ... } but I need to detect if multiple arrow keys are being pressed at once, how can I do this? (my OnKeyDown handler no longer does anything when a key is pressed. I'm not sure but it might be it doesn't have the focus, though I actually have no idea. Any ideas on that?) Any help is greatly appreciated. Thanks.

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          Take a look at the function GetKeyState(VK_DOWN), should return the state of the key, pressed or not etc. You will need to call it once for each key you want to check. If you vote me down, my score will only get lower

          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