gLabel on Mouse Over Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
That Kid
Posts: 10
Joined: 15 Nov 2021, 17:40

gLabel on Mouse Over

03 Feb 2022, 19:26

Hello, i cant find anything online about this so im not sure if this is possible, but is there a way to trigger a glabel when the mouse goes over a visible GUI?
User avatar
mikeyww
Posts: 27150
Joined: 09 Sep 2014, 18:38

Re: gLabel on Mouse Over  Topic is solved

03 Feb 2022, 19:54

Code: Select all

Global hWnd
Gui, +HwndhWnd
Gui, Add, Text, w250 h50, GUI
Gui, Show
OnMessage(0x0200, "WM_MOUSEMOVE")

WM_MOUSEMOVE(wParam, lParam) {
 Static in
 If in
  Return
 ToolTip, In!
 in := True
 SoundBeep, 1500
 SetTimer, Check, 200
 Return
 Check:
 CoordMode, Mouse
 WinGetPos, x1, y1, width, height, ahk_id %hWnd%
 x2 := x1 + width, y2 := y1 + height
 MouseGetPos, x, y
 If x between %x1% and %x2%
  If y between %y1% and %y2%
   Return
 SetTimer,, Off
 ToolTip, Out!
 SoundBeep, 1000
 in := False
 Return
}
That Kid
Posts: 10
Joined: 15 Nov 2021, 17:40

Re: gLabel on Mouse Over

03 Feb 2022, 20:00

thank you works well when implemented with me other script
User avatar
mikeyww
Posts: 27150
Joined: 09 Sep 2014, 18:38

Re: gLabel on Mouse Over

03 Feb 2022, 20:23

Possibly an improvement:

Code: Select all

Global hWnd
Gui, +HwndhWnd
Gui, Add, Text, w250 h50, GUI
Gui, Show
hoverTrigger()

overGUI(wParam, lParam) {
 hoverTrigger(False)
 ToolTip, In!
 SoundBeep, 1500
 SetTimer, Check, 200
 Return
 Check:
 CoordMode, Mouse
 WinGetPos, x1, y1, width, height, ahk_id %hWnd%
 x2 := x1 + width, y2 := y1 + height
 MouseGetPos, x, y
 If x between %x1% and %x2%
  If y between %y1% and %y2%
   Return
 SetTimer,, Off
 hoverTrigger()
 ToolTip, Out!
 SoundBeep, 1000
 Return
}

hoverTrigger(maxThreads := 1) {
 OnMessage(WM_MOUSEMOVE   := 0x0200, "overGUI", maxThreads) ; Client area
 OnMessage(WM_NCMOUSEMOVE := 0x00A0, "overGUI", maxThreads) ; Non-client area
}
scriptor2016
Posts: 864
Joined: 21 Dec 2015, 02:34

Re: gLabel on Mouse Over

04 Feb 2022, 01:22

mikeyww wrote:
03 Feb 2022, 20:23
Possibly an improvement:

Code: Select all

Global hWnd
Gui, +HwndhWnd
Gui, Add, Text, w250 h50, GUI
Gui, Show
hoverTrigger()

overGUI(wParam, lParam) {
 hoverTrigger(False)
 ToolTip, In!
 SoundBeep, 1500
 SetTimer, Check, 200
 Return
 Check:
 CoordMode, Mouse
 WinGetPos, x1, y1, width, height, ahk_id %hWnd%
 x2 := x1 + width, y2 := y1 + height
 MouseGetPos, x, y
 If x between %x1% and %x2%
  If y between %y1% and %y2%
   Return
 SetTimer,, Off
 hoverTrigger()
 ToolTip, Out!
 SoundBeep, 1000
 Return
}

hoverTrigger(maxThreads := 1) {
 OnMessage(WM_MOUSEMOVE   := 0x0200, "overGUI", maxThreads) ; Client area
 OnMessage(WM_NCMOUSEMOVE := 0x00A0, "overGUI", maxThreads) ; Non-client area
}
This is excellent! One question:

if we hover the cursor ontop of the "In!" and "Out!" tooltips, then the beeps also happen. Is there a way to prevent that from happening?
User avatar
mikeyww
Posts: 27150
Joined: 09 Sep 2014, 18:38

Re: gLabel on Mouse Over

04 Feb 2022, 06:04

That's an interesting point. Add as the first lines of overGUI:

Code: Select all

If !A_Gui
  Return
You then have the following.

Code: Select all

Global hWnd
Gui, +HwndhWnd
Gui, Add, Text, w250 h50, GUI
Gui, Show
hoverTrigger()

overGUI(wParam, lParam) {
 If !A_Gui
  Return
 hoverTrigger(False)
 ToolTip, In!
 SoundBeep, 1500
 SetTimer, Check, 200
 Return
 Check:
 CoordMode, Mouse
 WinGetPos, x1, y1, width, height, ahk_id %hWnd%
 x2 := x1 + width, y2 := y1 + height
 MouseGetPos, x, y
 If x between %x1% and %x2%
  If y between %y1% and %y2%
   Return
 SetTimer,, Off
 hoverTrigger()
 ToolTip, Out!
 SoundBeep, 1000
 Return
}

hoverTrigger(maxThreads := 1) {
 OnMessage(WM_MOUSEMOVE   := 0x0200, "overGUI", maxThreads) ; Client area
 OnMessage(WM_NCMOUSEMOVE := 0x00A0, "overGUI", maxThreads) ; Non-client area
}
It's been done many times earlier, using similar approaches.

viewtopic.php?p=431609#p431609
viewtopic.php?p=391784#p391784

Here it is using the window class.

Code: Select all

Gui, Add, Text, w250 h50, GUI
Gui, Show
hoverTrigger()                    ; Call overScript() if mouse goes "over the script"

overScript(wParam, lParam) {
 If !A_Gui                        ; Mouse is not over the GUI itself
  Return
 hoverTrigger(False)              ; Mouse is over GUI; stop calling this function
 ToolTip, In!
 SoundBeep, 1500
 SetTimer, Check, 200             ; Start check to see when mouse leaves the GUI
 Return
 Check:
 MouseGetPos,,, uid
 WinGetClass, class, ahk_id %uid% ; Window class under the mouse
 If (class = "AutoHotkeyGUI")     ; Mouse is over the GUI
  Return
 SetTimer,, Off                   ; Mouse is not over GUI; stop monitoring
 hoverTrigger()                   ; Reactivate the GUI hover trigger
 ToolTip, Out!
 SoundBeep, 1000
 Return
}

hoverTrigger(maxThreads := 1) {
 OnMessage(WM_MOUSEMOVE   := 0x0200, "overScript", maxThreads) ; Client area
 OnMessage(WM_NCMOUSEMOVE := 0x00A0, "overScript", maxThreads) ; Non-client area
}
scriptor2016
Posts: 864
Joined: 21 Dec 2015, 02:34

Re: gLabel on Mouse Over

05 Feb 2022, 02:10

This is really nice. It reminds me of another script I have tucked away that will scroll a Google Chrome window when the cursor is inside of the GUI:

Code: Select all

#NoEnv
#SingleInstance Force

Critical

OnMessage(0x200, "onMouseMove")
Gui, +AlwaysOnTop
Gui, Show, w225 h75
Return

GuiClose:
ExitApp
      
onMouseMove(wParam, lParam, msg, hwnd) {
   static
    x := lParam & 0xFFFF
    y := lParam >> 16
    if (x!=x2 and y!=y2) 
        {
        winactivate, ahk_exe chrome.exe
        sendinput {down 4}  
        x2 := x , y2 := y
        }
    return
}

...but the only problem with this one is that while the cursor must be inside the GUI for the scrolling to work, it must also be moving at all times. If the cursor stops moving, then the scrolling stops.
scriptor2016
Posts: 864
Joined: 21 Dec 2015, 02:34

Re: gLabel on Mouse Over

05 Feb 2022, 02:38

This script will scroll a Google Chrome window when the cursor is ontop of the GUI but the difference is that it uses a timer. Still works nicely though. Perhaps someone might have a use for it.

Code: Select all

Gui 1: +HwndIdTest +AlwaysOnTop  +ToolWindow -dpiScale  
Gui 1: Show, x200 y200 w300 h300, TEST
SetTimer, onout, 25
Return

onout:
MouseGetPos mx, my, IdWindow
WinGetTitle, WinT, ahk_id %IdWindow%
If (IdWindow = IdTest)
{
;The cursor is hovering over the GUI
winactivate, ahk_exe chrome.exe
sendinput {down}  
}

Else If (IdWindow <> IdTest)
{
;The cursor is not hovering over the GUI
Return 
}
Return
scriptor2016
Posts: 864
Joined: 21 Dec 2015, 02:34

Re: gLabel on Mouse Over

05 Feb 2022, 14:09

I'm really liking this one. I just have one more question if I may: is there a way to hover on top of/grab+drag the title bar without the functions triggering? So in other words the cursor would need to be inside the gui for everything to work but when the cursor is ontop of the title bar nothing would happen (except for the regular behavior of dragging the gui):

Code: Select all

Gui, Add, Text, w250 h50, GUI
Gui, Show
hoverTrigger()                    ; Call overScript() if mouse goes "over the script"

overScript(wParam, lParam) {
 If !A_Gui                        ; Mouse is not over the GUI itself
  Return
 hoverTrigger(False)              ; Mouse is over GUI; stop calling this function
 ToolTip, In!
 SoundBeep, 1500
 SetTimer, Check, 200             ; Start check to see when mouse leaves the GUI
 Return
 Check:
 MouseGetPos,,, uid
 WinGetClass, class, ahk_id %uid% ; Window class under the mouse
 If (class = "AutoHotkeyGUI")     ; Mouse is over the GUI
  Return
 SetTimer,, Off                   ; Mouse is not over GUI; stop monitoring
 hoverTrigger()                   ; Reactivate the GUI hover trigger
 ToolTip, Out!
 SoundBeep, 1000
 Return
}

hoverTrigger(maxThreads := 1) {
 OnMessage(WM_MOUSEMOVE   := 0x0200, "overScript", maxThreads) ; Client area
 OnMessage(WM_NCMOUSEMOVE := 0x00A0, "overScript", maxThreads) ; Non-client area
}
User avatar
mikeyww
Posts: 27150
Joined: 09 Sep 2014, 18:38

Re: gLabel on Mouse Over

05 Feb 2022, 14:22

You can remove the non-client OnMessage.
scriptor2016
Posts: 864
Joined: 21 Dec 2015, 02:34

Re: gLabel on Mouse Over

05 Feb 2022, 14:52

ok, it works. this is going to be super useful, thanks for this :)

Return to “Ask for Help (v1)”

Who is online

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