How to detect that mouse cursor leaves script's gui?

Get help with using AutoHotkey and its commands and hotkeys
Zvonko
Posts: 200
Joined: 19 Jun 2015, 11:52

How to detect that mouse cursor leaves script's gui?

14 Aug 2016, 07:15

What would be the simplest way to detect that the mouse cursor is moved outside the script's gui (without calculating coordinates etc.)?

Edited: I forgot to mention that in my script I already use OnMouseMove for other purpose, so I prefer a solution which works inside OnMouseMove.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by Zvonko on 14 Aug 2016, 10:58, edited 1 time in total.
For me as a newbie it is frustrating to fail due to "little" problems in projects in which the entire concept and even complex functions are working perfectly...
Gicu
Posts: 111
Joined: 19 Aug 2014, 08:19
Location: Italy

Re: How to detect that mouse cursor leaves script's gui?

14 Aug 2016, 09:44

with a timer seems to work

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Zvonko
Posts: 200
Joined: 19 Jun 2015, 11:52

Re: How to detect that mouse cursor leaves script's gui?

14 Aug 2016, 10:57

Thank you very much, Gicu.
I forgot to mention that in my script I already use OnMouseMove for other purpose, so I prefer a solution which works inside OnMouseMove.
For me as a newbie it is frustrating to fail due to "little" problems in projects in which the entire concept and even complex functions are working perfectly...
punchin
Posts: 394
Joined: 17 Jan 2014, 17:54

Re: How to detect that mouse cursor leaves script's gui?

14 Aug 2016, 11:13

You're already getting the mouse position, so just add in to OnMouseMove the calculation to test of its outside the gui. There is no simpler way than that that I know of. That really simple, especially if you use the built in variables A_GuiX, A_GuiY, A_GuiWidth, and A_GuiHeight.
just me
Posts: 5460
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to detect that mouse cursor leaves script's gui?

14 Aug 2016, 11:38

MSDN wrote:Posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse.

Source
In other words, if your Gui didn't capture the mouse and the cursor is outside your Gui you won't receive WM_MOUSEMOVE messages.
punchin
Posts: 394
Joined: 17 Jan 2014, 17:54

Re: How to detect that mouse cursor leaves script's gui?

14 Aug 2016, 11:53

If OnMouse move is not being called by the gui at times, you will need to set a timer to fire it manually.
Last edited by punchin on 16 Aug 2016, 12:44, edited 1 time in total.
User avatar
noname
Posts: 507
Joined: 19 Nov 2013, 09:15

Re: How to detect that mouse cursor leaves script's gui?

14 Aug 2016, 13:12

You can use the parameters " OnMouseLeave " message to detect it.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Zvonko
Posts: 200
Joined: 19 Jun 2015, 11:52

Re: How to detect that mouse cursor leaves script's gui?

16 Aug 2016, 08:43

Thank you very much, Gicu, punchin, just me, noname!

Conclusion:
There really seems to be no simple AHK method (usable inside OnMouseMove) to detect that the mouse cursor leaves script's window! That's amazing, isn't it?


So I was forced to give up the OnMouseMove method and to use a timer...
For me as a newbie it is frustrating to fail due to "little" problems in projects in which the entire concept and even complex functions are working perfectly...
bbscrip
Posts: 1
Joined: 18 Sep 2017, 06:46

Re: How to detect that mouse cursor leaves script's gui?

20 Jun 2018, 12:23

This topic is a few years ago, but I did not find solution simple enough on same subject. I edited above example with small loop to track title and check for a change.


Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Works fine for me.

Return to “Ask For Help”

Who is online

Users browsing this forum: AlphaBravo, Rishu0182, sn0365 and 96 guests