On Monday, April 22, 2013 5:19:35 PM UTC-5, Dan Christian wrote:
I have an application that has a GUI keypad on it. Each button calls
a callback (with some data from a lambda), and that works fine.
I’d like to do one of two things:
Globally send keyboard number keypresses to my callbacks (just like
the GUI keypad). Of course, it shouldn’t affect file dialogs.
When the window with the GUI keypad has focus, send keyboard number
keypresses to a callback.
I only found examples online that bound all key presses, or were doing
accelerators (with control or meta set).
Can anybody point me to an example of how to do this?
Thanks,
-Dan
To catch all key presses all the time, you’ll probably have to bind EVT_KEY_DOWN to all your widgets. An AcceratorTable is a possibility, but creating one that catches every single key press is kind of a pain.
If you want to catch key presses outside your app, that is not supported by wx. You’ll have to hook into the OS itself.
I'm just trying to catch select keys within the app, and in such a way
that it doesn't confuse dialog boxes.
I think I just need to bind certain keys at the frame level, but I
don't understand how to do that.
-Dan
···
On Tue, Apr 23, 2013 at 9:01 AM, Mike Driscoll <kyosohma@gmail.com> wrote:
Hi Dan,
On Monday, April 22, 2013 5:19:35 PM UTC-5, Dan Christian wrote:
I have an application that has a GUI keypad on it. Each button calls
a callback (with some data from a lambda), and that works fine.
I'd like to do one of two things:
Globally send keyboard number keypresses to my callbacks (just like
the GUI keypad). Of course, it shouldn't affect file dialogs.
When the window with the GUI keypad has focus, send keyboard number
keypresses to a callback.
I only found examples online that bound all key presses, or were doing
accelerators (with control or meta set).
Can anybody point me to an example of how to do this?
Thanks,
-Dan
To catch all key presses all the time, you'll probably have to bind
EVT_KEY_DOWN to all your widgets. An AcceratorTable is a possibility, but
creating one that catches every single key press is kind of a pain.
If you want to catch key presses outside your app, that is not supported by
wx. You'll have to hook into the OS itself.
- Mike
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I'm just trying to catch select keys within the app, and in such a way
that it doesn't confuse dialog boxes.
I think I just need to bind certain keys at the frame level, but I
don't understand how to do that.
You can't catch individual keys. You have to catch ALL keys
(EVT_KEY_DOWN, EVT_KEY_UP or EVT_CHAR), and just pass through the ones
you aren't interested in.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
I'm just trying to catch select keys within the app, and in such a way
that it doesn't confuse dialog boxes.
I think I just need to bind certain keys at the frame level, but I
don't understand how to do that.
You can't catch individual keys. You have to catch ALL keys
(EVT_KEY_DOWN, EVT_KEY_UP or EVT_CHAR), and just pass through the ones
you aren't interested in.
And keep in mind that these events are only delivered to the widget that currently has the keyboard focus, so if the frame contains any other widgets then you can't just bind the handlers to the frame and expect to get all of the events.
If the key events you are interested in could be thought of like hot keys, or like shortcut keys similar to those associated with menu items, then you can use a wx.AcceleratorTable attached to the frame. Then when those keys are pressed the frame will get a menu event.