How can a script simply mouseclick a window edge?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Coldblackice
Posts: 29
Joined: 13 Nov 2013, 14:39

How can a script simply mouseclick a window edge?

28 Jan 2016, 18:02

I've been using a KDE window resize script for a while. An issue with it, however, is that Windows 7 doesn't remember the new size of the window. Researching this, I discovered that this script is bypassing the way Windows tracks new size changes -- clicking and dragging the edge of a window. I find that, if I resize a window with my KDE script, as long as I click once on any window edge, Windows remembers the window size.

Unless someone has a better idea, I'm wondering if it's possible to trigger a click "programmatically" on a window edge bar -- by "programmatically", I mean without having to move the mouse cursor, like by triggering this function with a Windows API, or something.

Any thoughts/ideas?


EDIT:

Here's the code I'm currently using:

Code: Select all

;**************************
; *****RESIZING WINDOWS*****
; **************************

^#RButton::
; Get the initial mouse position and window id, and
; abort if the window is maximized.
MouseGetPos,KDE_X1,KDE_Y1,KDE_id
WinGet,KDE_Win,MinMax,ahk_id %KDE_id%
If KDE_Win
    return
; Get the initial window position and size.
WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
; Define the window region the mouse is currently in.
; The four regions are Up and Left, Up and Right, Down and Left, Down and Right.
If (KDE_X1 < KDE_WinX1 + KDE_WinW / 2)
   KDE_WinLeft := 1
Else
   KDE_WinLeft := -1
If (KDE_Y1 < KDE_WinY1 + KDE_WinH / 2)
   KDE_WinUp := 1
Else
   KDE_WinUp := -1
Loop
{
    GetKeyState,KDE_Button,RButton,P ; Break if button has been released.
    If KDE_Button = U
        break
    MouseGetPos,KDE_X2,KDE_Y2 ; Get the current mouse position.
    ; Get the current window position and size.
    WinGetPos,KDE_WinX1,KDE_WinY1,KDE_WinW,KDE_WinH,ahk_id %KDE_id%
    KDE_X2 -= KDE_X1 ; Obtain an offset from the initial mouse position.
    KDE_Y2 -= KDE_Y1
    ; Then, act according to the defined region.
    WinMove,ahk_id %KDE_id%,, KDE_WinX1 + (KDE_WinLeft+1)/2*KDE_X2  ; X of resized window
                            , KDE_WinY1 +   (KDE_WinUp+1)/2*KDE_Y2  ; Y of resized window
                            , KDE_WinW  -     KDE_WinLeft  *KDE_X2  ; W of resized window
                            , KDE_WinH  -       KDE_WinUp  *KDE_Y2  ; H of resized window
    KDE_X1 := (KDE_X2 + KDE_X1) ; Reset the initial position for the next iteration.
    KDE_Y1 := (KDE_Y2 + KDE_Y1)
}
return
Last edited by Coldblackice on 01 Feb 2016, 23:12, edited 1 time in total.
User avatar
lifeweaver
Posts: 144
Joined: 10 May 2014, 05:57
Location: OH
Contact:

Re: How can a script simply mouseclick a window edge?

29 Jan 2016, 11:07

Hi Coldblackice,

I would guess it's triggered by a windows message.
You might look at GetWindowPlacement and SetWindowPlacement.

Also see this post from the AutoHotkey forums:
Lexikos wrote:

Code: Select all

hwnd := WinExist("Untitled - Notepad")
WinGetPos, mX, mY

WinGetNormalPos(hwnd, x, y, w, h)
MsgBox Pos:`nx: %mX%`ny: %mY%`n`nNormalPos:`nx: %x%`ny: %y%`nw: %w%`nh: %h%



WinGetNormalPos(hwnd, ByRef x, ByRef y, ByRef w="", ByRef h="")
{
    VarSetCapacity(wp, 44), NumPut(44, wp)
    DllCall("GetWindowPlacement", "uint", hwnd, "uint", &wp)

    x := NumGet(wp, 28, "int")
    y := NumGet(wp, 32, "int")
    w := NumGet(wp, 36, "int") - x
    h := NumGet(wp, 40, "int") - y
}
Note: this code probably is for 32-bit, so it probably needs modified to work.
lexikos
Posts: 9604
Joined: 30 Sep 2013, 04:07
Contact:

Re: How can a script simply mouseclick a window edge?

29 Jan 2016, 18:51

I use this in WindowPad (the comments are from at least 3 years ago):

Code: Select all

    ; Explorer uses WM_EXITSIZEMOVE to detect when a user finishes moving a window
    ; in order to save the position for next time. May also be used by other apps.
    PostMessage, 0x232
In this case, the Last Found Window had been set to the window which was just moved.
User avatar
Coldblackice
Posts: 29
Joined: 13 Nov 2013, 14:39

Re: How can a script simply mouseclick a window edge?

01 Feb 2016, 23:28

lexikos wrote:I use this in WindowPad (the comments are from at least 3 years ago):

Code: Select all

    ; Explorer uses WM_EXITSIZEMOVE to detect when a user finishes moving a window
    ; in order to save the position for next time. May also be used by other apps.
    PostMessage, 0x232
In this case, the Last Found Window had been set to the window which was just moved.
Works beautifully! Thanks! Note, it only worked when I used a modified suggestion of yours found on another forum:

Code: Select all

PostMessage, 0x232,,,, A
The "A" text seems to be necessary, too, or else the size/position of a window won't save. Any idea why this is?
lexikos
Posts: 9604
Joined: 30 Sep 2013, 04:07
Contact:

Re: How can a script simply mouseclick a window edge?

02 Feb 2016, 00:17

"A" means the active window. The only case where you don't need to specify which window to send the message to is the one that I said:
I wrote:In this case, the Last Found Window had been set to the window which was just moved.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 120 guests