hover mouse over window and move mouse to resize window using autohotkey












1















I'm trying to creating a script that allows user to resize a window by hovering the mouse by pressing a keyboard shortcut without having to move a mouse to corner of a window each time.



This feature is currently available as part of BetterSnapTool for Mac OS X but I'm trying to develop the same feature for Windows 10 using AutoHotkey



I've developed a script for autohotkey that works well for most applications except for chrome and spotify (see below). It often gets stuck with the title bar menu open after hitting alt+space see video here



^+x::
MouseGetPos,,, hwnd
WinActivate, ahk_id %hwnd%
Send !{Space}
Sleep 1
Send m
sleep 1
send {down}
Return


Is there a more reliable way can do this?










share|improve this question



























    1















    I'm trying to creating a script that allows user to resize a window by hovering the mouse by pressing a keyboard shortcut without having to move a mouse to corner of a window each time.



    This feature is currently available as part of BetterSnapTool for Mac OS X but I'm trying to develop the same feature for Windows 10 using AutoHotkey



    I've developed a script for autohotkey that works well for most applications except for chrome and spotify (see below). It often gets stuck with the title bar menu open after hitting alt+space see video here



    ^+x::
    MouseGetPos,,, hwnd
    WinActivate, ahk_id %hwnd%
    Send !{Space}
    Sleep 1
    Send m
    sleep 1
    send {down}
    Return


    Is there a more reliable way can do this?










    share|improve this question

























      1












      1








      1


      2






      I'm trying to creating a script that allows user to resize a window by hovering the mouse by pressing a keyboard shortcut without having to move a mouse to corner of a window each time.



      This feature is currently available as part of BetterSnapTool for Mac OS X but I'm trying to develop the same feature for Windows 10 using AutoHotkey



      I've developed a script for autohotkey that works well for most applications except for chrome and spotify (see below). It often gets stuck with the title bar menu open after hitting alt+space see video here



      ^+x::
      MouseGetPos,,, hwnd
      WinActivate, ahk_id %hwnd%
      Send !{Space}
      Sleep 1
      Send m
      sleep 1
      send {down}
      Return


      Is there a more reliable way can do this?










      share|improve this question














      I'm trying to creating a script that allows user to resize a window by hovering the mouse by pressing a keyboard shortcut without having to move a mouse to corner of a window each time.



      This feature is currently available as part of BetterSnapTool for Mac OS X but I'm trying to develop the same feature for Windows 10 using AutoHotkey



      I've developed a script for autohotkey that works well for most applications except for chrome and spotify (see below). It often gets stuck with the title bar menu open after hitting alt+space see video here



      ^+x::
      MouseGetPos,,, hwnd
      WinActivate, ahk_id %hwnd%
      Send !{Space}
      Sleep 1
      Send m
      sleep 1
      send {down}
      Return


      Is there a more reliable way can do this?







      resize window autohotkey window-resize






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 19:40









      jerrysperryjerrysperry

      164




      164
























          2 Answers
          2






          active

          oldest

          votes


















          1














          I was able to solve this reliably by moving the mouse to the top right of the window next the minimize button and leaving the mouse button down while using blockinput.



          Benefits:




          • This allows the the user to move the mouse freely to move the window.

          • It works for resizing as well.

          • being able to move windows if they're snapped fullscreen.


          TIP: script has to be run as administrator for blockinput to work...



          ;Move Window Mode
          ^+x::
          KeyWait Shift
          KeyWait Alt
          BlockInput, On
          MouseGetPos,,, hwnd
          WinActivate, ahk_id %hwnd%
          WinGetPos, , , Width, Height, A
          MouseMove, Width-186, 10
          Click, down
          Send {Shift Up}
          Send {Ctrl Up}
          BlockInput, Off
          Return

          ;Resize Window Mode
          ^+z::
          KeyWait Shift
          KeyWait Alt
          BlockInput, On
          MouseGetPos,,, hwnd
          WinActivate, ahk_id %hwnd%
          WinGetPos, , , Width, Height, A
          MouseMove, Width-3, Height-3
          Click, down
          Send {Shift Up}
          Send {Ctrl Up}
          BlockInput, Off
          Return





          share|improve this answer

































            0














            The problem is that Sleep, 1 might not be enough time for the menu to appear on all applications.



            The most reliable way to do it would be avoiding the menu altogether but that's quite some work to do through WinGetPos, MouseGetPos, and WinMove.



            I guess you'll still be trying to use the menu, so my tip is to at least wait to be sure that the menu exists. You can do this getting the ProcessID of your hwnd, and wait so that first found window through that PID changes, that could be understood for us as a new window has appeared. In code means something like this:



            WinGet, WinPID, PID, ahk_id %hwnd%
            oldHwnd := WinExist("ahk_pid " WinPID)

            Send !{Space}

            newHwnd := oldHwnd
            while (newHwnd == oldHwnd)
            newHwnd := WinExist("ahk_pid " WinPID)


            But you'd need some better exit conditions in case that the menu didn't happen to appear (a timeout?) to not get stuck there.



            Still after that the Sleep, 1 might not be enough.






            share|improve this answer
























            • Hmmm I think you're right about the menu being too slow.

              – jerrysperry
              Jan 3 at 15:02














            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012216%2fhover-mouse-over-window-and-move-mouse-to-resize-window-using-autohotkey%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I was able to solve this reliably by moving the mouse to the top right of the window next the minimize button and leaving the mouse button down while using blockinput.



            Benefits:




            • This allows the the user to move the mouse freely to move the window.

            • It works for resizing as well.

            • being able to move windows if they're snapped fullscreen.


            TIP: script has to be run as administrator for blockinput to work...



            ;Move Window Mode
            ^+x::
            KeyWait Shift
            KeyWait Alt
            BlockInput, On
            MouseGetPos,,, hwnd
            WinActivate, ahk_id %hwnd%
            WinGetPos, , , Width, Height, A
            MouseMove, Width-186, 10
            Click, down
            Send {Shift Up}
            Send {Ctrl Up}
            BlockInput, Off
            Return

            ;Resize Window Mode
            ^+z::
            KeyWait Shift
            KeyWait Alt
            BlockInput, On
            MouseGetPos,,, hwnd
            WinActivate, ahk_id %hwnd%
            WinGetPos, , , Width, Height, A
            MouseMove, Width-3, Height-3
            Click, down
            Send {Shift Up}
            Send {Ctrl Up}
            BlockInput, Off
            Return





            share|improve this answer






























              1














              I was able to solve this reliably by moving the mouse to the top right of the window next the minimize button and leaving the mouse button down while using blockinput.



              Benefits:




              • This allows the the user to move the mouse freely to move the window.

              • It works for resizing as well.

              • being able to move windows if they're snapped fullscreen.


              TIP: script has to be run as administrator for blockinput to work...



              ;Move Window Mode
              ^+x::
              KeyWait Shift
              KeyWait Alt
              BlockInput, On
              MouseGetPos,,, hwnd
              WinActivate, ahk_id %hwnd%
              WinGetPos, , , Width, Height, A
              MouseMove, Width-186, 10
              Click, down
              Send {Shift Up}
              Send {Ctrl Up}
              BlockInput, Off
              Return

              ;Resize Window Mode
              ^+z::
              KeyWait Shift
              KeyWait Alt
              BlockInput, On
              MouseGetPos,,, hwnd
              WinActivate, ahk_id %hwnd%
              WinGetPos, , , Width, Height, A
              MouseMove, Width-3, Height-3
              Click, down
              Send {Shift Up}
              Send {Ctrl Up}
              BlockInput, Off
              Return





              share|improve this answer




























                1












                1








                1







                I was able to solve this reliably by moving the mouse to the top right of the window next the minimize button and leaving the mouse button down while using blockinput.



                Benefits:




                • This allows the the user to move the mouse freely to move the window.

                • It works for resizing as well.

                • being able to move windows if they're snapped fullscreen.


                TIP: script has to be run as administrator for blockinput to work...



                ;Move Window Mode
                ^+x::
                KeyWait Shift
                KeyWait Alt
                BlockInput, On
                MouseGetPos,,, hwnd
                WinActivate, ahk_id %hwnd%
                WinGetPos, , , Width, Height, A
                MouseMove, Width-186, 10
                Click, down
                Send {Shift Up}
                Send {Ctrl Up}
                BlockInput, Off
                Return

                ;Resize Window Mode
                ^+z::
                KeyWait Shift
                KeyWait Alt
                BlockInput, On
                MouseGetPos,,, hwnd
                WinActivate, ahk_id %hwnd%
                WinGetPos, , , Width, Height, A
                MouseMove, Width-3, Height-3
                Click, down
                Send {Shift Up}
                Send {Ctrl Up}
                BlockInput, Off
                Return





                share|improve this answer















                I was able to solve this reliably by moving the mouse to the top right of the window next the minimize button and leaving the mouse button down while using blockinput.



                Benefits:




                • This allows the the user to move the mouse freely to move the window.

                • It works for resizing as well.

                • being able to move windows if they're snapped fullscreen.


                TIP: script has to be run as administrator for blockinput to work...



                ;Move Window Mode
                ^+x::
                KeyWait Shift
                KeyWait Alt
                BlockInput, On
                MouseGetPos,,, hwnd
                WinActivate, ahk_id %hwnd%
                WinGetPos, , , Width, Height, A
                MouseMove, Width-186, 10
                Click, down
                Send {Shift Up}
                Send {Ctrl Up}
                BlockInput, Off
                Return

                ;Resize Window Mode
                ^+z::
                KeyWait Shift
                KeyWait Alt
                BlockInput, On
                MouseGetPos,,, hwnd
                WinActivate, ahk_id %hwnd%
                WinGetPos, , , Width, Height, A
                MouseMove, Width-3, Height-3
                Click, down
                Send {Shift Up}
                Send {Ctrl Up}
                BlockInput, Off
                Return






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 3 at 21:25

























                answered Jan 3 at 20:47









                jerrysperryjerrysperry

                164




                164

























                    0














                    The problem is that Sleep, 1 might not be enough time for the menu to appear on all applications.



                    The most reliable way to do it would be avoiding the menu altogether but that's quite some work to do through WinGetPos, MouseGetPos, and WinMove.



                    I guess you'll still be trying to use the menu, so my tip is to at least wait to be sure that the menu exists. You can do this getting the ProcessID of your hwnd, and wait so that first found window through that PID changes, that could be understood for us as a new window has appeared. In code means something like this:



                    WinGet, WinPID, PID, ahk_id %hwnd%
                    oldHwnd := WinExist("ahk_pid " WinPID)

                    Send !{Space}

                    newHwnd := oldHwnd
                    while (newHwnd == oldHwnd)
                    newHwnd := WinExist("ahk_pid " WinPID)


                    But you'd need some better exit conditions in case that the menu didn't happen to appear (a timeout?) to not get stuck there.



                    Still after that the Sleep, 1 might not be enough.






                    share|improve this answer
























                    • Hmmm I think you're right about the menu being too slow.

                      – jerrysperry
                      Jan 3 at 15:02


















                    0














                    The problem is that Sleep, 1 might not be enough time for the menu to appear on all applications.



                    The most reliable way to do it would be avoiding the menu altogether but that's quite some work to do through WinGetPos, MouseGetPos, and WinMove.



                    I guess you'll still be trying to use the menu, so my tip is to at least wait to be sure that the menu exists. You can do this getting the ProcessID of your hwnd, and wait so that first found window through that PID changes, that could be understood for us as a new window has appeared. In code means something like this:



                    WinGet, WinPID, PID, ahk_id %hwnd%
                    oldHwnd := WinExist("ahk_pid " WinPID)

                    Send !{Space}

                    newHwnd := oldHwnd
                    while (newHwnd == oldHwnd)
                    newHwnd := WinExist("ahk_pid " WinPID)


                    But you'd need some better exit conditions in case that the menu didn't happen to appear (a timeout?) to not get stuck there.



                    Still after that the Sleep, 1 might not be enough.






                    share|improve this answer
























                    • Hmmm I think you're right about the menu being too slow.

                      – jerrysperry
                      Jan 3 at 15:02
















                    0












                    0








                    0







                    The problem is that Sleep, 1 might not be enough time for the menu to appear on all applications.



                    The most reliable way to do it would be avoiding the menu altogether but that's quite some work to do through WinGetPos, MouseGetPos, and WinMove.



                    I guess you'll still be trying to use the menu, so my tip is to at least wait to be sure that the menu exists. You can do this getting the ProcessID of your hwnd, and wait so that first found window through that PID changes, that could be understood for us as a new window has appeared. In code means something like this:



                    WinGet, WinPID, PID, ahk_id %hwnd%
                    oldHwnd := WinExist("ahk_pid " WinPID)

                    Send !{Space}

                    newHwnd := oldHwnd
                    while (newHwnd == oldHwnd)
                    newHwnd := WinExist("ahk_pid " WinPID)


                    But you'd need some better exit conditions in case that the menu didn't happen to appear (a timeout?) to not get stuck there.



                    Still after that the Sleep, 1 might not be enough.






                    share|improve this answer













                    The problem is that Sleep, 1 might not be enough time for the menu to appear on all applications.



                    The most reliable way to do it would be avoiding the menu altogether but that's quite some work to do through WinGetPos, MouseGetPos, and WinMove.



                    I guess you'll still be trying to use the menu, so my tip is to at least wait to be sure that the menu exists. You can do this getting the ProcessID of your hwnd, and wait so that first found window through that PID changes, that could be understood for us as a new window has appeared. In code means something like this:



                    WinGet, WinPID, PID, ahk_id %hwnd%
                    oldHwnd := WinExist("ahk_pid " WinPID)

                    Send !{Space}

                    newHwnd := oldHwnd
                    while (newHwnd == oldHwnd)
                    newHwnd := WinExist("ahk_pid " WinPID)


                    But you'd need some better exit conditions in case that the menu didn't happen to appear (a timeout?) to not get stuck there.



                    Still after that the Sleep, 1 might not be enough.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 2 at 22:08









                    scsoscso

                    30624




                    30624













                    • Hmmm I think you're right about the menu being too slow.

                      – jerrysperry
                      Jan 3 at 15:02





















                    • Hmmm I think you're right about the menu being too slow.

                      – jerrysperry
                      Jan 3 at 15:02



















                    Hmmm I think you're right about the menu being too slow.

                    – jerrysperry
                    Jan 3 at 15:02







                    Hmmm I think you're right about the menu being too slow.

                    – jerrysperry
                    Jan 3 at 15:02




















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012216%2fhover-mouse-over-window-and-move-mouse-to-resize-window-using-autohotkey%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                    Npm cannot find a required file even through it is in the searched directory