Jump to content
  • Advertisement


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


Key Pressed macro

This topic is 5822 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...


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


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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!