This article will show you how to use the
CHotkeyHandler class in order to manage and create global hotkeys.
Using the code
void handA(void *)
printf("this is A\n");
void handQ(void *)
printf("this is Q\n");
void hand1(void *param)
WinExec((char *)param, SW_SHOW);
int err, id;
hk.InsertHandler(MOD_CONTROL | MOD_ALT, 'Q', handQ, id);
hk.InsertHandler(MOD_CONTROL | MOD_ALT, 'A', handA, id);
hk.InsertHandler(MOD_CONTROL | MOD_ALT, '1', hand1, id);
err = hk.Start("calc.exe");
if (err != CHotkeyHandler::hkheOk)
printf("Error %d on Start()\n", err);
printf("hotkeys started!!!\n...press any key to stop them...\n");
err = hk.Stop();
First we declare a
CHotkeyHandler instance. We then start inserting the hotkeys defined by their Control key, Virtual Key, Callback function. The
InsertHandler() will return us an identifier for the registered hotkey. You can use this id with the
RemoveHandler(). After we have inserted our handlers you can enable the hotkeys by calling
Start(). You should always check for error codes returned by the
CHotkeyHandler methods. The
Start() will take an optional parameter that will be passed to the registered callback when it gets invoked. We then disable all hotkeys via
For more information about error codes and other methods description please refer to the CHotkeyHandler.cpp file. That's all.
- 9 May 2003
- Initial CodeProject version
- 20 Oct 2003
Elias (aka lallousx86, @0xeb) has always been interested in the making of things and their inner workings.
His computer interests include system programming, reverse engineering, writing libraries, tutorials and articles.
In his free time, and apart from researching, his favorite reading topics include: dreams, metaphysics, philosophy, psychology and any other human/mystical science.
Former employee of Hex-Rays (the creators of IDA Pro), was responsible about many debugger plugins, IDAPython project ownership and what not.
Elias currently works at Microsoft as a software security engineer.
More articles and blog posts can be found here: