OnMessage(0x200, "OnMouseMove")

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptor2016
Posts: 862
Joined: 21 Dec 2015, 02:34

OnMessage(0x200, "OnMouseMove")

23 Jul 2017, 02:29

One more question here tonight: OnMessage(0x200, "OnMouseMove"), from what I can see, monitors the GUI to see if the cursor is ontop of it *constantly*. So while the cursor is ontop, it continues to see that it is indeed ontop (kind of like a loop, until the cursor leaves)

I was looking to see if there's an OnMessage to monitor the GUI to see when the cursor enters the GUI, but only upon entry and then terminate the monitoring?

So in other words, when the cursor eventually enters the GUI, it should recognize the cursor's entrance, and then stop monitoring.

Hope this makes sense. I checked this page for all possible messages, and even tried a few, but none worked:

https://www.autohotkey.com/docs/misc/Se ... geList.htm
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: OnMessage(0x200, "OnMouseMove")

23 Jul 2017, 04:07

Hello, there is a message called WM_MOUSELEAVE. Edit: fixed incorrect struct size. I didn't get it to work on 64 bit though :wave:

Code: Select all

OnMessage(0x200, "OnMouseMove")

gui, +hwndguiId

; This doesn't work on 64 bit
/*
typedef struct tagTRACKMOUSEEVENT {
  DWORD cbSize;
  DWORD dwFlags;
  HWND  hwndTrack;
  DWORD dwHoverTime;
} TRACKMOUSEEVENT, *LPTRACKMOUSEEVENT;
*/

WM_MOUSELEAVE:=0x2A3
cbSize:=A_PtrSize=4?16:24
TME_LEAVE:=0x00000002
dwFlags:=TME_LEAVE


VarSetCapacity(TRACKMOUSEEVENT, cbSize,0)
NumPut(cbSize, TRACKMOUSEEVENT, 0, "Uint")
NumPut(dwFlags, TRACKMOUSEEVENT, 4, "Uint")
NumPut(guiId, TRACKMOUSEEVENT, 8, "Ptr")
; NumPut(0, TRACKMOUSEEVENT, 8+A_PtrSize, "Uint") ; Not needed

if !DllCall("User32.dll\TrackMouseEvent", "Ptr", &TRACKMOUSEEVENT)
	Msgbox fail
else
	OnMessage(WM_MOUSELEAVE, "WM_MOUSELEAVE")

gui, show, w200 h200

OnMouseMove(){
	global TRACKMOUSEEVENT
	OnMessage(0x200, "OnMouseMove", 0)
	DllCall("User32.dll\TrackMouseEvent", "Ptr", &TRACKMOUSEEVENT)
	ToolTip % "Mouse entered gui @ " A_TickCount,0,0
}

WM_MOUSELEAVE(){
	ToolTip, % "Mouse left gui @ " A_TickCount,0,0
	OnMessage(0x200, "OnMouseMove")
}
esc::
guiclose:
	exitapp
Last edited by Helgef on 23 Jul 2017, 06:58, edited 2 times in total.
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: OnMessage(0x200, "OnMouseMove")

23 Jul 2017, 05:25

Helgef wrote:Hello, there is a message called WM_MOUSELEAVE. I didn't get it to work on 64 bit though :think:
4 + 4 + 8 + 4 ended up being 24.

Code: Select all

cbSize := A_PtrSize == 8 ? 24 : 16
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: OnMessage(0x200, "OnMouseMove")

23 Jul 2017, 06:52

Indeed, sizeof(TRACKMOUSEEVENT); is 24 on 64 bit. Ty, I'll edit the code.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 233 guests