Skip to main content
gamedev.net
🔒 Locked

detect space bar release

Started by Viks 4 replies 4.1k views
Original Post
Viks
Viks
After pressing space bar for some time and releasing it, is there a way in OpenGL to detect that the space bar has been released?
Codeka
Codeka
OpenGL is a graphics library, it has no support for keyboard input at all.

What platform are you running on? Do you already have a library to handle input?
Nypyren
Nypyren
OpenGL handles graphics. You need an input API.

On Win32, for example, you could use the WM_KEYUP message. In .Net, you could use a form's KeyUp event. It really depends on what language and libraries you are using.
Viks
Viks
Quote:
Original post by Codeka
OpenGL is a graphics library, it has no support for keyboard input at all.

What platform are you running on? Do you already have a library to handle input?


I am using Visual Studio C++ 2008. For input, I am using glutKeyboardFunc() to capture a space bar hit (detects an ASCII value of 32 if input is through the space bar), but the problem is when do I find out the user is not pressing the space bar anymore?

Let me be a little more specific here. I am developing a golf game in which space bar is provided to the user as an input to provide the force with which the ball is hit. Now, the user has to press the space bar if he wants to increase the force. The moment he/she releases the space bar, my program will have to hit the ball with the force provided by the user, which means, I need to find out, when the user actually released the space bar, so that I can grab those values and calculate the necessary vectors.
Zakwayda
Zakwayda
Quote:
I am using Visual Studio C++ 2008. For input, I am using glutKeyboardFunc() to capture a space bar hit (detects an ASCII value of 32 if input is through the space bar), but the problem is when do I find out the user is not pressing the space bar anymore?

Let me be a little more specific here. I am developing a golf game in which space bar is provided to the user as an input to provide the force with which the ball is hit. Now, the user has to press the space bar if he wants to increase the force. The moment he/she releases the space bar, my program will have to hit the ball with the force provided by the user, which means, I need to find out, when the user actually released the space bar, so that I can grab those values and calculate the necessary vectors.
A Google search for 'glut key release' led me here (first hit). In particular, look here and here.
Viks
Viks
Bingo, jyk!! glutKeyboardUpFunc() was the one I was looking for. I had looked at the GLUT library before. It's been like a Bible to me. In fact, I am using glutKeyboardFunc() in my code. But I am not sure how I missed glutKeyboardUpFunc(). Many thanks, for the help!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.