Bring back the active off screen window with AutoHotkey

Howdy!

The following script can bring back the Find and Replace window which sometimes goes off screen:
CoordMode, Mouse, Screen
^+m::
    MouseGetPos, x, y
    WinMove A,, %x%, %y%
return

Source: https://www.youtube.com/watch?v=YStr_W9acpw . Check minute 0:30.
Credits to Joe and Isaías.

emoji
Parents
  • It's probably something very obvious, but I don't have much experience with AHK yet. I watched the video, and I don't get what I'm doing wrong, but it doesn't work. The screen does move, but not necessarily to my mouse. Sometimes it even disappears. This is what my script looks like:

    Screenshot of an AHK script with code to bring a window to the mouse position using MouseGetPos and WinMove commands.

    I don't see why that's not correct. Would you have any idea? Below the video, they're saying this:

    Screenshot of a user's comment asking for help about their script not moving the window to the mouse cursor, mentioning they have 4 monitors.

    But what does that effectively mean?

    emoji


    Generated Image Alt-Text
    [edited by: Trados AI at 4:32 AM (GMT 0) on 5 Mar 2024]
  • Hi ,

    I don't see why that's not correct. Would you have any idea?

    Ummm… I think you are right. Please try bringing the CoordMode line below the ^+m line, as krad said in the comments:

    ^+m::
        CoordMode, Mouse, Screen   
        MouseGetPos, x, y
        WinMove A,, %x%, %y%
    return

    I’ve tested it and it works. If you confirm it works for you as well, I’ll edit the script in my original post.

    You need to do 2 things:

    1. First you need to bring the window with issues to first  (via ALT+TAB or selecting it in the the task bar).
    2. Only then, run the script (pressing CTRL+SHIFT+M keys).

    Alternatively, you can skip step 1 with the following script, which moves only the Find and Replace window and without selecting it first:

    ^+m::
        CoordMode, Mouse, Screen   
        MouseGetPos, x, y
        WinMove Find and Replace,, %x%, %y%
    return

    But what does that effectively mean?

    Joe mentioned to use the line CoordMode, Mouse, Screen

    And Krad included the above line below the ^+m line in order for the script to work.

    emoji
Reply
  • Hi ,

    I don't see why that's not correct. Would you have any idea?

    Ummm… I think you are right. Please try bringing the CoordMode line below the ^+m line, as krad said in the comments:

    ^+m::
        CoordMode, Mouse, Screen   
        MouseGetPos, x, y
        WinMove A,, %x%, %y%
    return

    I’ve tested it and it works. If you confirm it works for you as well, I’ll edit the script in my original post.

    You need to do 2 things:

    1. First you need to bring the window with issues to first  (via ALT+TAB or selecting it in the the task bar).
    2. Only then, run the script (pressing CTRL+SHIFT+M keys).

    Alternatively, you can skip step 1 with the following script, which moves only the Find and Replace window and without selecting it first:

    ^+m::
        CoordMode, Mouse, Screen   
        MouseGetPos, x, y
        WinMove Find and Replace,, %x%, %y%
    return

    But what does that effectively mean?

    Joe mentioned to use the line CoordMode, Mouse, Screen

    And Krad included the above line below the ^+m line in order for the script to work.

    emoji
Children