keyboard

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.

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 ?

Mikael

And by all means, use GLFW. Cool to do simple portable games/demos with it.

i’m using MSVC++, in XP with glut.
I think i’ll give GLFW a go though, it looks promising.

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:
http://www.cs.csustan.edu/~rsc/SDSU/EventHandling.pdf