intercepting ENTER (or RETURN) key

How do you intercept the event of the user pressing the ENTER (or RETURN) key on the keyboard.?

wx.EVT_KEY_UP ignores this event.

raffaello wrote:

How do you intercept the event of the user pressing the ENTER (or RETURN) key on the keyboard.?

wx.EVT_KEY_UP ignores this event.

Have you tried putting wx.WANTS_CHARS in the style of your wxWindow, which has focus when the keys are pressed? Check out the KeyEvents demo in the wxPython demo for an example if you need one.

- Mike

P.S.
I had a flash, and it may be of interest for other people.
I was trying to mimic the behaviour of a default button in Visual Basic, i.e. a button that starts also when the user presses the RETURN key in an application that looks for a string in a database.
But, in fact, I did not need to start the button from anywhere in the frame, just from the wx.TextCtrl where the user writes the string to be searched. So I added the wx.WANTS_CHARS only to the style of that wx.TextCtrl.
Well, it works.

Thanks for the help.

···

2008/6/3 raffaello barbarossa.platz@gmail.com:

I tried, Mike, but the frame stubbornly refused to obey.
I have looked at the demo, and the only significant difference I can see is that the window intercepting the event in the demo (and it does) is a wx.Window, while mine is a wx.Frame. But wx.Frame derives from wx.Window…

Is there some flag I neglected?

2008/6/3 Mike Rooney mxr@qvii.com:

raffaello wrote:

How do you intercept the event of the user pressing the ENTER (or RETURN) key on the keyboard.?

wx.EVT_KEY_UP ignores this event.

Have you tried putting wx.WANTS_CHARS in the style of your wxWindow, which has focus when the keys are pressed? Check out the KeyEvents demo in the wxPython demo for an example if you need one.

  • Mike

wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

raffaello wrote:

I tried, Mike, but the frame stubbornly refused to obey.
I have looked at the demo, and the only significant difference I can see is that the window intercepting the event in the demo (and it does) is a wx.Window, while mine is a wx.Frame. But wx.Frame derives from wx.Window...
Is there some flag I neglected?

Key events are only sent to the widget with the focus, and frames are not supposed to ever have the focus themselves (although I've been told that they can on wxGTK but that is probably an accident of the implementation.) If you read the paragraph on the fruit catching robots at self.Bind vs. self.button.Bind - wxPyWiki then key events (and other non-command events) are essentially fruit that vanish before they reach the next branch down, so if there isn't a robot to catch them at that same level in the hierarchy then they won't be caught at all.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!