I'm trying to display a list of hotkeys in a tooltip.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

I'm trying to display a list of hotkeys in a tooltip.

Post by LAPIII » 02 Feb 2023, 13:46

I put the hotkeys in a variable, but I need help:

Code: Select all

#SingleInstance Force
#NoTrayIcon
CoordMode, Mouse, Screen

Hotkeys := [X = Close, O = Open]

ToolTip, %Hotkeys%, 872, 469
SetTimer, RemoveToolTip, -5000
return

RemoveToolTip:
ToolTip
return

I would also like the tooltip to launch with the hotkey Ctrl + F1.

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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 02 Feb 2023, 14:14

LAPIII wrote: I put the hotkeys in a variable
No, you have not. By now, you really should be learning these fundamentals.

Code: Select all

#SingleInstance Force
#NoTrayIcon
CoordMode, ToolTip, Screen

Hotkeys := ["X = Close", "O = Open"]
for Each, Hotkey in Hotkeys
	HotkeyList .= Hotkey "`n"
return

^F1::
	ToolTip, %HotkeyList%, 872, 469
	SetTimer, RemoveToolTip, -5000
return

RemoveToolTip:
	ToolTip
return

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by LAPIII » 18 Apr 2023, 17:23

Code: Select all

#SingleInstance Force
#NoTrayIcon
CoordMode("ToolTip", "Screen")

Hotkeys := ["X = Close", "O = Open"]
for Each, Hotkey in Hotkeys
	HotkeyList .= Hotkey "`n"
return

^F1::{
ToolTip(HotkeyList, 872, 469)


	SetTimer(RemoveToolTip,-5000)
}

RemoveToolTip:
	ToolTip
	
I got:

Hotkeys_tooltip.ahk 18_04_23 06⦂22⦂49⦂191 PM.jpg
Hotkeys_tooltip.ahk 18_04_23 06⦂22⦂49⦂191 PM.jpg (33.12 KiB) Viewed 568 times

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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 18 Apr 2023, 17:53

As the error message shows, v2 doesn't let you use the built-in function name Hotkey as your variable. So just change it to something else. You also have to make RemoveToolTip a function, because there are no labeled subroutines in v2.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
#NoTrayIcon
CoordMode("ToolTip", "Screen")

Hotkeys := ["X = Close", "O = Open"]
for Each, HK in Hotkeys
	HotkeyList .= HK "`n"
return

^F1::{
	ToolTip(HotkeyList, 872, 469)
	SetTimer(RemoveToolTip,-5000)
}

RemoveToolTip() {
	ToolTip
}

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by LAPIII » 18 Apr 2023, 18:25

Thank you, I tried to implement a toggle and an error says that the variable online 12 has not been assigned value:

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
#NoTrayIcon
CoordMode("ToolTip", "Screen")

Hotkeys := ["X = Close", "O = Open"]
for Each, HK in Hotkeys
	HotkeyList .= HK "`n"
return

^F1::{
 If (Toggle = False) {
Toggle := True
ToolTip(HotkeyList, 872, 469)
 } Else If (Toggle = True) {

      Toggle := False

      ToolTip()

   }
}

esc::{
RemoveToolTip:
	ToolTip()
}

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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 18 Apr 2023, 21:00

You just need to give it an initial value. Insert this line at line 5:

Code: Select all

Toggle := False

By the way, you don’t need Else If…. It can just be Else because there is no reason to check if it’s True when the only other alternative relative to the first If is that it is True.

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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 18 Apr 2023, 21:11

Sorry, what I said above is not correct because it’s in a function. You can initialize it as the first line inside the function like this:

Code: Select all

static Toggle := False

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by LAPIII » 18 Apr 2023, 21:14

It ssays that is an unexpected declaration.
Last edited by LAPIII on 18 Apr 2023, 21:24, edited 1 time in total.

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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 18 Apr 2023, 21:19

You must not have done what I said. Where did you put that line?


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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 18 Apr 2023, 21:25

Read what I said again about where to put the static declaration.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by LAPIII » 18 Apr 2023, 21:45

I'm lost now. After errors said to get rid of the { in line 11, Else in line 14, } in lines 20 and 21, { in line 14, and the return preceding line 14, I got the variable for line number 14 has not been assigned a value. Here is the script:

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
#NoTrayIcon
CoordMode("ToolTip", "Screen")

Hotkeys := ["X = Close", "O = Open"]
for Each, HK in Hotkeys
	HotkeyList .= HK "`n"
return
^F1::{
 static Toggle := False {
Toggle := True
ToolTip(HotkeyList, 872, 469)
 } Else (Toggle = True)
{}

      Toggle := False

      ToolTip()}
   }
}

esc::{
RemoveToolTip:
	ToolTip()
}

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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 18 Apr 2023, 21:49

Huh? Go back to your last script, and don’t do anything else but add the line I said to add as the first line in the function.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by LAPIII » 18 Apr 2023, 21:53

Okay

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
#NoTrayIcon
CoordMode("ToolTip", "Screen")

Hotkeys := ["X = Close", "O = Open"]
for Each, HK in Hotkeys
	HotkeyList .= HK "`n"
return

^F1::{
static Toggle := False {
Toggle := True
ToolTip(HotkeyList, 872, 469)
 } Else (Toggle = True) {

      Toggle := False

      ToolTip()

   }
}

esc::{
RemoveToolTip:
	ToolTip()
}

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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 18 Apr 2023, 21:56

No, I didn’t say to replace the if statement. Insert it before that line as a new line in the function.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by LAPIII » 18 Apr 2023, 22:50

I don't know if there is some interference, but The tooltip will only blip on the screen after pressing ^F1 many times. And As you can see from this a animated gif that I made to show you so what I had just explained, the tooltip seems to actually be something that jumps around the screen:
Hotkeys_tooltip.ahk_-_SciTE4AutoHotkey_[4_of_4] 18_04_23 11⦂42⦂58⦂894 PM.gif
Hotkeys_tooltip.ahk_-_SciTE4AutoHotkey_[4_of_4] 18_04_23 11⦂42⦂58⦂894 PM.gif (36.65 KiB) Viewed 492 times

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

Re: I'm trying to display a list of hotkeys in a tooltip.

Post by boiler » 18 Apr 2023, 23:34

When I said you only needed Else instead of Else If…, you can’t leave in the condition (Toggle = True) that went along with the If. That has to come out too. The way you have it now, that’s the only thing that executes as a condition of the else. The stuff in the braces below it now executes no matter what, whether the else or if branch is is true.

Just get rid of the (Toggle = True), and it should all work.

Post Reply

Return to “Ask for Help (v1)”