Reputation: 933
I have a simple Autohotkey script that I want to use to determine if the mouse was clicked inside a window. I want the function to fail if the click was on the title bar or on the scroll bars of the window. My script looks like this:
LButton::
WinGetPos, X, Y, Width, Height, A
MouseGetPos, x,y
Rightmargin := Width - 50
Topmargin := Y+25
if (x < Rightmargin and y > Topmargin)
MsgBox You're Inside
return
The problem is when I run this, it freezes up my machine. All the left mouse clicks are captured and do not get through to the system and for some reason the test case always fails (I never see the MsgBox).
Can you tell me what I am doing wrong?
Upvotes: 0
Views: 709
Reputation: 10892
Variables, Labelnames and so on are case-insensitive in AutoHotkey. So, with WinGetPos, X, Y
and MouseGetPos, x,y
, you are allocating these two variables twice, overwriting the window's position coordinates. So, for example, you might want to rename x
to mouseX
and y
to mouseY
.
Since you obviously want your mouse coordinates being measured by the current window, you should also include coordmode, mouse, relative
before your hotkey assignments.
Finally, if you also want your Click to be send to the window, includ a tilde ~
before your Hotkey: ~LButton::
.
Upvotes: 2