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

HotKeys ?
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: HotKeys ?
Firstly, try not to revive old threads like this. They're great for reference but if you have a particular question about it, it's better to start a new thread. ;)

Now, working with global hotkeys is not a very simple thing to do. Countdown Live includes a class which makes this a lot easier to do, but it's still pretty advanced stuff. The following steps should be followed up precisely, otherwise you might crash Messenger. :P

In the latest version of Countdown Live, you'll find a file called GlobalHotkey.js which contains all logic for working with system-wide hotkeys. To use this class, you'll have to do a few things:
  1. Copy "GlobalHotkey.js" from Countdown Live to your script folder.
    You'll have to change one thing though. Find this line:
    js code:
    Trace(bPaused ? "> Global hotkeys paused" : "> Global hotkeys re-enabled");
    and remove it. This was just some debug code which uses my custom Trace() function. There's no need to keep this line, but if you do keep it you'll need to have a Trace() function as well. Therefore, it's better to just delete it.
  2. In order to capture hotkey presses, the class needs to create a subclass window to listen to window notifications. Therefore, you need to copy "WndSubclass.xml" from the Interfaces folder as well. This window won't be visible in any way but is required to capture these notifications.
  3. Pick a key combination to use. In this example, I'll use Ctrl+Alt+R as an example.
  4. Look up the virtual-key codes for your chosen combination. You can find all key codes with their hexadecimal codes on MSDN. For the sample combination, you need the key code for "A" which is 0x41.
  5. In your OnEvent_Initialize handler, you need to add some code to correctly start the class.
    • In the subclass configuration, make sure the InterfacePath and WindowId properties correctly point to the subclass window.
    • The registry functions are used to clean up hot keys after the script has suddenly stopped working. I put in two simply functions which read and write to a "SubclassHandle" key value inside the script's registry key. If you already use another set of registry functions, you can replace the code in these handlers with your custom registry calls. Just make sure that they work! ;)
    • The interesting part is where you create the hotkey. Here, you use the virtual-key code for the main key and some constants for the key modifiers (MOD_CTRL, MOD_ALT, MOD_SHIFT and/or MOD_WIN). You also need to specify a function which will be called when the hotkey is pressed. For this example, I used an anonymous function which writes something to the debug window and then calls your reFloat() function. (You'll probably want to check whether the current user is logged in before you call reFloat() though.)
    js code:
    function OnEvent_Initialize(MessengerStart) {
        // Subclass configuration
        GlobalHotkey.Subclass.InterfacePath = "WndSubclass.xml";
        GlobalHotkey.Subclass.WindowId = "WndSubclass";
        GlobalHotkey.Subclass.Registry.GetValue = function() {
            new ActiveXObject("WScript.Shell").RegRead( MsgPlus.ScriptRegPath + "SubclassHandle");
        };
        GlobalHotkey.Subclass.Registry.SetValue = function(handle) {
            new ActiveXObject("WScript.Shell").RegWrite( MsgPlus.ScriptRegPath + "SubclassHandle", handle, "REG_DWORD");
        };
        // Hotkey registration
        var HotkeyID = "MyPlusScript::reFloat"; // Unique identifier
        var KeyCode = 0x41; // A key
        var Modifiers = MOD_CONTROL | MOD_ALT; // Ctrl + Alt
        var Callback = function() {
            Debug.Trace("Hotkey pressed!");
            reFloat();
        };
        GlobalHotkey.Add(HotkeyID, KeyCode, Modifiers, Callback);
        // Configuration is done, now get this thing started
        GlobalHotkey.Init();
    }
  6. Add this cleanup code to your OnEvent_Uninitialize handler:
    js code:
    function OnEvent_Uninitialize(MessengerExit) {
        GlobalHotkey.DeleteAll();
        GlobalHotkey.Destroy();
    }
  7. Finally, you need to add the hotkey notification handler to the notification event of the subclass window.
    js code:
    function OnWndSubclassEvent_MessageNotification(PlusWnd, Message, wParam, lParam) {
        if(GlobalHotkey.HandleNotification(arguments)) return -1;
    }
Yes, that's a pretty long list but I believe you should be able to pull this off if you have a bit of scripting experience. :)

This post was edited on 11-28-2010 at 11:14 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-27-2010 10:45 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
HotKeys ? - by Xat on 10-28-2008 at 05:51 PM
RE: HotKeys ? - by matty on 10-28-2008 at 06:26 PM
RE: HotKeys ? - by Matti on 10-28-2008 at 06:45 PM
RE: RE: HotKeys ? - by V@no on 11-27-2010 at 04:59 AM
RE: HotKeys ? - by Matti on 11-27-2010 at 10:45 AM
RE: HotKeys ? - by V@no on 11-27-2010 at 05:47 PM
RE: HotKeys ? - by Matti on 11-28-2010 at 11:15 AM


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