Old 20th January 2011, 07:55   #1
sanghoang04
Junior Member
 
Join Date: Jan 2011
Posts: 6
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.
sanghoang04 is offline   Reply With Quote
Old 20th January 2011, 12:39   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Just use RegisterHotKey:
code:
#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
Afrow UK is offline   Reply With Quote
Old 20th January 2011, 23:03   #3
sanghoang04
Junior Member
 
Join Date: Jan 2011
Posts: 6
Thank. I see that function, just i don't know it can set for silent mode or not. I'll try it myself.
sanghoang04 is offline   Reply With Quote
Old 21st January 2011, 15:22   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
code:
if (extra->exec_flags->silent)
extra->RegisterPluginCallback(g_hInstance, PluginCallback);

Stu
Afrow UK is offline   Reply With Quote
Old 21st January 2011, 15:25   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,451
SetWindowsHookEx is not the way you normally register a hotkey, there is a specific hotkey api you should use...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 21st January 2011, 15:30   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Quote:
Originally Posted by Anders View Post
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
Afrow UK is offline   Reply With Quote
Old 21st January 2011, 15:37   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,451
Quote:
Originally Posted by Afrow UK View Post
(Windows 2000 and above).
MSDN lies, it works on win95 etc When MSDN says 2000 it often means any 32bit OS

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 21st January 2011, 15:41   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Quote:
Originally Posted by Anders View Post
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
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump