
detect released keys in glut??
hi
Is there something that i can add so that it knows or detects when a certain key is being released in glut?
i.e. if up is being pressed, then accelerate, if released then decelerate.
Hope it makes sense. Thanks.
oh btw: i remember seeing a thread similar to this before but i cant seem to find it. plus the search function still doesnt work
[edited by - xnin on January 2, 2003 10:01:10 AM]

In your WndProc function handle a message called WM_KEYDOWN.
Just look it up in Nehe''s tutorials.
Just look it up in Nehe''s tutorials.
glutKeyboardUpFunc() and glutSpecialUpFunc(). You might also find glutIgnoreKeyRepeat(int) useful.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote:
Original post by Fruny
glutKeyboardUpFunc() and glutSpecialUpFunc(). You might also find glutIgnoreKeyRepeat(int) useful.
Thanks for your help. I did that but now the problem is that if i release the up key, the thing moving automaticaly stops. Even if i put some loop to make it gradually slow down
i.e.while (velocity > 0) { velocity -=0.001; }
Also, i dont whant to put the glutIgnoreKeyRepeat(int) because i dont what to keep tapping on the up key to get it to move.
thanks for your help so far guys

[edited by - xnin on January 4, 2003 1:07:08 AM]
Your loop doesn''t exit until velocity <= 0. Nothing else happens in the mean time. Instead, do something similar to :
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
void my_glut_idle_func(){ if( no_key_pressed ) { if( velocity > 0 ) velocity -=0.001 else velocity = 0; }}
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement