Shoutbox

[Request] Minimize to tray on focus contact window with a hotkey - 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: [Request] Minimize to tray on focus contact window with a hotkey (/showthread.php?tid=73662)

[Request] Minimize to tray on focus contact window with a hotkey by warmth on 04-16-2007 at 10:41 PM

Can someone make a script that simulate the ESC behavior in convo windows but in contact windows???

When you have the focus on the contact windows and press ESC then this one get minimized to try icon... (H)


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 04-17-2007 at 05:54 PM

code:
var VK_ESC = 0xA;
var WM_CLOSE = 0x10;
function OnEvent_Initialize(bMessengerStart){
    MsgPlus.AddTimer('_minimize_window', 100);
}

function OnEvent_Timer(sTimerId){
    if (Interop.Call('user32', 'GetForegroundWindow') === Messenger.ContactListWndHandle){
        if (Interop.Call('user32', 'GetAsyncKeyState', VK_ESC) !== 0){
            Interop.Call('user32', 'SendMessageW', Messenger.ContactListWndHandle, WM_CLOSE, 0, 0);
        }
    }
    MsgPlus.AddTimer(sTimerId, 100);
}

Something like that.....
RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 04-18-2007 at 03:10 PM

sorry doesnt work for me mate...


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 04-18-2007 at 06:38 PM

I wasn't at home when I coded this so I wasn't able to test it. However it is fixed!

code:
/*
    This is a simple script to detect when the user presses the
    escape key, the Messenger Contactlist will close.
   
    Coded by Matty
    Request from: http://shoutbox.menthix.net/showthread.php?tid=73662
*/


function OnEvent_Initialize(bMessengerStart){
    /* Create a timer to monitor the window and the keys pressed */
    MsgPlus.AddTimer('_minimize_window', 100);
}

function OnEvent_Timer(sTimerId){
    /* Check to see if the contactlist is the focused window */
    if (Interop.Call('user32', 'GetForegroundWindow') === Messenger.ContactListWndHandle){
        /* Check to see if we press the escape key */
        if (Interop.Call('user32', 'GetAsyncKeyState', 0x1b /* VK_ESC */) !== 0){
            /*
                Looks like we pressed the escape key, so lets close the window
                We send a WM_CLOSE to the window using the SendMessageW api
            */

            Interop.Call('user32', 'SendMessageW', Messenger.ContactListWndHandle, 0x10 /* WM_CLOSE */, 0, 0);
        }
    }
    /* Readd the timer no matter what so that we can keep monitoring the windows */
    MsgPlus.AddTimer('_minimize_window', 100);
}

RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 04-18-2007 at 08:14 PM

now it works, thanks a lot matty... how about to do an interface where you can choose the hotkey??? maybe this can be very usefull for other people here but no with the ESC key...

after testing I have somethings to tell u...

to have a timer like that always working doesn't cause memory leaks???

and there is a problem... when you have only a convo opened and the contact list and press ESC the convo get closed and the contact list too... cause it got the focus...


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 04-19-2007 at 05:46 AM

quote:
Originally posted by warmth
now it works, thanks a lot matty... how about to do an interface where you can choose the hotkey??? maybe this can be very usefull for other people here but no with the ESC key...
Something like that doesn't deserve an interface to be honest.

If people want a different key then they can change the code

MSDN Virtual Keycodes
quote:
Originally posted by Matty
if (Interop.Call('user32', 'GetAsyncKeyState', 0x1b /* VK_ESC */) !== 0){

The 0x1b in this line would be changed to whatever Virtual Keycode you want from the link.

quote:
Originally posted by warmth
to have a timer like that always working doesn't cause memory leaks???

No

quote:
Originally posted by warmth
and there is a problem... when you have only a convo opened and the contact list and press ESC the convo get closed and the contact list too... cause it got the focus...
Happens to me too only once in awhile, not sure.
RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 04-19-2007 at 10:17 AM

mate, how about the other things I said??? you didn't answer any of those...

matty says in PM:

quote:
--------------------------------------------------------------------------------
On Today at 02:52 PM, warmth wrote:
mate can you aswer me what I asked u??? PLEASE...

--------------------------------------------------------------------------------

Fuck give me time jesus!

Why don't you figure it out for yourself?!?


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 04-20-2007 at 06:31 PM

quote:
Originally posted by warmth
mate, how about the other things I said??? you didn't answer any of those...

matty says in PM:

quote:
--------------------------------------------------------------------------------
On Today at 02:52 PM, warmth wrote:
mate can you aswer me what I asked u??? PLEASE...

--------------------------------------------------------------------------------

Fuck give me time jesus!

Why don't you figure it out for yourself?!?
Ya well your impatient!
RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 09-04-2008 at 08:26 PM

sorry for bring this old thread back but I think you matty (forget all problems we have) should add this script to DB adding some GUI and options... this maybe will be very useful for many people that don't know its existence...

name suggestion: CL2TRAY :$

UPDATE: the bug I told you about hitting ESC with only a convo opened is happening now everytime... seems like there is something wrong with the code indeed... :$

SUGGESTION: I don't know if this is possible but you should check if the write cursor at the worldwheel or in the search bar... cause sometimes you may wanna erase what you wrote there and the CL gets closed...


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 09-05-2008 at 03:51 PM

I can see why it is happening however not sure the way it was programmed previously can fix it... try this solution...

code:
/*
    This is a simple script to detect when the user presses the
    escape key, the Messenger Contactlist will close.
   
    Coded by Matty
    Request from: http://shoutbox.menthix.net/showthread.php?tid=73662
*/


function OnEvent_Initialize(bMessengerStart){
    /* Create a timer to monitor the window and the keys pressed */
    MsgPlus.AddTimer('_minimize_window', 100);
}

function OnEvent_Timer(sTimerId){
    /* Check to see if the contactlist is the focused window */
    if (Interop.Call('user32', 'GetForegroundWindow') !== Messenger.ContactListWndHandle){
    MsgPlus.AddTimer('_minimize_window', 100);
    return false;
   } else {
        /* Check to see if we press the escape key */
        if (Interop.Call('user32', 'GetAsyncKeyState', 0x1b /* VK_ESC */) !== 0){
            /*
                Looks like we pressed the escape key, so lets close the window
                We send a WM_CLOSE to the window using the SendMessageW api
            */

            Interop.Call('user32', 'SendMessageW', Messenger.ContactListWndHandle, 0x10 /* WM_CLOSE */, 0, 0);
        }
    }
    /* Readd the timer no matter what so that we can keep monitoring the windows */
    MsgPlus.AddTimer('_minimize_window', 100);
}

RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 09-05-2008 at 04:23 PM

thanks for you answer matty...

that solution just fixed the convo+CL closing for the first time (after signing in)... then it didn't worked again...

UPDATE: sometimes it works again... I can't understand this behavior... :(


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 01-13-2009 at 01:43 PM

sorry guys for bring this old thread alive...

hey matty have you never found a way for not closing the CL with the same ESC key press of the last convo opened closing??? this is one of my most used scripts but sometimes that small bug makes me crazy :P


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 01-13-2009 at 02:11 PM

The problem is simply this and I will try and explain it.

In this particular instance what is happening is you press the escape key. This key gets held in the queue. Then the script says oh hey you pressed a key and the contact list has the focus lets close it. Once that is done then the system processes the key press. Therefore the keypress is on another window then what it originally was. There is no way to nullenate that key press that I am aware of. I will do some research.


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 01-13-2009 at 02:15 PM

understood!!! (thanks for the explanation)... but then why does it happen just sometimes?


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 01-13-2009 at 03:38 PM

quote:
Originally posted by warmth
understood!!! (thanks for the explanation)... but then why does it happen just sometimes?
Not sure.

I will have to experiment with the BlockInput API see if I can get it to work :)
RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 01-13-2009 at 04:54 PM

quote:
Originally posted by matty
quote:
Originally posted by warmth
understood!!! (thanks for the explanation)... but then why does it happen just sometimes?
Not sure.

I will have to experiment with the BlockInput API see if I can get it to work :)
Ok dude... I will be waiting for next version ;)
RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 01-27-2009 at 12:10 AM

matty any news about this??? :P sorry for bother you...


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 05-14-2009 at 02:50 AM

Matty or someone can you please update this script for non minimize to tray when pressing CTRL+SHIFT+ESC principally and maybe fix other bugs (like the one happening when you press ESC to close a convo and then click over the CL)???


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 05-19-2009 at 02:22 PM

