June 19th, 2004, 06:28 AM
wxPython + Keyboard Shortcut
Is it possible to make a Function to be triggered by keyboard shortcut without associating it with menu in wxPython? For eg. I want the program to do something when the user press Alt+K but doesn't have the menu for it.
June 19th, 2004, 11:15 AM
You can assign a keyboard event to any control not just menus:
EVT_CHAR(control,callback function )
The callback function will examine the keypress (one of the event attributes) and will do something with it or pass it on for handling by another event handler.
Typically the callback function will parse all key presses and only acts on the keys it is interested in - so you normally have a series of if ... elsif ... else statements.
Note: you would probably attach the handler to a menu's parent to ensure your handler gets a chance to see the key press.
Last edited by Grim Archon; June 19th, 2004 at 11:18 AM.