GetAsyncKeyState() "key pressed"

This is a discussion on GetAsyncKeyState() "key pressed" within the C++ Programming forums, part of the General Programming Boards category; hello, when you press a key you can use the GetAsyncKeyState(); function, but how do i do if i wan't ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    33

    Question GetAsyncKeyState() "key pressed"

    hello, when you press a key you can use the
    GetAsyncKeyState();
    function, but how do i do if i wan't to get the key you havé pressed
    Code:
    if (Getapressedkey(vk_shift)) // code dosent work.
    {
    cout << "you have pressed on shift";
    }

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    2
    The proper way to use GetAsyncKeyState is to BitAND the return value with 0x8000.

    Code:
    if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
    {
       // The key is currently down
    }
    You can also get a list of key states by calling GetKeyboardState.

    Code:
    unsigned char KeyStates[256];
    GetKeyboardState(KeyStates);
    
    for (int i = 0; i < 256; i++)
    {
          if (KeyStates[i] & 0x8000)
          {
                // The keyboard key that 'i' represents is currently held down.
          }
    }

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    33
    thx you, worked it ;D

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetAsyncKeyState Problem
    By kevinawad in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2008, 06:00 PM
  2. Problems with cin and GetAsyncKeyState
    By KgNe in forum C++ Programming
    Replies: 32
    Last Post: 08-21-2008, 11:00 AM
  3. Infinite Loop with GetAsyncKeyState
    By guitarist809 in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2008, 01:09 PM
  4. Problems with GetAsyncKeyState
    By blurrymadness in forum C++ Programming
    Replies: 13
    Last Post: 04-21-2007, 07:13 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21