Does GLUT not detect correctly more than two keys pressed?

I am trying to make a small game using (for free) GLUT. I know that it is old and there are better alternatives, but for now I prefer to stick with it and use it as much as possible. I am programming with C.

I'm currently trying to get GLUT to correctly recognize all the keys that I press. I use glutKeyboardFunc, glutKeyboardUpFunc, glutSpecialFunc and glutSpecialUpFunc to detect keystrokes, and I save their state in the short array that I created (currently I have only 5 keys used, so I just created a specific array for them).

However, if everything works fine for 2 keys or less, the game does not properly detect 3 keys or more. Although for some keys it correctly determines the combination (which actually happens for only one specific combination), for others, the functions simply do not detect the third key that I press.

I checked my code several times, and there is nothing special about the combination that works. I also made glutKeyboardFunc and glutSpecialFunc directly print every keystroke they receive, and it seems that they just stop working after I press more than two keys.

Is this a known issue with GLUT or something else? I googled a lot and did not find anyone with a similar problem.

+4
source share
2 answers

I don't really like GLUT, but as I know, you have to make sure that your keyboard supports more than two input keys at the same time. This function is called n-key rollover . This page says that 2-key rollover may be common for some keyboards, but you do not need to trust this source.

+4
source

I will clarify the point: glutKeyBoardFunc is a callback, i.e. it is called for each key pressed and executed again and again, and all if-else (or switch-case) statements for various key combinations are executed. This means that if you would press β€œA”, β€œ->” (right arrow) and β€œD” immediately, depending on which keypress event was received first, the callback will be executed accordingly. Sometimes with a delay, and sometimes on the screen, the animation may stop for a moment.

GLUT is intended solely for educational / training purposes, but is not suitable for full-blown applications, as this is not what it is intended for. You land using specific OS or other languages ​​(for example, Qt) to embed an OpenGL β€œwindow” in them and execute keyboard events, etc. Event handling in these (and / or OS-specific frames) is radically different (and better) than GLUT.

You might want your simultaneous keystrokes to be minimal. You can zoom it with the mouse to get rid of the disgusting response / processing ...

+1
source

All Articles