View Full Version : VK_key's (don't read last one)
03-31-2005, 12:14 PM
Okay.. I'm having a problem with the following code:
if ( (keys[VK_SPACE]) && (ball_h <= -19) )
x = 0;
It's pretty much supposed to be when you hold space and the ball gets to a certian point, it stops it.
The problem is that it only works when i press space at the right moment and not when it's being held...
is there a VK_SPACE_HELD or something I can use?
03-31-2005, 12:19 PM
create a bool bSpaceDown.
On your key down handler, check the param, if it's VK_SPACE set bSpaceDown = true;
On your key up handler, again, check the param, if it's the space key bSpaceDown = false;
then your test becomes
if(bSpaceDown && whatever)
03-31-2005, 12:35 PM
But I'm now having a few problems I wasn't expecting...
I'd like to freeze the screen the way it is when space is held, and unfreeze it and make the ball move again when space is pressed again..
In DrawGLScene(GLvoid), I got the height of the ball changing (ball_h += 0.01 or -= 0.01 depending on the direction)
The screen does freeze when i set X to 0 (1 when going up, -1 when going down) but my call_h is still incrementing... I'd like to pretty much stop the function DrawGLScene w/o blanking the screen.
03-31-2005, 12:41 PM
simple - don't update any positions if bSpaceDown is true.
You could create a function that performs all of the position updates in your scene.
guard the call to that function by bSpaceDown, this way you can control exactly when objects in the scene are moving.
03-31-2005, 01:15 PM
VK_SPACE works but a letter like VK_F won't
I found a site that lists all the keys and VK_F seems to be valid, however my compiler doesn't think so... lol
03-31-2005, 01:19 PM
VK_F is not a virtual key.
you can just use 'F' and 'f' for the byte comparison.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.