From: Bruce S. <Bru...@nc...> - 2011-06-11 17:03:18
|
Thanks for the code. I'll definitely try to get this into the next release. Bruce Sherwood On Sat, Jun 11, 2011 at 6:10 AM, Frank W. Samuelson <fr...@me...> wrote: > > I am interested in using vpython to make some simple games. Apparently there > are a few others like me based on some internet posts that I found. To make > games we need to know when keyboard buttons are released as well as pressed. > To facilitate this happening, I made a couple small code changes represented by > the below patch on the visual-5.71 release. You are welcome to incorporate or > ignore them. When keys are released, the generated keyboard events are > proceeded with the string "Released: " in front of them. > > The good: > -The patch is very small > -This hack is backwards compatible for people who use code like > s = scene.kb.getkey() > if s == 'k': ... > -Processing of keyboard events is still easy string comparisons > > The bad: > -The code is currently only for gtk. I don't have "Windows" or Mac computer on > which to test any change that I make. > > Thanks for all your work on vpython. It's great. > > -Frank > > > --- src/gtk2/display.cpp.~1.58.~ 2009-10-11 17:33:43.000000000 -0400 > +++ src/gtk2/display.cpp 2011-06-11 07:24:54.176217104 -0400 > @@ -133,6 +133,8 @@ > area->set_size_request( w, h ); > area->signal_key_press_event().connect( > sigc::mem_fun( *this, &display::on_key_pressed)); > + area->signal_key_release_event().connect( > + sigc::mem_fun( *this, &display::on_key_pressed)); > > // Glade-based UI. > // Turned off toolbar in display initialization for now; not yet available on Windows or Mac > @@ -270,6 +272,11 @@ > // other than a US keyboard. > guint k = key->keyval; > std::string ctrl_str; > + > + // Is this a press or release? > + if (key->type == GDK_KEY_RELEASE) { > + ctrl_str += "Released: "; > + } > // First trap for shift, ctrl, and alt. > if (key->state & GDK_CONTROL_MASK) { > ctrl_str += "ctrl+"; > > > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |