0x80 is hex. in decimal its 128. in binary its 10000000. 8th bit. 0x8000 is 32768 in decimal. 1000000000000000 is binary. making it the 16th bit. So that guy who told who it was the 15th bit was a bit confused, unless they meant 0x4000.
=======================================
A man with no head is still a man.
A head with no man is plain freaky.
keyboard problem
heheh "a bit confused" sound funny in relavant to the matter, but does the 15th bit test for KeyUp while bit 8th test for KeyDown? I can''t get it to work under DI.
bool wait=false;
>>>...then in main loop...<<<
if ((keys[VK_SPACE])&&(!wait)){
player.engine = ~player.engine;
wait=true;
}
if(!keys[VK_SPACE])
wait=false;
..have fun
>>>...then in main loop...<<<
if ((keys[VK_SPACE])&&(!wait)){
player.engine = ~player.engine;
wait=true;
}
if(!keys[VK_SPACE])
wait=false;
..have fun
^cyber, if i do the code you exampled, the game only will be Paused when the button is hold down, but will Unpause as soon as it is released.
bool wait=false; // watch that you dont put this in main loop
//...then in main loop...
if ((keys[VK_SPACE])&&(!wait)){
if(player.engine){
player.engine=false;
}else{
player.engine=true;
}
wait=true;
}
if(!keys[VK_SPACE])
wait=false;
//this time i tested it and it worked
ok, what''s i''m trying to do is this:
but ''tis not working!!!
if (PauseState == false){///Get KeyStateif (FAILED(lpDIDeviceKeyboard->GetDeviceState(sizeof(KeyState), (LPVOID)&KeyState))){ return(0);}//end ifFunction1();if (KeyDown(KeyState, DIK_P)){PauseState = true;}//end if}else{///Get KeyStateif (FAILED(lpDIDeviceKeyboard->GetDeviceState(sizeof(KeyState), (LPVOID)&KeyState))){ return(0);}//end ifFunction2();if (KeyDown(KeyState, DIK_P)){PauseState = false;}//end if}
but ''tis not working!!!
That's all you'll have to do
-Markus-
Edited by - Cygon on August 23, 2000 4:07:20 AM
bool spacedown = false; // Is Space key down ?if(keys[VK_SPACE]) { // If space is pressed if(!spacedown) // Check if we already changed state player.engine = !player.engine; spacedown = true; // Set the flag so the engine is not switched again} else { // else (space key not down) spacedown = false; // Clear the flag so it'll switch on the next press again}
-Markus-
Edited by - Cygon on August 23, 2000 4:07:20 AM
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
hello again its me again,
the problem is that you dont understand how keyboard input is working, thats way Cygon thinks that he is right but he is wrong You must know that when you press some key and you have function like KeyDown(KeyState, DIK_P) in DirectInput, the function will be returning TRUE as long as are you holding that key down. For example if your main loop executes 1000 times in second that means that if you "press" the key and you are pressing it for 0.5 seconds then 500x times the function KeyDown(KeyState, DIK_P) will return true(each time once in one loop). If you press it for 0.1 second then the function will return TRUE 100x times in second(each time once in one loop). Immediately when you release key the function will return FALSE.
bool wait=false;
bool pause=false;
//then in main loop...
//here we get key state
if (FAILED(lpDIDeviceKeyboard->GetDeviceState(sizeof(KeyState), (LPVOID)&KeyState))){ return(0);}
//here we check if key P is pressed ***AND if wait!=true
if ((KeyDown(KeyState, DIK_P))&&(!wait)){
pause=!pause. //switch from false to true or vice versa
wait=true; //if we will be still pressing this key in the next main loop we wont go in the function
}
//here we check if the key was released, and if it was was wait=false, notice that "!" before KeyDown, you would read this line as: if function KeyDown is returning false(that is when you are not pressing key) then wait=false
if(!KeyDown(KeyState, DIK_P))
wait=false;
//if pause is FALSE we go in function 1, if pause is TRUE we go in function 2
if(!pause){
function1();
}else{
function2();
}
hope this helps
^cyer
the problem is that you dont understand how keyboard input is working, thats way Cygon thinks that he is right but he is wrong You must know that when you press some key and you have function like KeyDown(KeyState, DIK_P) in DirectInput, the function will be returning TRUE as long as are you holding that key down. For example if your main loop executes 1000 times in second that means that if you "press" the key and you are pressing it for 0.5 seconds then 500x times the function KeyDown(KeyState, DIK_P) will return true(each time once in one loop). If you press it for 0.1 second then the function will return TRUE 100x times in second(each time once in one loop). Immediately when you release key the function will return FALSE.
bool wait=false;
bool pause=false;
//then in main loop...
//here we get key state
if (FAILED(lpDIDeviceKeyboard->GetDeviceState(sizeof(KeyState), (LPVOID)&KeyState))){ return(0);}
//here we check if key P is pressed ***AND if wait!=true
if ((KeyDown(KeyState, DIK_P))&&(!wait)){
pause=!pause. //switch from false to true or vice versa
wait=true; //if we will be still pressing this key in the next main loop we wont go in the function
}
//here we check if the key was released, and if it was was wait=false, notice that "!" before KeyDown, you would read this line as: if function KeyDown is returning false(that is when you are not pressing key) then wait=false
if(!KeyDown(KeyState, DIK_P))
wait=false;
//if pause is FALSE we go in function 1, if pause is TRUE we go in function 2
if(!pause){
function1();
}else{
function2();
}
hope this helps
^cyer
when i said:
"when you press some key and you have function like KeyDown(KeyState, DIK_P) in DirectInput, the function will be returning TRUE as long as are you holding that key down" i meant:
"when you press <<"p" key>> and you have function like KeyDown(KeyState, DIK_P) in DirectInput, the function will be returning TRUE as long as are you holding that key down", obvious KeyDown(KeyState, DIK_P) will return true just for key "p"
^cyer
"when you press some key and you have function like KeyDown(KeyState, DIK_P) in DirectInput, the function will be returning TRUE as long as are you holding that key down" i meant:
"when you press <<"p" key>> and you have function like KeyDown(KeyState, DIK_P) in DirectInput, the function will be returning TRUE as long as are you holding that key down", obvious KeyDown(KeyState, DIK_P) will return true just for key "p"
^cyer
quote:
the problem is that you dont understand how keyboard input is working, thats way Cygon thinks that he is right but he is wrong
Read my example again.
I'm right, just as you are.
bool spacedown = false;if(keys[VK_SPACE]) { if(!spacedown) player.engine = !player.engine; spacedown = true;} else { spacedown = false;}
I perfectly know that keys[VK_SPACE] (which is an array returned by IDID7::GetDeviceState(), not a function) will return true as long as the key is down. And I know that if you just switch the engine state when the key is down, it will flicker between true and false every frame.
The important value isn't spacedown, it's player.engine . spacedown is just a helper value to see if the engine was already switched.
STEP-BY-STEP
When keys[VK_SPACE] becomes (and stays) true, the engine will be switched if spacedown is not set.
Then spacedown will be set to true.
When the loop (with the key still down) executes the second (or third, ...) time, spacedown will be true and the engine will not be switched.
If keys[VK_SPACE] is false (the key is released), spacedown is cleared again, so that when keys[VK_SPACE] gets true another time, the engine will again be switched once .
Just look a bit more thorough at the code before saying someone is 'wrong', I'm just doing it another way than you ^cyer, ok ?
-Markus-
Edited by - Cygon on August 23, 2000 2:58:53 PM
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement