Keayboard Input Help.
Hi
Im having a simple problem. I have a simple car that moves up/down etc...When i hold the up key it accelerates but if at the same time i press the left key to turn (but still holding the up key) it stops accelerating. So i have to re-tap the up key. This happens for any direction.
I hope i didnt confuse you. Basically i want to be able to turn while at the same time be able to accelerate. Is there a way to do this? Im using the glut library by the way.
Thank You
That should be possible...
How do you check whether a key is pressed or not?
If you post some problem related code, it''s easier to help.
I think nehe has an excellent way to do so in one of his first (or is it in the first one) tutorials.
[My Lousy Page | Kings Of Chaos | Vampires | email.me]
How do you check whether a key is pressed or not?
If you post some problem related code, it''s easier to help.
I think nehe has an excellent way to do so in one of his first (or is it in the first one) tutorials.
[My Lousy Page | Kings Of Chaos | Vampires | email.me]
For your keyboard, use Direct Input, you''ll can use 2 keys at the same time otherwise :
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
if (UP)// Go go if ((UP) && (LEFT))// Go go with left
========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
May 23, 2003 02:18 PM
If you''re using MSV then you could do it like this.
Create an array like
int keys[256];
catch the WM_KEYDOWN and WM_KEYUP events
switch (pMsg->message){
case WM_KEYDOWN:
keys[pMsg->wParam]=true;
break;
case WM_KEYUP:
keys[pMsg->wParam]=false;
break;
}
then create a function that checks the array repeately.
function checkkeys(){
if(keys[37]){
//GO LEFT
}
if(keys[38]){
//GO UP
}
if(keys[39]){
//GO RIGHT
}
if(keys[40]){
//GO DOWN
}
}
Create an array like
int keys[256];
catch the WM_KEYDOWN and WM_KEYUP events
switch (pMsg->message){
case WM_KEYDOWN:
keys[pMsg->wParam]=true;
break;
case WM_KEYUP:
keys[pMsg->wParam]=false;
break;
}
then create a function that checks the array repeately.
function checkkeys(){
if(keys[37]){
//GO LEFT
}
if(keys[38]){
//GO UP
}
if(keys[39]){
//GO RIGHT
}
if(keys[40]){
//GO DOWN
}
}
quote:
Original post by Anonymous Poster
Create an array like
int keys[256];
Yes, that''s a good suggestion, if you don''t want to use DirectInput... But I think you should just use
bool keys[256];
Glut Kinda sucks when it comes to multiple keypresses... 
You'll either have to go with a different framework, or use non-portable code...
How I handled this, is use the LaMothe keypress functions....
then check other keys using
VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_SPACE...
place this in your keyboardspecfunc(),
If you decided to Abandon Glut, watch out, these functions catch keypresses even if you lose focus!
(edit, had logic bug in code)
[edited by - dede on May 23, 2003 4:13:50 PM]

You'll either have to go with a different framework, or use non-portable code...
How I handled this, is use the LaMothe keypress functions....
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
then check other keys using
VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_SPACE...
place this in your keyboardspecfunc(),
if(KEYDOWN(VK_UP) && KEYDOWN(VK_LEFT){ turn left}
If you decided to Abandon Glut, watch out, these functions catch keypresses even if you lose focus!
(edit, had logic bug in code)
[edited by - dede on May 23, 2003 4:13:50 PM]
~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn
Glut doesnt suck.
In the latest version 3.7, glut supports the detection of KeyUp.
So whenever a key is pressed, u could change a variable to true. Whenever a Keyup is detected, u could change it back to false.
In the latest version 3.7, glut supports the detection of KeyUp.
So whenever a key is pressed, u could change a variable to true. Whenever a Keyup is detected, u could change it back to false.
quote:
Original post by GamerSg
Glut doesnt suck.
In the latest version 3.7, glut supports the detection of KeyUp.
So whenever a key is pressed, u could change a variable to true. Whenever a Keyup is detected, u could change it back to false.
Wow, I don''t see that in the documentation...

Ahh, the documentation hasn''t been updated since 3.2...
No wonder
~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement