I want to make some custom hot keys where in any program I can bring up different programs with certain key combinations. I researched how to do hooks and was given this example.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
// Set windows hook
HHOOK keyboardHook = SetWindowsHookEx(
WH_KEYBOARD_LL,
keyboardHookProc,
hInstance,
0);
MessageBox(NULL, "Press OK to stop hot keys", "Information", MB_OK);
return 0;
}
Rather than a message box, as I want this to run in the background, I tried using loops but nothing I have tried successfully behaves like the messagebox. Any ideas?
Don’t use windows hooks unless you absolutely need to. In your case you can install a hotkey by calling the
RegisterHotKeyfunction, which is much simpler since you don’t need to develop interprocess communication (that is between your DLL with the hook procedure and your main app).