Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Clyde on September 13, 2006

Title: GetAsyncKeyState()
Post by: Clyde on September 13, 2006
I wonder if anyone knows how to make it so that when you press a key using GetAsyncKeyState() that it doesnt make things happen so quickly when a key is pressed?

Dummy example:

Code: [Select]
If (GetAsyncKeyState(68)) Then Debug=Debug+1
If Debug>1 Then Debug=0

If Debug Then
  'Display Info
End If

Cheers and many thanks,
Clyde.
Title: Re: GetAsyncKeyState()
Post by: Rbz on September 14, 2006
Try this one it will work fine  ;)

Code: [Select]
If ( GetAsyncKeyState(68) = -32767 ) Then Debug=Debug+1
If Debug>1 Then Debug=0

If Debug Then
  'Display Info
End If
Title: Re: GetAsyncKeyState()
Post by: Clyde on September 14, 2006
Cheers for that buddy.
Title: Re: GetAsyncKeyState()
Post by: Jim on September 14, 2006
Because GetAsyncKeyState returns two values at once.  0x8000 if the key is currently pressed and/or 0x0001 if the key was pressed since the last time you called GetAsyncKeyState.  Rbraz's -32767 is, in fact, 0x8001 (&h8001 in basic).

Jim
Title: Re: GetAsyncKeyState()
Post by: Shockwave on September 14, 2006
This function is very useful, I was messing with it yesterday and came on to post the very same question you did Clyde so I guess I got the fastest answer ever. :)