View Full Version : ahhh help....rapid keypress detection
technoXavage
12-18-2003, 11:02 AM
how do i detect rapid keypresses?? If i put a variable within the if (keypress) and let it increment so that when it reach lets say 10 the thrust sound starts to kick in....once i let go even wif a single tap the thrust sound kicks in.....how do i go about this??need help fast 15 hrs to submission
Bubba
12-18-2003, 01:00 PM
Err....uh.....is this for DirectX or what?
If you are using the Windows GDI then its not a mystery why you are having this problem.
If you are using DirectX, look at the following code:
#include "dinput.h"
#include <objbase.h>
#define INITGUID
//Set objects to null
LPDIRECTINPUT lpdi=NULL;
IDIRECTINPUTDEVICE lpdikey=NULL;
//Create DirectInput object - get interface
if (FAILED(DirectInputCreate(main_instance,DIRECTINPU T_VERSION,&lpdi,NULL))
{ //error }
//Create DirectInput device
if (FAILED(lpdi->CreateDevice(GUID_SysKeyboard,&lpdikey,NULL))
{ //error }
//Set cooperative level
if (FAILED(lpdikey->SetCooperativeLevel(main_window_handle,DISCL_BACKG ROUND | DISCL_NONEXCLUSIVE)) {//error}
//Keystate array
typedef _DIKEYSTATE UCHAR[256];
//Set data format to keyboard
if (FAILED(lpdikey->SetDataFormat(&c_dfDIKeyboard))) {//error}
//Acquire the keyboard
if (FAILED(lpdikey->Acquire())) {//error}
//Get info from the keyboard
if (FAILED(lpdikey->GetDeviceState(sizeof(_DIKEYSTATE),(LPVOID)keystat e))) {//error}
//Test for key down
if (keystate[DIK_ESCAPE] & 0x80)
{
//down
}
else
{
//up
}
//Could also use this macro for keydown
#define DIKEYDOWN(data,n) (data[n] &0x80)
This sets up the DirectInput object, Keyboard object, and shows how to test keys. It comes directly from Andre Lamothe's book, Tricks of the Windows Game Programming Gurus.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.