What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » RegisterHotKey

RegisterHotKey
Author: Message:
PaulE
Junior Member
**


Posts: 28
Joined: Jul 2006
O.P. RegisterHotKey
Hello Folks,

I'm trying to use the RegisterHotKey function, however.. I'm stuck. What I want is to let my script react on two hotkeys (Alt+Q and Alt+W). Can anyone help me a bit with it? This is what I got so far, but I don't know what to do next:

js code:
function OnEvent_Initialize(MessengerStart)
{
    if(Messenger.MyStatus !== STATUS_UNKNOWN)
    {
        OnEvent_SigninReady(Messenger.MyEmail);
    }
}

function OnEvent_Uninitialize(MessengerExit)
{
}

function OnEvent_SigninReady(Email)
{
    _hotkey = MsgPlus.CreateWnd('Hotkey.xml', 'WndHotkey', 2);
    _hotkey.RegisterMessageNotification(WM_HOTKEY, true);
   
    // Interop.Call('user32', "RegisterHotKey", _hotkey.Handle,              <- Stuck from here
}

function lobyte(w) { return w & 0xff; }
function hibyte(w) { return w >> 8; }

This is my Hotkey.xml
xml code:
<?xml version="1.0" encoding="UTF-16"?>
<Interfaces xmlns="urn:msgplus:interface" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:msgplus:interface PlusInterface.xsd" Name="Message Notifier">
    <Window Id="WndHotkey" Version="1">
        <Attributes>
            <ShowInTaskbar>False</ShowInTaskbar>
        </Attributes>
        <DialogTmpl/>
        <Position Width="0" Height="0" />
    </Window>
</Interfaces>

So what do I have to put as parameters for the Call() function, and how can I make this script execute two different functions when the hotkeys are being pressed?

Thanks in advance!

This post was edited on 05-15-2011 at 03:23 PM by PaulE.
05-15-2011 03:21 PM
Profile PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: RegisterHotKey
You can register hotkeys like this:
jscript code:
Interop.Call("user32", "RegisterHotKey", _hotkey.Handle, ID, Mods, Key);
...where ID is a number relating to the action (so you can tell what combination was pressed later), Mods is the numerical representation of all modifiers you wish to use (in your case, Alt = 1), and Key is the code for the keys you wish to use (Q = 81, W = 87 - see my function below for generating key codes for letters).

Process key combinations using the message notification:
jscript code:
function OnWndHotkeyEvent_MessageNotification(PlusWnd, Message, wParam, lParam)
{
    switch (wParam)
    {
        case 1:
            // ...
            break;
    }
}
The wParam holds the ID you set when you registered the hotkey.

You will also need to unregister hotkeys (i.e. when the user signs out, or when Messenger is closed - whichever is more appropriate), otherwise they will not register next time.
jscript code:
Interop.Call("user32", "UnregisterHotKey", _hotkey.Handle, ID);
Use the same ID as when you registered them.

Also, is WM_HOTKEY (= 0x312) defined?



You can use this to convert letters and numbers to codes, and back again:
jscript code:
var Letters = "0123456789       ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
var Count = 0x30;
var Codes = [];
for (var Letter in Letters)
{
    if (Letters[Letter] !== " ")
    {
        Codes[Count] = Letters[Letter].toString();
        Codes[Letters[Letter]] = Count;
    }
    Count++;
}
Use Codes['A'] or Codes['1'] to generate codes, or Codes[70] to convert back.

This post was edited on 05-16-2011 at 08:04 AM by whiz.
05-15-2011 06:49 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On