I'm writing a game in C with GTK+ 2.0. It creates a full-screen window with a drawing area and uses it.
The game logics runs in a timeout callback and needs to know
if a key is pressed at the moment or not.
5 keys are being tracked: [Up]. [Right], [Down], [Left] and [Space].
To do this, I have an array of 5 gboolean values.
Code:
gboolean keys[5];
I also connect a callback function that saves the current key (up/down) state:
Code:
guint on_key_press(GtkWidget *widget,
GdkEventKey *event, Data *data) {
// ...
data->keys[key_index] = event->type == 8;
// ...
return FALSE;
}
// ...
gtk_key_snooper_install(on_key_press, (gpointer)data);
This basically assigns TRUE or FALSE to the [0 .. 4] elements of the array.
Everything is working, except one thing:
If in the game you hold [Up] and [Space] in the same time and then press [Left]. (i.e. three keys simultaniously), the application will not notice anything.
If you do the same but press the [Right] key, it will work with no problem.
It works perfectly if I change [Space] to [A] key.
It looks like [Space] key is blocking [Left] key if [Up] is also pressed.I first thought it is somehow connected to the fact that if a key is held down, key press events keep coming repeatedly. (like when you hold "a" you get "aaaaaaaaa"), but that doesn't make sense, and it is not possible in GTK+ to disable repeating keys in a cross-platform way.
I've also tried:
Code:
g_signal_connect(G_OBJECT(window), "key_press_event", ... );
instead of:
Code:
gtk_key_snooper_install(on_key_press, ... );
but it doesn't make any difference.
I'm using Debian.
P.S.: While I was writing this message, I noticed that the same is happening with the [G] key. [G] is blocking [Left] in the same way, and doesn't affect the [Right] key.
In the same time [C] works perfectly (like [A]). May be these are some special hotkeys?
P.S.#2: Now I noticed that if you hold down [T+G], keys [Up] and [Right] are blocked, whereas [Left] and [Down] work! What is that???