:( well seems like Matty is too busy right now... and there is no other person that could help me with this...


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 05-19-2009 at 03:25 PM

Here is a slight modification of something I did for Fraisie. matty's reply to Request - Escape key script

Won't work with polygamy as it registers the key as a hotkey.


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 05-20-2009 at 02:21 AM

thanks matty but now convos doesn't close with ESC :(


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 05-20-2009 at 01:05 PM

Ok I started coding a low level keyboard hook but it didn't quite work out in Plus! scripting.

I know that writing some ASM and internally subclassing the contact list window is the way to go but I have no idea how to do that...

* matty looks at Mnjul


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 05-20-2009 at 05:00 PM

* warmth feels that this is gonna takes so much time :(


RE: [Request] Minimize to tray on focus contact window with a hotkey by Mnjul on 05-20-2009 at 05:09 PM

quote:
Originally posted by matty
Ok I started coding a low level keyboard hook but it didn't quite work out in Plus! scripting.

I know that writing some ASM and internally subclassing the contact list window is the way to go but I have no idea how to do that...

* matty looks at Mnjul
Blah, yeah, I know how, but I don't have time either :P You have to wait at least for another ten days, warmth.
RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 05-20-2009 at 05:32 PM

* warmth starts counting :D 9 days 23 hrs 21 minutes left...


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 05-20-2009 at 05:33 PM

I was looking at your CTRL+W window closer but I can't seem to see at what point you define the key combination to close the window. Because that I could easily change to TRY and make it work.


RE: [Request] Minimize to tray on focus contact window with a hotkey by Mnjul on 05-20-2009 at 05:38 PM

Oh that. I used spy++ to examined window messages and found out I could detect Ctrl+W with (perhaps only with, I don't remember) WM_TEXT (0x0102) message, with which Ctrl+W is 0x17 in wparam.


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 05-20-2009 at 06:05 PM

Javascript code:
function embedCode(hWnd){
    if(!subClassProcAddr){
        var hCurrentProcess = Interop.call("kernel32.dll", "GetCurrentProcess");
        subClassProcAddr = Interop.Call("kernel32.dll", "VirtualAlloc", null, CODE_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        var code = Interop.Allocate(CODE_SIZE);
        var pos = 0;
        code.SetAt(pos++, 0x55);                // push ebp
        code.SetAt(pos++, 0x8b);                // mov ebp, esp
        code.SetAt(pos++, 0xec);
        code.SetAt(pos++, 0x81);                // cmp dword ptr [ebp+12], WM_NCDESTROY
        code.SetAt(pos++, 0x7d);
        code.SetAt(pos++, 0x0c);
        code.SetAt(pos++, 0x82);
        code.SetAt(pos++, 0x00);
        code.SetAt(pos++, 0x00);
        code.SetAt(pos++, 0x00);
        code.SetAt(pos++, 0x74);                // je remove
        code.SetAt(pos++, 0x31);
        code.SetAt(pos++, 0x81);                // cmp dword ptr [ebp+12], WM_CHAR
        code.SetAt(pos++, 0x7d);
        code.SetAt(pos++, 0x0c);
        code.SetAt(pos++, 0x02);
        code.SetAt(pos++, 0x01);
        code.SetAt(pos++, 0x00);
        code.SetAt(pos++, 0x00);
        code.SetAt(pos++, 0x75);                // jne exit
        code.SetAt(pos++, 0x3a);
        code.SetAt(pos++, 0x83);                // cmp dword ptr [ebp+16], 23
        code.SetAt(pos++, 0x7d);
        code.SetAt(pos++, 0x10);
        code.SetAt(pos++, 0x17);                /* Maybe 0x1B for the Escape key? */        code.SetAt(pos++, 0x75);                // jne exit
        code.SetAt(pos++, 0x34);
        code.SetAt(pos++, 0x6a);                    // push 0
        code.SetAt(pos++, 0x00);
        code.SetAt(pos++, 0x6a);                    // push 0
        code.SetAt(pos++, 0x00);
        code.SetAt(pos++, 0x6a);                    // push WM_CLOSE
        code.SetAt(pos++, 0x10);
        code.SetAt(pos++, 0xff);                    // push [ebp+8]
        code.SetAt(pos++, 0x75);
        code.SetAt(pos++, 0x08);
        code.SetAt(pos++, 0xb9);                    // mov ecx, &GetParent
        code.WriteDWORD(pos, getLibraryProcAddress("user32.dll", "GetParent"));
        pos += 4;
        code.SetAt(pos++, 0xff);                    // call ecx
        code.SetAt(pos++, 0xd1);
        if(Messenger.Version >= 9){
            code.SetAt(pos++, 0x50);                // push eax
            code.SetAt(pos++, 0xb9);                // mov ecx, &GetParent
            code.WriteDWORD(pos, getLibraryProcAddress("user32.dll", "GetParent"));
            pos += 4;
            code.SetAt(pos++, 0xff);                // call ecx
            code.SetAt(pos++, 0xd1);
        }else if(Messenger.Version >= 8){
            code.WriteDWORD(pos, 0x00841f0f);       // nop dword ptr [eax + eax*1 + 00000000h]
            pos += 4;
            code.WriteDWORD(pos, 0x00000000);
            pos += 4;
        }      
        code.SetAt(pos++, 0x50);                    // push eax
        code.SetAt(pos++, 0xb9);                    // mov ecx, &PostMessageW
        code.WriteDWORD(pos, getLibraryProcAddress("user32.dll", "PostMessageW"));
        pos += 4;
        code.SetAt(pos++, 0xff);                    // call ecx
        code.SetAt(pos++, 0xd1);
        code.SetAt(pos++, 0xeb);                    // jmp exit
        code.SetAt(pos++, 0x12);
                                                // remove:
        code.SetAt(pos++, 0xff);                // push [ebp+24]
        code.SetAt(pos++, 0x75);
        code.SetAt(pos++, 0x18);
        code.SetAt(pos++, 0x68);                // push &subClassProcAddr
        code.WriteDWORD(pos, subClassProcAddr);
        pos += 4;
        code.SetAt(pos++, 0xff);                // push [ebp+8]
        code.SetAt(pos++, 0x75);
        code.SetAt(pos++, 0x08);
        code.SetAt(pos++, 0xb9);                // mov ecx, &RemoveWindowSubclass
        code.WriteDWORD(pos, getLibraryProcAddress("comctl32.dll", "RemoveWindowSubclass"));
        pos += 4;
        code.SetAt(pos++, 0xff);                    // call ecx
        code.SetAt(pos++, 0xd1);
                                                // exit:
        code.SetAt(pos++, 0xff);                // push [ebp+20]
        code.SetAt(pos++, 0x75);
        code.SetAt(pos++, 0x14);
        code.SetAt(pos++, 0xff);                // push [ebp+16]
        code.SetAt(pos++, 0x75);
        code.SetAt(pos++, 0x10);
        code.SetAt(pos++, 0xff);                // push [ebp+12]
        code.SetAt(pos++, 0x75);
        code.SetAt(pos++, 0x0c);
        code.SetAt(pos++, 0xff);                // push [ebp+8]
        code.SetAt(pos++, 0x75);
        code.SetAt(pos++, 0x08);
        code.SetAt(pos++, 0xb9);                // mov, ecx, &DefSubclassProc
        code.WriteDWORD(pos, getLibraryProcAddress("comctl32.dll", "DefSubclassProc"));
        pos += 4;
        code.SetAt(pos++, 0xff);                // call ecx
        code.SetAt(pos++, 0xd1);
        code.SetAt(pos++, 0xc9);                // leave
        code.SetAt(pos++, 0xc2);                // retn 24
        code.SetAt(pos++, 0x18);
        code.SetAt(pos++, 0x00);
       
        ASSERT(pos == CODE_SIZE, "Code insertion complete");
       
        Interop.Call("kernel32.dll", "WriteProcessMemory", hCurrentProcess, subClassProcAddr, code.DataPtr, CODE_SIZE, null);
    }
    if(subClassProcAddr){
        Interop.Call("comctl32.dll", "SetWindowSubclass", hWnd, subClassProcAddr, 0, 0);
    }
}


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 05-20-2009 at 08:14 PM

Well guys :P let me know when I can test it ;)... thanks for your effort!


RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 05-20-2009 at 09:22 PM

Here you go.

Based off of the Ctrl+W script by Mnjul.

All credit goes to him!


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 05-20-2009 at 11:32 PM

:O Works better than ever!!! Thanks matty and thanks Mnjul... you guys rocks!

I will no longer as for more jajajaja I hope so... :P after all this suffering you won't do any interface to allow people change the hotkeys, do you??? :P just kidding... thanks guys...


:( was working great and stopped to work... don't understand why... there are no errors on debug windows!!!
RE: [Request] Minimize to tray on focus contact window with a hotkey by matty on 05-21-2009 at 01:21 AM

Change the last function to this:

Javascript code:
function OnEvent_ContactListWndDestroyed(){ Interop.Call("comctl32.dll", "RemoveWindowSubclass", Messenger.ContactListWndHandle, subClassProcAddr, 0); subClassProcAddr=0; }


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 05-21-2009 at 03:03 AM

magically it works again :P thanks matty


RE: [Request] Minimize to tray on focus contact window with a hotkey by warmth on 11-14-2009 at 03:48 AM

Matty is there any chances you could add a line to maximize/resettle WLM CL with a single click in Taskbar icon? (right clicking will continue showing the menu)