Placing Text Notifications Above the Start Button

Post your working scripts, libraries and tools.
imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Placing Text Notifications Above the Start Button

Post by imkira3 » 29 Jan 2023, 20:43

I found a few cool tricks while building my new script, I'll post one of them here for you now. I always liked my notifications to be tucked away in the corner, so while I was designing my script I made a way to tuck away a tooltip notification in the corner. Normally tooltips follow the mouse or operate within the window you have focus of, so this was a bit harder than you might think. The code is light and easy to edit, I imagine this can be useful to add descriptive text to most any script with ease, and the tooltip messages will match your current theme. The Y co-ordinate may change by a few pixels depending on themes, windows version, etc. Right now it's configured for the Windows Classic theme but it's easy to adjust. Just make sure to use the proper variable for the Y co-ordinates, the number at the end of the variable must match the number of lines in play. Right now it's configured to use buttons 1-9 with example text. Here is the code:

Code: Select all

;;;;;;;;;;;;;;
;            ;
;  Settings  ;
;            ;
;;;;;;;;;;;;;;

A_1 := "LINE 1"
A_2 := "LINE 1`rLINE 2"
A_3 := "LINE 1`rLINE 2`rLINE 3"
A_4 := "LINE 1`rLINE 2`rLINE 3`rLINE 4"
A_5 := "LINE 1`rLINE 2`rLINE 3`rLINE 4`rLINE 5"
A_6 := "LINE 1`rLINE 2`rLINE 3`rLINE 4`rLINE 5`rLINE 6"
A_7 := "LINE 1`rLINE 2`rLINE 3`rLINE 4`rLINE 5`rLINE 6`rLINE 7"
A_8 := "LINE 1`rLINE 2`rLINE 3`rLINE 4`rLINE 5`rLINE 6`rLINE 7`rLINE 8"
A_9 := "LINE 1`rLINE 2`rLINE 3`rLINE 4`rLINE 5`rLINE 6`rLINE 7`rLINE 8`rLINE 9"
A_TooltipDelay := "10000"
A_TooltipX := "0"
A_TooltipY1 := "-20"
A_TooltipY2 := "-33"
A_TooltipY3 := "-46"
A_TooltipY4 := "-59"
A_TooltipY5 := "-72"
A_TooltipY6 := "-85"
A_TooltipY7 := "-98"
A_TooltipY8 := "-111"
A_TooltipY9 := "-124"

;;;;;;;;;;;;;;;;;;;;;
;                   ;
;  Basic Functions  ;
;                   ;
;;;;;;;;;;;;;;;;;;;;;

1::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_1, A_TooltipX, A_TooltipY1
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}
2::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_2, A_TooltipX, A_TooltipY2
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}
3::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_3, A_TooltipX, A_TooltipY3
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}
4::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_4, A_TooltipX, A_TooltipY4
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}
5::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_5, A_TooltipX, A_TooltipY5
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}
6::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_6, A_TooltipX, A_TooltipY6
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}
7::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_7, A_TooltipX, A_TooltipY7
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}
8::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_8, A_TooltipX, A_TooltipY8
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}
9::{
A_OGWindow := WinActive("A")
WinActivate "ahk_class" "Shell_TrayWnd"
ToolTip A_9, A_TooltipX, A_TooltipY9
SetTimer () => ToolTip(), -A_TooltipDelay
WinActivate A_OGWindow
}

User avatar
boiler
Posts: 16955
Joined: 21 Dec 2014, 02:44

Re: Placing Text Notifications Above the Start Button

Post by boiler » 29 Jan 2023, 23:57

imkira3 wrote: Normally tooltips follow the mouse or operate within the window you have focus of, so this was a bit harder than you might think.
Not if you set:

Code: Select all

CoordMode "ToolTip", "Screen"
Then you can place them exactly where you want in screen coordinates.

imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Re: Placing Text Notifications Above the Start Button

Post by imkira3 » 30 Jan 2023, 00:07

boiler wrote:
29 Jan 2023, 23:57
imkira3 wrote: Normally tooltips follow the mouse or operate within the window you have focus of, so this was a bit harder than you might think.
Not if you set:

Code: Select all

CoordMode "ToolTip", "Screen"
Then you can place them exactly where you want in screen coordinates.
That's true, but this way sets 0, 0 to the top left pixel of your taskbar, rather than the top left corner of the screen. It's better suited for placing notifications in the bottom-left corner, since different resolutions will affect where things go ofc. You see it's actually switching to the taskbar for a fraction of a second, but it switches back so fast you barely notice.

User avatar
boiler
Posts: 16955
Joined: 21 Dec 2014, 02:44

Re: Placing Text Notifications Above the Start Button

Post by boiler » 30 Jan 2023, 00:12

imkira3 wrote: That's true, but this way sets 0, 0 to the top left pixel of your taskbar, rather than the top left corner of the screen.
Edit: I see what you're saying. So it's changing the 0, 0 point.

imkira3
Posts: 84
Joined: 10 Jan 2023, 13:57
Contact:

Re: Placing Text Notifications Above the Start Button

Post by imkira3 » 30 Jan 2023, 00:27

boiler wrote:
30 Jan 2023, 00:12
imkira3 wrote: That's true, but this way sets 0, 0 to the top left pixel of your taskbar, rather than the top left corner of the screen.
I don't know what you mean by that. Setting the CoordMode to Screen makes 0, 0 at the top-left corner of your screen. What does this script do other than put the ToolTip at the top-left corner or the screen (and put it there immediately, not switching from anywhere for a fraction of a second)?

Code: Select all

#Requires AutoHotkey v2.0
CoordMode "ToolTip", "Screen"
ToolTip "Hello, world", 0, 0
return

Esc::ExitApp
Ah, you misunderstood, I want the bottom-left not the top-left, and just above the Start Button. My script creates a variable with data that can be used to identify what window you currently have focus of:

Code: Select all

A_OGWindow := WinActive("A")
Then it switches to the taskbar:

Code: Select all

WinActivate "ahk_class" "Shell_TrayWnd"
By default tooltip operates within the window you currently have focus of, making 0, 0 the top-left corner of the taskbar when you have focus of the taskbar, so -20 Y will move the text 20 pixels above the new 0, 0 which is the correct distance for a single line of text. Add -13 pixels for each additional line, I control it all with variables based on how many lines are in a tooltip. Simple, right? Now we run the tooltip using the variables we configured in the settings section:

Code: Select all

ToolTip A_1, A_TooltipX, A_TooltipY1
And we set the timer for the tooltip:

Code: Select all

SetTimer () => ToolTip(), -A_TooltipDelay
And finally we switch back to the original window:

Code: Select all

WinActivate A_OGWindow
It all happens in a fraction of a second. As I said you can do the same things with co-ordinates, but a change in resolution would throw co-ordinate mode off a lot more than if we set 0, 0 to the top-left of the taskbar first. At most it would be off by a few pixels.

Post Reply

Return to “Scripts and Functions (v2)”