I want to bind certain keypresses to the entire main window. For example,
when I press Escape anywhere in the main window, I want to run a StopAudio
function.
In Perl/Tk, I can do this:
$mw->bind("<Key-Escape>", [\&stop_mp3]);
In WxPython, though, I try this:
聽聽聽聽EVT_CHAR(self, self.EvtChar)
but it doesn't work. If I restrict the EVT_CHAR to a certain part of the
main window, though, it does work:
聽聽聽聽self.searchpanel = SearchPanel(self, self.db)
聽聽聽聽EVT_CHAR(self.searchpanel, self.EvtChar) <-- This works
I want to bind certain keypresses to the entire main window. For example,
when I press Escape anywhere in the main window, I want to run a StopAudio
function.
In Perl/Tk, I can do this:
$mw->bind("<Key-Escape>", [\&stop_mp3]);
In WxPython, though, I try this:
EVT_CHAR(self, self.EvtChar)
but it doesn't work. If I restrict the EVT_CHAR to a certain part of the
main window, though, it does work:
self.searchpanel = SearchPanel(self, self.db)
EVT_CHAR(self.searchpanel, self.EvtChar) <-- This works
but it doesn't work. If I restrict the EVT_CHAR to a certain part of the
main window, though, it does work:
self.searchpanel = SearchPanel(self, self.db)
EVT_CHAR(self.searchpanel, self.EvtChar) <-- This works
What am I doing wrong?
Try using a wxAcceleratorTable.
A little, more detail: KEY and CHAR events only go to the window that
has the focus. Accelerators are the mechanism to use to have a
frame-wide hotkey. When the key is pressed when any subwindow of the
frame has the focus then a EVT_MENU event is generated (since normally
you use accelerators with menu items.)
路路路
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!