Archive: Global HotKey Plugin with global hook


Global HotKey Plugin with global hook
I have write a hotkey plugin using global hook WH_KEYBOARD_LL. In my dll plugin I have callback KeyboardProc (normally, get Ctrl+Shift+Q), NSIS function SetHotKey (SetWindowsHookEx), and DllMain (with g_hInstance on DLL_PROCESS_ATTACH, UnHookWindowsHookEx on DLL_PROCESS_DETACH).
In my script, I call SetHotKey, but seem it's not working, when i try dumpstate plugin - dumpstate::debugger right after SetHotKey call, debugger window display, at that time, I press combine keys (Ctrl+Shift+Q), wow it working. Now know it, I see somewhere in msdn say that one of these function (i don't remember) must in process message queue to hook working, so it seem my nsis plugin not get into nsis message. So anyone can have any solution for this, or can have another HotKey plugin? (I use this plugin in silent mode).



Ps: I'm not English man, so my English not good.


Just use RegisterHotKey:

#define HOTKEY_ID 1

RegisterHotKey(NULL, HOTKEY_ID, MOD_CONTROL | MOD_ALT | MOD_SHIFT, 'K');

while (!fDone)
{
MSG msg;
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) && msg.message == WM_HOTKEY)
{
// do something here
}
}

UnregisterHotKey(NULL, HOTKEY_ID);
You should only create your own message loop if extra->exec_flags->silent is set. Otherwise you can subclass the outer window (hwndParent). Also if you use your own message loop you can set fDone to TRUE yourself when the PluginCallback is called and msg == NSPIM_UNLOAD.

Stu

Thank. I see that function, just i don't know it can set for silent mode or not. I'll try it myself.


if (extra->exec_flags->silent)
extra->RegisterPluginCallback(g_hInstance, PluginCallback);
Stu

SetWindowsHookEx is not the way you normally register a hotkey, there is a specific hotkey api you should use...


Originally posted by Anders
SetWindowsHookEx is not the way you normally register a hotkey, there is a specific hotkey api you should use...
RegisterHotKey is the one I use and that seems to work nicely (Windows 2000 and above).

Stu

Originally posted by Afrow UK
(Windows 2000 and above).
MSDN lies, it works on win95 etc When MSDN says 2000 it often means any 32bit OS

Originally posted by Anders
MSDN lies, it works on win95 etc When MSDN says 2000 it often means any 32bit OS
Ah awesome that's good to know thanks :)

Stu