my tooltip sometimes goes way of position but should not Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

my tooltip sometimes goes way of position but should not

21 Apr 2024, 03:05

hello ive been trying to find some math or whatever to ensure my tooltip is always somewhat centered at my first monitor

but that does not always happen
monitor 1 i have at 150% scaling and monitor 2 at 125% scaling (if that matters)

often in ahk my screen is being seen as much bigger than it actualy is because of it (like +/- 2300 wide but it really is 1920, not sure this matters tho for what i want) however i cant predict what it will see it as, i think if i just used something on monitor 2 it goes off because the focus is stil there (maybe just thinking)

so i have this code and i wonder is there a better way to do this to ensure its always on my first monitor's center

Code: Select all

Tooltip, Macro Launcher 2 Loaded , A_ScreenWidth/2-100 , A_ScreenHeight/2-50
SetTimer , RemoveToolTip, -2500
edit: i forgot to say that ofc i can put in hardcoded coordinates but in time i intent to share this with others so i need it to be right always no matter the setup
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: my tooltip sometimes goes way of position but should not

21 Apr 2024, 05:33

Hello,

What you can predict is which :arrow: CoordMode your script will use for its tooltips. You can also change the CoordMode if you wish.
X, Y: If blank or omitted, the tooltip will be shown near the mouse cursor. Otherwise, specify the X and Y position of the tooltip relative to the active window (use CoordMode, ToolTip to change to screen coordinates).
Source: ToolTip - Syntax & Usage | AutoHotkey v1
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

Re: my tooltip sometimes goes way of position but should not

21 Apr 2024, 08:06

mikeyww wrote:
21 Apr 2024, 05:33
Hello,

What you can predict is which :arrow: CoordMode your script will use for its tooltips. You can also change the CoordMode if you wish.
X, Y: If blank or omitted, the tooltip will be shown near the mouse cursor. Otherwise, specify the X and Y position of the tooltip relative to the active window (use CoordMode, ToolTip to change to screen coordinates).
Source: ToolTip - Syntax & Usage | AutoHotkey v1
ive tried that but its stil doing it, i think i am gonna make it adjustable from my global settings gui :) this is not a thing i want to spend to much time on. bigger fish to fry so to say

thnx mikeyww
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: my tooltip sometimes goes way of position but should not

21 Apr 2024, 08:36

Post your revision if you wish.

Code: Select all

#Requires AutoHotkey v1.1.33.11
#Persistent
centerTip("abc def ghi xxxxxxxxxxx`n`n`nxxxxxxxxxxxxxxxxx")

centerTip(str) {
 Static ttip := "ahk_class tooltips_class32"
      , x    := A_ScreenWidth  / 2 - 100
      , y    := A_ScreenHeight / 2 - 13
 CoordMode ToolTip
 ToolTip % str, x, y
 WinGetPos,,, w, h, % ttip
 WinMove % ttip,,,, (A_ScreenWidth - w) / 2, (A_ScreenHeight - h) / 2
}
Last edited by mikeyww on 21 Apr 2024, 08:50, edited 1 time in total.
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

Re: my tooltip sometimes goes way of position but should not

21 Apr 2024, 08:49

mikeyww wrote:
21 Apr 2024, 08:36
Post your revision if you wish.

Code: Select all

#Requires AutoHotkey v1.1.33.11
#Persistent
centerTip("abc def ghi xxxxxxxxxxxxxxxxxxxxxxxxxxxx")

centerTip(str) {
 Static ttip := "ahk_class tooltips_class32"
 CoordMode ToolTip
 ToolTip % str, A_ScreenWidth / 2 - 100, A_ScreenHeight / 2 - 25
 WinGetPos,,, w, h, % ttip
 WinMove % ttip,,,, (A_ScreenWidth - w) / 2, (A_ScreenHeight - h) / 2
}
i was just gonna add fixed values from ini to it but this looks interesting i never realized you could use winmove on tooltips thnx ill play around with this tonight when i have more time and let ya know :)
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: my tooltip sometimes goes way of position but should not  Topic is solved

21 Apr 2024, 08:51

Bug fix here.

Center a ToolTip

Code: Select all

#Requires AutoHotkey v1.1.33.11
#Persistent
centerTip("abc def ghi xxxxxxxxxxx`n`n`nxxxxxxxxxxxxxxxxx")

centerTip(str) {
 Static ttip := "ahk_class tooltips_class32"
      , x    := A_ScreenWidth  / 2 - 100
      , y    := A_ScreenHeight / 2 - 13
 CoordMode ToolTip
 ToolTip % str, x, y
 WinGetPos,,, w, h, % ttip
 WinMove % ttip,, (A_ScreenWidth - w) / 2, (A_ScreenHeight - h) / 2
}
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

Re: my tooltip sometimes goes way of position but should not

21 Apr 2024, 09:34

mikeyww wrote:
21 Apr 2024, 08:51
Bug fix here.

Center a ToolTip

Code: Select all

#Requires AutoHotkey v1.1.33.11
#Persistent
centerTip("abc def ghi xxxxxxxxxxx`n`n`nxxxxxxxxxxxxxxxxx")

centerTip(str) {
 Static ttip := "ahk_class tooltips_class32"
      , x    := A_ScreenWidth  / 2 - 100
      , y    := A_ScreenHeight / 2 - 13
 CoordMode ToolTip
 ToolTip % str, x, y
 WinGetPos,,, w, h, % ttip
 WinMove % ttip,, (A_ScreenWidth - w) / 2, (A_ScreenHeight - h) / 2
}
mikey ahk wizard :) thnx
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

Re: my tooltip sometimes goes way of position but should not

21 Apr 2024, 13:52

@mikeyww works like a charm i was not able to break this from working right :) thank you mikeyww
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

Re: my tooltip sometimes goes way of position but should not

21 Apr 2024, 15:02

this is how i ended up using it for those interested (since my tooltip is in the startup section and because i already have my removetooltip label in use for other tooltips i can do it like this however if thats not the case use mikeyww''s function below)

Code: Select all

centerTip("Macro Launcher 2 Loaded")
centerTip(str) {
 Static ttip := "ahk_class tooltips_class32"
      , x    := A_ScreenWidth  / 2 - 100
      , y    := A_ScreenHeight / 2 - 13
 CoordMode ToolTip
 ToolTip % str, x, y
 WinGetPos,,, w, h, % ttip
 WinMove % ttip,, (A_ScreenWidth - w) / 2, (A_ScreenHeight - h) / 2
 SetTimer , RemoveToolTip, -2500
}
elsewhere in my script

Code: Select all

RemoveToolTip:
ToolTip
return
Last edited by peter_ahk on 21 Apr 2024, 17:21, edited 2 times in total.
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: my tooltip sometimes goes way of position but should not

21 Apr 2024, 15:34

In case of interest: combining the two actions into a single function.

Code: Select all

centerTip(str) {
 Static ttip := "ahk_class tooltips_class32"
      , cx   := A_ScreenWidth / 2, cy := A_ScreenHeight / 2
      , x    := cx - 100, y := cy - 13
 CoordMode ToolTip
 ToolTip % str, x, y
 WinGetPos,,, w, h, % ttip
 WinMove % ttip,, cx - w / 2, cy - h / 2
 SetTimer RemoveToolTip, -2500
 Return
 RemoveToolTip:
 ToolTip
 Return
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 85 guests