I've seen a lot of people with questions about why clicking or pressing a key makes their game zoom by real fast.
So, here are the functions I use to detect
single keytaps and clicks. That means holding down the key or mouse button will not continue to make your game do backflips.
bSingleClick():
// the parameter iBtn is the mouse button to check:
// 1: LEFT 2: RIGHT 3: BOTH
// See documentation on dbMouseClick() for more details.
// returns true if a single click is detected.
bool bSingleClick(int iBtn){
static bool bBtnDwn = false;
if(dbMouseClick()!=iBtn)
{
bBtnDwn = false;
}
if(dbMouseClick()==iBtn&&!bBtnDwn)
{
bBtnDwn = true;
return true;
}
return false;
}
bKeyTap():
/* returns true if a key is pressed, holding key has no further effect.*/
bool bKeyTap(int iScanCode)
{
static bool keyDown = false;
if(dbScanCode()!=iScanCode)
{
keyDown = false;
}
if(dbScanCode() ==iScanCode && keyDown == false)
{
keyDown = true;
return true;
}
return false;
}
And for those of you trying to figure out scancodes, running this should help:
// ScanCode Checker //
//////////////////////
#include "DarkGDK.h"
void DarkGDK()
{
dbSyncRate(0);
dbSyncOn();
while(LoopGDK())
{
dbCLS();
dbPrint((LPSTR)"Hold any key to see the scancode displayed.");
dbSetCursor(20,20);
if(dbScanCode()>0)
dbPrint((double)dbScanCode());
dbSync();
}
}
~you can call me lantz~