Hi, Lyle! I tested the program on Windows XP and it works great, so you don't have to study WinAPI. Maybe there are some other ways to do this in Linux too ? I will test it on Ubuntu 9.10 later, since I don't have installed Linux right now. Also, if you find a solution, post it here please, it's interesting. Good luck!
2009/12/24, Lyle Underwood <[email protected]>: > So there's no way I can actually use a pressed key as a mode toggle > without getting down into OS-specific functions like in xlib? I'm build > a cross-platform application, but I really don't want to get down into > the win32 api. I've never really done any win32 programming, or xlib for > that matter, but this functionality would just be so nice to have. > > Thanks for confirming my fears though. > > On Wed, 2009-12-23 at 21:57 +0100, michi7x7 wrote: >> This is the automatic key-repeat-function by the OS, Windows does it >> just like Linux or Mac. >> If you want to get the real state of the Key, you'll have to use >> X.org-functions (the xlib) >> > This must be different between my computer and yours. I'm on Ubuntu >> > 9.10, are you on a linux system? >> > >> > I compiled and ran your test code, but this too is affected by key >> > repeat. If I hold down the space bar for just a second then I get a >> > whole bunch of output. >> > >> > In this example I only pressed the spacebar one time, and tried to hold >> > it down for exactly one second: >> > >> > $ ./test >> > Toggled (active) >> > Toggled (inactive) >> > Toggled (active) >> > Toggled (inactive) >> > Toggled (active) >> > Toggled (inactive) >> > Toggled (active) >> > Toggled (inactive) >> > Toggled (active) >> > Toggled (inactive) >> > Toggled (active) >> > Toggled (inactive) >> > >> > For the first quarter to half a second there was only one >> > active/inactive pair, and then my key repeat kicked in and I got all the >> > rest. Is this not what happens for you? >> > >> > Thanks for taking the time, by the way. >> > >> > On Wed, 2009-12-23 at 16:24 +0600, Галымжан Кожаев wrote: >> > >> >> I don't know why your code doesn't work. Look at this, I've written >> >> and tested this code: >> >> >> >> bool hasToggled; >> >> >> >> bool keyPressHandler(GdkEventKey* event) { >> >> if(event->type == GDK_KEY_PRESS && event->keyval == GDK_space && >> >> !hasToggled) { >> >> hasToggled = true; >> >> cout << "Toggled (active)" << endl; >> >> } >> >> else if(event->type == GDK_KEY_RELEASE && event->keyval == GDK_space >> >> && hasToggled) { >> >> hasToggled = false; >> >> cout << "Toggled (inactive)" << endl; >> >> } >> >> return false; >> >> } >> >> >> >> gint main(int argc, char *argv[]) { >> >> Gtk::Main program(argc, argv); >> >> Gtk::Window wnd; >> >> hasToggled = false; >> >> wnd.signal_key_press_event().connect(sigc::ptr_fun(&keyPressHandler), >> >> false); >> >> >> >> wnd.signal_key_release_event().connect(sigc::ptr_fun(&keyPressHandler), >> >> false); >> >> program.run(wnd); >> >> return 0; >> >> } >> >> >> >> Try to compile and run it. Works perfectly, I think it's exactly what >> >> you need. Write if you have any problems. >> >> >> >> 2009/12/23, Lyle Underwood <[email protected]>: >> >> >> >>> 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 <[email protected]>: >> >>>> >> >>>>> 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 >> >>>>> [email protected] >> >>>>> http://mail.gnome.org/mailman/listinfo/gtkmm-list >> >>>>> >> >>>>> >> >>> >> >>> >> > >> > >> > _______________________________________________ >> > gtkmm-list mailing list >> > [email protected] >> > http://mail.gnome.org/mailman/listinfo/gtkmm-list >> > > > > _______________________________________________ > gtkmm-list mailing list > [email protected] > http://mail.gnome.org/mailman/listinfo/gtkmm-list > _______________________________________________ gtkmm-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/gtkmm-list
