Re: Key presses and releases



That's what I'm doing now. The problem is that the signals don't seem to
fire in this way. I expected the same behavior you did, I thought it
would work like this:

pressed event <-- // spacebar held down
released event <-- // spacebar let go after a couple seconds

pressed event <-- // spacebar held down
released event <-- // spacebar let go after a couple seconds

pressed event <-- // spacebar held down
released event <-- // spacebar let go after a couple seconds

But it actually does this:

pressed event // <-- spacebar held down
released event
pressed event
released event
pressed event
released event
pressed event
released event
pressed event
released event // <-- spacebar let go after a couple seconds

pressed event // <-- spacebar held down
released event
pressed event
released event
pressed event
released event
pressed event
released event
pressed event
released event // <-- spacebar let go after a couple seconds

This results in the keyAlreadyPressed bool flipping between true and
false over and over in quick succession while the space bar is
depressed.

On Wed, 2009-12-23 at 12:42 +0600, Галымжан Кожаев wrote:
> Hi,
> 
> Maybe you can do like this:
> 
> void onKeyPressed(...) {
>   if(!keyAlreadyPressed) {
>      // space toggled (now active)
>      keyAlreadyPressed = true;
>      //... additional handling
>   }
> }
> 
> void onKeyReleased(...) {
>    // space toggled (now inactive)
>    keyAlreadyPressed = false;
> }
> 
> keyAlreadyPressed is a bool private member or global variable.
> 
> 2009/12/23, Lyle Underwood <lyleunderwood gmail com>:
> > I'm so close to finishing up this application now, I'm just putting some
> > polish on it.
> >
> > I have a drawing area in a viewport for scrolling. I want to add the
> > ability to pan with the mouse, but since the user is usually drawing
> > onto the drawing area I wanted them to use the spacebar to pan. So, you
> > hold down spacebar and drag around to pan, just like in photoshop, gimp,
> > etc..
> >
> > I'm pretty sure I'm not going to have any problem with the actual
> > panning, but I can't figure out how to use the spacebar as a toggled
> > state. It seems the events are triggered by some kind of key repeat,
> > because when I hold down space I get a huge series of press events and
> > release events. So is there some way that I can tell if the spacebar is
> > held down constantly? I was looking through the GdkEventKey struct and
> > couldn't find a solution.
> >
> > Also, I wanted to ask, what's the easiest way to get the selected row in
> > a TreeView to redraw?
> >
> > Thanks.
> >
> > _______________________________________________
> > gtkmm-list mailing list
> > gtkmm-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtkmm-list
> >




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