I’m writing a game in C using the Gtk libraries, in which the player controls a movable character. However, I want the player to be able to hold a key to continuously move in one direction. How do I override the normal behavior for holding a key, in which a key event is generated, there is a brief pause, and then key events occur in a continuous stream?
I’ve noticed a similar question was asked previously about doing the same thing in Javascript; however, the answer doesn’t really assist with implementing the same system in Gtk. I’ve noticed that there is a GtkDevice “class”; is there a function having to do with it that will allow me to control the buffering of keyboard input?
Connect to GTK’s
key_press_eventandkey_release_eventsignals.They will work as you describe.
It will be your responsibility to track whether the keys you are interested in are currently pressed at a given time.