Skipping EVT_HOTKEY events when using Window.RegisterHotKey

21 views
Skip to first unread message

James Scholes

unread,
Nov 1, 2015, 8:08:01 PM11/1/15
to wxpytho...@googlegroups.com
Hi all,

In the following code, I'm trying to bind a hotkey that is local to my
application's main window and its child controls. In other words, if
the application doesn't have focus, the hotkey should be passed to
Windows as normal. That's the bit that's puzzling me. I'm using
Event.Skip() in my event handler, and if my application isn't focussed
the action associated with the hotkey doesn't occur. However, nor does
the keypress get passed to other applications.

class HotkeyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
super(HotkeyFrame, self).__init__(parent=None, title='Hotkey
Frame', *args, **kwargs)
VK_F1 = 0x70
hotkey_id = wx.NewId()
self.Bind(wx.EVT_HOTKEY, self.onHotkeyPressed, id=hotkey_id)
self.RegisterHotKey(hotkey_id, 0, VK_F1)

def onHotkeyPressed(self, event):
focus = self.FindFocus()
if self.IsDescendant(focus):
wx.Bell()
else:
event.Skip()

app = wx.App()
frame = HotkeyFrame()
frame.Show()
app.MainLoop()
--
James Scholes
http://twitter.com/JamesScholes

Tim Roberts

unread,
Nov 2, 2015, 3:20:47 PM11/2/15
to wxpytho...@googlegroups.com
James Scholes wrote:
> In the following code, I'm trying to bind a hotkey that is local to my
> application's main window and its child controls. In other words, if
> the application doesn't have focus, the hotkey should be passed to
> Windows as normal. That's the bit that's puzzling me. I'm using
> Event.Skip() in my event handler, and if my application isn't focussed
> the action associated with the hotkey doesn't occur. However, nor does
> the keypress get passed to other applications.

RegisterHotKey registers a system-wide hot key, as you have seen. Your
registration overrides any previous assignment.

If you just want to catch a key within your own application, then you
can use the normal key up/down message events. You don't need to
register a hot key.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Reply all
Reply to author
Forward
0 new messages