Archived

This topic is now archived and is closed to further replies.

Key Pressed macro

This topic is 5536 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is what I have so far #define KEY_DOWN( vk_code ) ( ( GetAsyncKeyState( vk_code ) & 0x8000 ) ? 1 : 0 ) #define KEY_UP( vk_code ) ( ( GetAsyncKeyState( vk_code ) & 0x8000 ) ? 0 : 1 ) Which I got from lamothe''s book, but I''m wondering how to do a key pressed macro, so it only detects if a key has been pushed once.

Share this post


Link to post
Share on other sites
GetAsyncKeyState also returns whether the key has been pressed since the last call to the function, although the number of times it has been pressed isn''t.

The obvious answer would be to process the WM_KEYUP/WM_KEYDOWN message that occured when you pushed the key...

Jans.

Share this post


Link to post
Share on other sites
The search feature doesn''t work, so I searched manually 10 pages back, with no luck.

Then I did some google searches, but all examples are on how to use getasynckeystate for a key being pressed, not pressed once.

Then I just played around and came up with this


  
//F3

if( KEY_DOWN( VK_F3 ) ) F3 = true;
if( KEY_UP( VK_F3 ) && F3 )
{
F3 = false;
}


Don''t know if this is best way to do it, but it works none the less.

Share this post


Link to post
Share on other sites