View Full Version : keyboard

12-26-2003, 02:02 AM
I'm trying to make a program in which the user can type text to the screen in opengl.

I do this by running strcat each time a key is pressed and adding the pressed letter to a string and printing it to the screen.

But what happens is that strcat is executed while the key is pressed and therefore if say the letter T is pressed then about 20 T's are printed to the screen.

My question is how do I get the program to strcat only once while the key is being held down.

12-26-2003, 04:29 AM
I do hope you don't expect anyone to be able to answer that question ???

You need at least give some information about what you are using, win32, MFC glut, xlib, fltk, FOX, Qt, glfw, sdl or what ?


12-26-2003, 07:25 AM
And by all means, use GLFW. Cool to do simple portable games/demos with it.

12-26-2003, 02:51 PM
i'm using MSVC++, in XP with glut.
I think i'll give GLFW a go though, it looks promising.

12-28-2003, 08:43 AM
There are two ways of handling keyboard input, one is to poll the keyboard to see what's pressed, the other is to handle the press events with an event handler.

You are using polling and it has the problems you describe and more, for example you may miss fast key presses.

Instead you chould look at the key press events and append the char only when each key press arrives. This will solve your problem and is normally how applicatiosn handle keyboard input.

Read this: