C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-05-2009, 02:37 PM   #1
Registered User
 
Join Date: Feb 2009
Posts: 22
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";
}
vrkiller is offline   Reply With Quote
Old 03-06-2009, 12:54 PM   #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.
      }
}
chris95219 is offline   Reply With Quote
Old 03-06-2009, 05:22 PM   #3
Registered User
 
Join Date: Feb 2009
Posts: 22
thx you, worked it ;D
vrkiller is offline   Reply With Quote
Reply

Tags
getasynckeystate(), noob, pressed, vrkiller

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GetAsyncKeyState Problem kevinawad C++ Programming 1 11-07-2008 06:00 PM
Problems with cin and GetAsyncKeyState KgNe C++ Programming 32 08-21-2008 10:00 AM
Infinite Loop with GetAsyncKeyState guitarist809 Windows Programming 1 04-18-2008 12:09 PM
Problems with GetAsyncKeyState blurrymadness C++ Programming 13 04-21-2007 06:13 PM


All times are GMT -6. The time now is 04:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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