Shoutbox

HELP - Hotkeys! - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: HELP - Hotkeys! (/showthread.php?tid=90980)

HELP - Hotkeys! by whiz on 06-08-2009 at 05:05 PM

Basically, I need a hotkey that can be used anywhere (is this called "global"?), but I'm not sure how to go about it.  I have had a look in a few scripts (including Matty's hotkey example script), but either they're for picking up the key combination within a window, or I have no idea how it works...  :S


RE: HELP - Hotkeys! by SmokingCookie on 06-08-2009 at 05:12 PM

The problem with some scripts is, that they cannot be used anywhere (indeed "global"). They only listen for keypresses when a window is in the foreground (which is called "local"; although I still have problems specifying whether the window is actually in the foreground..).

However, you may try Matti's "Countdown live" script. There's a file called "GlobalHotkey.js". See if you can do anything with that ;)


RE: HELP - Hotkeys! by Mnjul on 06-08-2009 at 05:18 PM

Well you can also look into my HopperLive script's CHopkeyReceiver.js file. Basically you just need to know how RegisterHotKey() API works, how PlusWnd.RegisterMessageNotification() works and how OnWindowIdEvent_MessageNotification() works :)


RE: HELP - Hotkeys! by whiz on 06-08-2009 at 06:19 PM

I've added the following lines to my script:

js code:
var MOD_ALT = 0x1;
var MOD_CONTROL = 0x2;
var MOD_SHIFT = 0x4;
var WndSbc = MsgPlus.CreateWnd("Windows.xml", "WndSubclass", 2);
RegisterHotKey(WndSbc.Handle, "OpenMenu", MOD_ALT + MOD_SHIFT, 0x4D);
...but the debugger shows "Error: Object expected (code: -2146823281)".

Do I need to register the hotkey with the window, like this:
js code:
WndSbc.RegisterHotKey(WndSbc.Handle, "OpenMenu", MOD_ALT + MOD_SHIFT, 0x4D);

EDIT: updated the top code (included Alt/Control/Shift variables) - still doesn't work, though.
RE: HELP - Hotkeys! by Matti on 06-08-2009 at 06:35 PM

"RegisterHotkey" is a Win32 API function and is located in the "user32.dll" library. You can find this at the bottom of the MSDN page. This means you have to use Interop.Call() to call this function.


RE: HELP - Hotkeys! by whiz on 06-08-2009 at 06:46 PM

js code:
Interop.Call("user32", "RegisterHotKey", WndSbc.Handle, "OpenMenu", MOD_ALT + MOD_SHIFT, 0x4D);

And if that is the case, how can I monitor it so I can perform an action when the combination is pressed?

EDIT: It works with just "MOD_ALT", or with just "MOD_SHIFT", but can I use both?
RE: HELP - Hotkeys! by SmokingCookie on 06-08-2009 at 06:57 PM

MOD_ALT | MOD_SHIFT?

Also, what you do with the "OpenMenu" thingy is wrong. you have to send a number, not a string. This works, because Plus! sends the pointer to your string (which is actually a number), but you need to use something like 0x100.


RE: HELP - Hotkeys! by whiz on 06-08-2009 at 07:02 PM

Ok.  Just one other thing.  "MOD_CONTROL" and "MOD_ALT" work fine, but I can't seem to get "MOD_SHIFT" to work (0x4).  Is this the wrong number?


RE: HELP - Hotkeys! by SmokingCookie on 06-08-2009 at 07:05 PM

Weird, it is the right number...

Also (just to make sure you know about this), in the OnWindowIDEvent_MessageNotification() function, you might want to check for the hotkey identifier (that is the 0x100 number I told ya about). The wParam is this identifier.


RE: HELP - Hotkeys! by whiz on 06-08-2009 at 07:10 PM

js code:
function OnWndSubclassEvent_MessageNotification(PlusWnd, Message, wParam, lParam)
{
    if (wParam == 0x100)
    {
        // ...
    }
}
Like that?
RE: HELP - Hotkeys! by SmokingCookie on 06-08-2009 at 07:15 PM

Yep. What also works (and saves some typing) is this:

JScript code:
function OnWndSubclassEvent_MessageNotification(PlusWnd,Message,wParam,lParam) {
    switch(wParam) {
        case 0x100:
            // do stuff
        break;
        case 0x101: // A different ID for a different hotkey
            // do other stuff
        break;
        case 0xN:
            // do other other stuff
        break;
    }
    // do whatever else ya want
}

RE: HELP - Hotkeys! by whiz on 06-08-2009 at 07:39 PM

Although I won't need that, since I only plan to use one notification.  :)


RE: HELP - Hotkeys! by SmokingCookie on 06-08-2009 at 07:42 PM

Just to let ya know ;)


RE: HELP - Hotkeys! by whiz on 06-08-2009 at 08:39 PM

Actually, I changed my mind.  ;)  It's going to have multiple menus (code incorporated)...  :D


RE: HELP - Hotkeys! by SmokingCookie on 06-09-2009 at 12:12 PM

Told you :P

How are you actually planning to do your menus?


RE: HELP - Hotkeys! by whiz on 06-10-2009 at 07:26 PM

I've just finished the script, and I'll make a topic for it in a mo (it's called "QuickKey").  :D