Please help me to improve my script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
emvaized
Posts: 3
Joined: 11 Apr 2023, 12:29

Please help me to improve my script

11 Apr 2023, 12:38

I created a script which proccesses mouse actions over each window's titlebar. When right click is detected, it minimizes the window, middle click closes it, scroll up maximizes window and scroll down restores it's size.
But titlebar detection is not perfect. For example, sometimes it fails to detect title bar (Windows 11 file explorer window), and sometimes false-detects titlebar in any point of window's background (PowerToys settings window). How could it be improved?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#If MouseIsOverTitlebar()
RButton::WinMinimize
MButton::WinClose
WheelUp::WinMaximize
WheelDown::WinRestore

MouseIsOverTitlebar() {
    static WM_NCHITTEST := 0x84, HTCAPTION := 2
    CoordMode Mouse, Screen
    MouseGetPos x, y, w
    if WinExist("ahk_class Shell_TrayWnd ahk_id " w)  ; Exclude taskbar.
        return false
    SendMessage WM_NCHITTEST,, x | (y << 16),, ahk_id %w%
    WinExist("ahk_id " w)  ; Set Last Found Window for convenience.
    return ErrorLevel = HTCAPTION
}
[Mod edit: Moved topic to AHK v1 help, based on posted code.]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], tomaxtoro, Yahoo [Bot] and 148 guests