Page 1 of 1

RegisterHotKey Event

Posted: Fri Feb 28, 2014 11:26 am
by musictreeAstro
All of the examples I can find using the Windows RegisterHotKey make use of a static event table, which wxCrafter doesn't create. How can I register a systemwide hotkey using wxCrafter?
I can make the call to

Code: Select all

bool wxWindow::RegisterHotKey( int hotkeyId, int modifiers, int virtualKeyCode )	
but I don't know how to attach it to an EVT_HOTKEY.

Re: RegisterHotKey Event

Posted: Fri Feb 28, 2014 2:14 pm
by eranif
Atm, there is no way of connecting hot key from the designer.
However, its pretty straight forward to do that:

Lets assume you want to have 2 hot keys, ID_HOTKEY1 and ID_HOTKEY2:

So, define the hotkey ids:

Code: Select all

#define HOTKEY_ID1 wxID_HIGHEST + 1
#define HOTKEY_ID2 wxID_HIGHEST + 2
In the constructor of the subclass, bind the events and register the hotkeys:

Code: Select all

    // Hot key number 1: Ctrl-T
    RegisterHotKey(HOTKEY_ID1, wxMOD_CONTROL, 'T');
    Bind(wxEVT_HOTKEY, &MyFrame::OnHotKey1, this, HOTKEY_ID1);
    
    // Hot key number 2: Ctrl-R
    Bind(wxEVT_HOTKEY, &MyFrame::OnHotKey2, this, HOTKEY_ID2);
    RegisterHotKey(HOTKEY_ID2, wxMOD_CONTROL, 'R');
Next, add 2 handlers (and their prototypes) in your MyFrame class (or whatever class you have):

Code: Select all

void MyFrame::OnHotKey1(wxKeyEvent& e)
{
}
void MyFrame::OnHotKey2(wxKeyEvent& e)
{
}
and thats it
Note that hot keys are not that different from other events, however, they are implemented only under Windows
Eran