hold back key
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,
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
Dan
Edited by - GameDev135 on August 14, 2001 12:30:54 PM
#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
Dan
Edited by - GameDev135 on August 14, 2001 12:30:54 PM
Feel free to email me at NYYanks432@hotmail.com if you have any questions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement