Re: key press events & holding keys down



On Sun, 18 Mar 2012 20:08:12 -0800
Christopher Howard <christopher howard frigidcode com> wrote:
On 03/16/2012 04:29 PM, Christopher Howard wrote:

I control the spacecraft with the arrow keys, which I do by
grabbing the GdkEventKey and then checking it against GDK_KEY_Left,
GDK_KEY_Right, and so forth. Strictly speaking what I am concerned
with is whether or not the key is held down, but this seems to work
because the key event gets repeated.

However, if one of the arrows is held down, and another arrow is
pressed, then it shuts off events for the first arrow. That's bad,
of course, because in my game the player may want to hold down two
arrows keys at once (e.g., UP for acceleration and LEFT to turn the
spacecraft). So...


Okay, having got no responses, let me ask the question in a more
direct manner: under Gtk+, how does one check whether or not any
particular keyboard key is currently pressed? I know this is possible
because I used to do it back in my ClanLib days.

I see in the Gdk docs that there is a GdkDevice object, but it is not
clear to me how to create or utilize this to such an end.

Since GtkWidget objects have key-press-event and a key-release-event
signals that you can connect to (and from your explanation, clearly you
have connected to), you will probably need to explain why these don't do
what you want in order to get a meaningful answer. Most people would
monitor these in conjunction with gdk_event_get_keyval() or
gdk_event_get_keycode() and keep state.

Chris



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]