Simulating key pressing, is that possible?

Hi people,

I have added an OpenGL interface to an old mathematical program that I had before. It has a loop system and in each iteration, part of the program calculates and the results are shown in the OpenGL visualization in realtime.

Due to an unknown reason, the next iteration of the loop only goes on if I hit a key or move the mouse around. I have no idea why it’s happening and I was wondering, maybe I could trick the computer simulating that a key is pressed at each iteration, so it wouldn’t be up to the user pressing a key to get the whole process working.

Any ideas, thoughts or suggestions?


This is probably not useful but I’ll write it anyway.
Maybe you’re waiting for an event using a blocking call (say XNextEvent or GetEvent in win32). Then, the result is here but it’s not displayed until the blocking call returns.
As soon as you move the mouse, you get a <mouse move> message and the collateral result is that framebuffer goes updated.

What other informations are avaiable?

I had this thought too. Let me explain the situation:

I’ve coded everything in Fortran 90 using f90gl ( to have the OpenGL, GLU and GLUT subroutines. I’ve had some problems with glutMainLoop. I’ve tried to use my older mathematical subroutines running in parallel and I’ve got many problems with that glut subroutine, once it never returns.

I made some modifications in GLUT source code based on the tips given by Steve Baker at In my modifications, glutMainLoop returns making my program coding pretty easy but now I have this problem with event handling. Before modificating GLUT, key pressing was not needed.

Any else ideas? Maybe is the problem at GLUT code, something I didn’t notice?



can you call Windows SDK functions? Then you should call SendMessage. E.g.

SendMessage(hwnd, WM_KEYDOWN, VK_DELETE, 1L);

will simulate to press the DEL-key one time.


Use the glutIdleFunc().
Source code :

You can do other tricks with glutPostRedisplay() etc.