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. Whether 'Control' Key is pressed ?

Whether 'Control' Key is pressed ?

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
3 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.
  • N Offline
    N Offline
    nilaysoft
    wrote on last edited by
    #1

    I response the WM_KEYDOWND message to shift my view if the arrow keys are pressed, while the moving speed should be faster if Control key is pressed simultaneously. This line of code is used:

    case VK_LEFT:
    case VK_RIGHT:
    if (GetKeyState(VK_CONTROL) == -128 || GetKeyState(VK_CONTROL) == -127)
    {
    // Do somthing here.
    }

    I do think there should exist a better way than this stupid one, do you know that?

    L M 2 Replies Last reply
    0
    • N nilaysoft

      I response the WM_KEYDOWND message to shift my view if the arrow keys are pressed, while the moving speed should be faster if Control key is pressed simultaneously. This line of code is used:

      case VK_LEFT:
      case VK_RIGHT:
      if (GetKeyState(VK_CONTROL) == -128 || GetKeyState(VK_CONTROL) == -127)
      {
      // Do somthing here.
      }

      I do think there should exist a better way than this stupid one, do you know that?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I think the code can't work.Unlike "shift" key,you can't catch the "control" key in the WM_KEYDOWN.You should handle it in PreTranslateMessage(). //Do the Ctrl+A action BOOL C***::PreTranslateMessage(MSG* pMsg) { if( pMsg->message == WM_KEYDOWN ) { int vkey = pMsg->wParam; if( vkey == 'A' ) { if( GetKeyState( VK_CONTROL ) & 0x8000 ) SelectAll(); } } return CBase***::PreTranslateMessage( pMsg ); } Chreers

      1 Reply Last reply
      0
      • N nilaysoft

        I response the WM_KEYDOWND message to shift my view if the arrow keys are pressed, while the moving speed should be faster if Control key is pressed simultaneously. This line of code is used:

        case VK_LEFT:
        case VK_RIGHT:
        if (GetKeyState(VK_CONTROL) == -128 || GetKeyState(VK_CONTROL) == -127)
        {
        // Do somthing here.
        }

        I do think there should exist a better way than this stupid one, do you know that?

        M Offline
        M Offline
        Mustafa Demirhan
        wrote on last edited by
        #3

        Use GetAsyncKeyState instead... Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

        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