Jump to content
  • Advertisement


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


hold back key

This topic is 6211 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

I don''t know how kan I make my heros move light. I just want to know how can I understand if key is press. Not to write from Keyboard buffer and wait 1/4 sec after first read from buffer. QBASIC, PASCAL, C, C++, VB, PERL,

Share this post

Link to post
Share on other sites
In C++, define these two macros at the top of the file:

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 :0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

IMPORTANT- make sure that each macro fits onto 1 line.

Also make sure that you include:
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <stdio.h>// i'm not sure if you actually need
#include <stdlib.h>// these last 3
#include <math.h>

then you can test for certain specific keys,
such as:
if (KEYDOWN(VK_UP )) {
//move character up
if (KEYUP(VK_UP)) {
// user released the up key
This only works for keys such as VK_SPACE, VK_RETURN, VK_F1, VK_UP, VK_DOWN, etc. (special keys). It doesnt work for regular keys like "a" or "b" I'm not actually sure how to do that. If anyone knows I would appreciate that.

Hope this helps


Edited by - GameDev135 on August 14, 2001 12:30:54 PM

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!