Re: Game development - keystroke detection question.




Eric Harlow <linuxgeek@yahoo.com> writes:

> Ok, so I started the game after getting many good ideas and I'm quite
> far along except that I don't like the key_press_event and the
> key_release_event.  I haven't looked into it, but I'm still working on
> the graphics and wondered if anyone can help me with this - or point
> me somewhere. 
> 
> Few problems are:
> 
> Holding down 1 key and pressing another results in the second key
> being repeated.  No indication that the first key is being pressed. 
> This is bad when you're fleeing a group of bad guys (full thrust key)
> while firing (missile key).  Is there a way to get a list of the keys
> currently pressed? 

You'll just have to keep track of the key press and key release
events. The fact that autorepeat is done as key press/release
pairs is rather annoying for this purpose. You can use

 void gdk_key_repeat_disable (void);
 void gdk_key_repeat_restore (void);

Though these have the nasty property of disabling key repeat
globally, instead of locally to your app. (You might want
to switch the repeat mode on "focus_in" and "focus_out")

[ Another approach is to look at event->time and ignore 
  release/press pairs with identical timestamps. But since
  GTK+ doesn't allow looking ahead in the event queue, this
  could make for tricky programming ]
 
> This would also fix the problem with the shift/ctrl keys where they
> send a "key_press_event" but don't send a "key_release_event". 

Hmmm, I have no problems getting "key_release_event" here.
Perhaps you are being caught by the fact that GDK_KEY_PRESS_MASK
is by default in the event mask for a GtkWindow, but
GDK_KEY_RELEASE_MASK isn't.
 
Regards,
                                        Owen








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