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. Pressing Arrow Key

Pressing Arrow Key

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 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.
  • R Offline
    R Offline
    Rajveer
    wrote on last edited by
    #1

    How do I check to see if the key being pressed is the up, down, left or right arrow key? i.e. to check if "I" is pressed, I do this: void CChildFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CMDIChildWnd::OnKeyDown(nChar, nRepCnt, nFlags); char keypressed = char(nChar); if(keypressed == 'I') //Do stuff } but what do I write in the if statement to check for an arrow key?

    N P R 3 Replies Last reply
    0
    • R Rajveer

      How do I check to see if the key being pressed is the up, down, left or right arrow key? i.e. to check if "I" is pressed, I do this: void CChildFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CMDIChildWnd::OnKeyDown(nChar, nRepCnt, nFlags); char keypressed = char(nChar); if(keypressed == 'I') //Do stuff } but what do I write in the if statement to check for an arrow key?

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      You can use VK_LEFT, VK_UP, VK_RIGHT and VK_DOWN Nish


      The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?

      1 Reply Last reply
      0
      • R Rajveer

        How do I check to see if the key being pressed is the up, down, left or right arrow key? i.e. to check if "I" is pressed, I do this: void CChildFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CMDIChildWnd::OnKeyDown(nChar, nRepCnt, nFlags); char keypressed = char(nChar); if(keypressed == 'I') //Do stuff } but what do I write in the if statement to check for an arrow key?

        P Offline
        P Offline
        Paul M Watt
        wrote on last edited by
        #3

        You can find all of the other lookup codes in MSDN by looking up Virtual Key Codes.


        Build a man a fire, and he will be warm for a day
        Light a man on fire, and he will be warm for the rest of his life!

        1 Reply Last reply
        0
        • R Rajveer

          How do I check to see if the key being pressed is the up, down, left or right arrow key? i.e. to check if "I" is pressed, I do this: void CChildFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default CMDIChildWnd::OnKeyDown(nChar, nRepCnt, nFlags); char keypressed = char(nChar); if(keypressed == 'I') //Do stuff } but what do I write in the if statement to check for an arrow key?

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

          You may need to handle the arrow keys in the PreTranslateMessage function which you can override.

          if (pMsg->message == WM_KEYDOWN)
          {
          switch (pMsg->wParam)
          {
          case VK_UP :
          case VK_DOWN :
          case ...
          }
          }

          you should return TRUE if you dont want te message to be processed further, or pass the message through to the base class to allow it to be processed by controls as normal. Roger Allen Sonork 100.10016 yet to be identified being from the planet Paltinmoriumbanfrettybooter

          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