Hover cursor outside of GUI

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

Hover cursor outside of GUI

29 Apr 2018, 15:06

Hi I've made a script with a GUI that requires you to place your cursor inside of it. When you hover your cursor outside of the GUI, it sends a command depending on which side of the GUI you crossed the cursor over.

For example if you place the cursor in the middle of the GUI and then move the cursor over the right edge and outside the GUI, it sends a command. Now if you move the cursor outside of the GUI by crossing over the top edge, it sends a different command, and so on. Clicking down on the GUI and dragging will move the GUI around the screen.

My question: sometimes when you move the cursor outside of the GUI slowly, it misses the command, requiring you to do it again.

Is there a way to have it so that it will always detect the cursor moving outside of the GUI, regardless of how fast the cursor is moving?

Code: Select all

#NoEnv
#NoTrayIcon
SetBatchLines, -1
Coordmode, Mouse, Screen


Gui, +Resize -Caption +AlwaysOnTop -0x30000 -SysMenu  
Gui, Color, 996666
Gui, Show, w150 h150, PANEL
winmove, PANEL,, 200, 500

OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x200, "WM_MOUSEMOVE")
Return

WM_MOUSEMOVE() {
   wingetpos, winX1, winY1, W1, H1, PANEL
   MouseGetPos, X1, Y1
   Sleep, 1
   MouseGetPos, X2, Y2
   GUIHeight := winY1 + H1
   GUIWidth  := winX1 + W1
   
   GUIWidthRightEdge := winX1 + W1 
   GUIWidthRightEdge -= 25
   
   GUIHeightBottomEdge := winY1 + H1 
   GUIHeightBottomEdge -= 25
   
   winX1 += 25
   winY1 += 25
   
	  If (X2 > X1) and (X2 > GUIWidthRightEdge) and (Y2 > winY1) and (Y2 < GUIHeight) ;glide cursor from inside GUI to outside right edge
      {
	  tooltip, right
      X1 := X2
	  W1 := W2
      }

	  If (X2 < X1) and (X2 < winX1) and (Y2 > winY1) and (Y2 < GUIHeight) ;glide cursor from inside GUI to outside left edge
      {
	  tooltip, left
      X1 := X2
	  W1 := W2
      }
	  
	  If (Y2 > Y1) and (Y2 > GUIHeightBottomEdge) and (X2 > winX1) and (X2 < GUIWidth) ;glide cursor from inside GUI to outside bottom edge
      {
	  tooltip, bottom
      Y1 := Y2
	  Y1 := Y2
      }
	  
	  If (Y2 < Y1) and (Y2 < winY1) and (X2 > winX1) and (X2 < GUIWidth) ;glide cursor from inside GUI to outside top edge
      {
	  tooltip, top
      Y1 := Y2
	  Y1 := Y2
      }

}
return

WM_LBUTTONDOWN() {
PostMessage, 0xA1, 2,,, A 
return
}
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Hover cursor outside of GUI

30 Apr 2018, 08:42

I think you should be able to use OnMessage(0x2A3, "WM_MOUSELEAVE")

See my post here: https://autohotkey.com/boards/viewtopic ... 37#p149837

I use WM_MOUSELEAVE to hide images when the mouse leaves the GUI.
scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Re: Hover cursor outside of GUI

01 May 2018, 23:58

I've tried playing around with MouseLeave, but haven't had any luck with it.

I've shortened the script just to test it out, but when the cursor leaves the GUI, the tooltip doesn't show up:

Code: Select all

#NoEnv
#NoTrayIcon
SetBatchLines, -1
Coordmode, Mouse, Screen


Gui, +Resize -Caption +AlwaysOnTop -0x30000 -SysMenu  
Gui, Color, 996666
Gui, Show, w150 h150, PANEL
winmove, PANEL,, 200, 500

OnMessage(0x2A3, "WM_MOUSELEAVE")
Return

WM_MOUSELEAVE() {
 tooltip, cursor has left the gui
}
return
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Hover cursor outside of GUI

02 May 2018, 03:06

You might be interested in this topic: OnMessage(0x200, "OnMouseMove") :wave:.

Cheers.
scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Re: Hover cursor outside of GUI

04 May 2018, 23:47

Hi Helgef, may I ask a question?


In the script below, when the cursor leaves the GUI, the tooltip says something like "Mouse left gui @ 999749536"

What does 999749536 represent?
scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Re: Hover cursor outside of GUI

04 May 2018, 23:49

Hi Helgef, may I ask a question?


In the script below, when the cursor leaves the GUI, the tooltip says something like "Mouse left gui @ 999749536"

What does 999749536 represent?


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
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Hover cursor outside of GUI

05 May 2018, 13:13

Those numbers are from A_TickCount, I guess Helgef2017 liked the visual effect :beard: .

Cheers.
scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Re: Hover cursor outside of GUI

05 May 2018, 20:56

Do they represent coordinates?
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: Hover cursor outside of GUI

05 May 2018, 21:23

A_TickCount (<<<< this is clickable, btw) is a built-in AHK variable that gets some info from your computer: "It is the number of milliseconds since the computer was rebooted." (from the docs)
There a lot of built-in variables, you might have encountered some of them before: https://autohotkey.com/docs/Variables.htm#BuiltIn Many start with A_, some not.
scriptor2016
Posts: 854
Joined: 21 Dec 2015, 02:34

Re: Hover cursor outside of GUI

05 May 2018, 21:59

Ok, now I get it :)

I couldn't figure out what it was, I was looking for some kind of a pattern or something to determine what it meant but it always seemed random. Now I know it's milliseconds. Thanks :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, RandomBoy and 396 guests