From: Kevin A. <al...@se...> - 2004-09-19 17:22:57
|
On Sep 19, 2004, at 10:14 AM, Nick Lunt wrote: > Hi folks, > > Im sure this must be in the documentation somewhere, but Im afraid I > can't > find it. > Also I've searched the archives and I can't find it there either. > > Could someone please tell me how to capture when <return> is pressed > on a > keyboard ? > > I know this much : > > def on_ipInput_keyPress(self, event): > print "key pressed %s" %event > > which outputs something like : > > you pressed <wx._core.KeyEvent; proxy of C++ wxKeyEvent instance at > _0cf41200_p_wxKeyEvent> > > But I don't know how to specifically capture the <return> key. > > I apologise in advance for this post, as Im sure that this must be > documented somewhere, I simply cannot find where. Any pointers to the > relevant documentation greatfully received. > > Many thanks > Nick. If you use dir() on the event you'll see all the methods and attributes including the base wxPython ones. In this case, PythonCard "decorates" the event instance with some helper attributes so you don't have to use the methods. keyCode has what you're looking for. Return is ASCII 13, so... def on_ipinput_keyPress(self, event): print dir(event) if event.keyCode == 13: print "return" else: event.skip() If you want the field to get the return key, then you'll need to insert it yourself or call event.skip() in addition to whatever other processing you were planning on. And no, the event attributes are not documented very well, but they are used in quite a few of the samples and tools. You can take a look at event.py to see the basic "decoration" done for all events, mouse events, key events, etc. For component specific attributes, look at the individual component files. ka |