RegisterHotKey Event

Post here wxCrafter related issues / features / bugs
musictreeAstro
CodeLite Curious
Posts: 7
Joined: Sat Sep 14, 2013 1:50 am
Genuine User: Yes
IDE Question: C++
Contact:

RegisterHotKey Event

Post 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.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: RegisterHotKey Event

Post 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
Make sure you have read the HOW TO POST thread
Post Reply