Hotkey profiles Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
strawberrysteel
Posts: 1
Joined: 31 Jan 2018, 07:04

Hotkey profiles

31 Jan 2018, 07:23

Hi everyone. I'm trying to find a way to have several profiles for hotkeys that can be toggled with a key or key . For example, if I press '1', I want 'q' to output '1', if I press '2' - for 'q' to become '2' and so on. So far I've only got Duplicate hotkey errors with several approaches

edit: thanks, boiler, works flawlessly. I seemed to always forget to put # in front of 'if'
Last edited by strawberrysteel on 01 Feb 2018, 03:54, edited 1 time in total.
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: Hotkey profiles  Topic is solved

31 Jan 2018, 11:12

Use the Hotkey command to define/change your hotkeys.

Another approach would be to use the typical hotkey labels approach preceded by an #If directive, such as:

Code: Select all

Profile := 1 ;default
$1::Profile := 1
$2::Profile := 2

#If Profile = 1
q::Send, 1

#If Profile = 2
q::Send, 2
koolestani
Posts: 78
Joined: 15 Jun 2020, 04:22

Re: Hotkey profiles

09 Jan 2021, 10:28

Can just one hotkey cycle through multiple profiles, instead of assigning dedicated hotkey for each profile?
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: Hotkey profiles

09 Jan 2021, 11:41

Sure. Like this:

Code: Select all

Profile := 1 ; default
Count := 3

^Tab:: ; Ctrl+Tab to cycle through the profiles
	Profile := Profile = Count ? 1 : Profile + 1
	ToolTip, % "Profile " Profile
	SetTimer, ToolTipOff, -1000
return

ToolTipOff:
	ToolTip
return

#If Profile = 1
q::Send, 1

#If Profile = 2
q::Send, 2

#If Profile = 3
q::Send, 3
koolestani
Posts: 78
Joined: 15 Jun 2020, 04:22

Re: Hotkey profiles

10 Jan 2021, 02:05

Thank you so much! You're a legend :D

Can you help me with this, I wanted profile 2 behave as below:

When using Mozilla Firefox/Google Chrome
Volume Up ➡ "."
Volume Down ➡ ","
(these are the keys for next and previous frame for YouTube)

When using VLC Media Player
Volume Up ➡ "e"
Volume Down ➡ "Shift+Left"
(these are the keys for next and previous frame for VLC)

I have managed to achieve this with the following code:

Code: Select all

#If Profile = 2
#IfWinActive, ahk_class MozillaWindowClass
Volume_Up::Send .
Volume_Down::Send ","

#IfWinActive, ahk_class Qt5QWindowIcon
Volume_Up::Send e
Volume_Down::Send +{Left}
It's working perfectly for now, but i'm not sure; do i need an IF contingency here (its working as expected outside these two apps as well so i'm guessing i don't.)
I wanted to add another condition here which is when using Firefox/Chrome the window title should contain " - YouTube".
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: Hotkey profiles

10 Jan 2021, 09:32

koolestani wrote: It's working perfectly for now, but i'm not sure; do i need an IF contingency here (its working as expected outside these two apps as well so i'm guessing i don't.)
They should work only when the specified windows are active. What they wouldn't do is pay attention to the profile number because that gets wiped out by the #IfWinActive. To have it subject to both, you would do this:

Code: Select all

#If Profile = 2 && WinActive("ahk_class MozillaWindowClass")
Volume_Up::Send .
Volume_Down::Send ","

#If Profile = 2 && WinActive("ahk_class Qt5QWindowIcon")
Volume_Up::Send e
Volume_Down::Send +{Left}

koolestani wrote: I wanted to add another condition here which is when using Firefox/Chrome the window title should contain " - YouTube".
To do this, the condition would be:

Code: Select all

#If Profile = 2 && WinActive(" - YouTube")
...and you would need to put this at the top of your script:

Code: Select all

SetTitleMatchMode, 2
koolestani
Posts: 78
Joined: 15 Jun 2020, 04:22

Re: Hotkey profiles

10 Jan 2021, 10:47

Once again, worked perfectly. Thank you again.
Is there a way to change the profile name displayed in the tooltip (assuming profiles can be named in the first place)?
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: Hotkey profiles

10 Jan 2021, 11:09

You could do something like this:

Code: Select all

Profile := 1 ; default
ProfileName := ["Apple", "Banana", "Cherry"]

^Tab:: ; Ctrl+Tab to cycle through the profiles
	Profile := Profile = ProfileName.Count() ? 1 : Profile + 1
	ToolTip, % "Profile: " ProfileName[Profile]
	SetTimer, ToolTipOff, -1000
return

ToolTipOff:
	ToolTip
return

#If Profile = 1
q::Send, 1

#If Profile = 2
q::Send, 2

#If Profile = 3
q::Send, 3
koolestani
Posts: 78
Joined: 15 Jun 2020, 04:22

Re: Hotkey profiles

12 Jan 2021, 11:15

Thank you for helping, much appreciated.
flamingonion
Posts: 20
Joined: 11 Feb 2018, 21:54

Re: Hotkey profiles

23 Jan 2023, 11:13

boiler wrote:
31 Jan 2018, 11:12
Use the Hotkey command to define/change your hotkeys.

Another approach would be to use the typical hotkey labels approach preceded by an #If directive, such as:

Code: Select all

Profile := 1 ;default
$1::Profile := 1
$2::Profile := 2

#If Profile = 1
q::Send, 1

#If Profile = 2
q::Send, 2
Hi, I know this is an old thread but it's exactly what I'm looking for and I would really appreciate it if someone can help me with my scenario.
So after pressing q to send 1, how do I make it switch to another profile without pressing key associate to that profile?
Thank you, hope to get some helps!
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: Hotkey profiles

23 Jan 2023, 16:41

flamingonion wrote: So after pressing q to send 1, how do I make it switch to another profile without pressing key associate to that profile?
Do you mean that after pressing q, you want it to not only send 1 but also switch to a different profile number? Something like this?:

Code: Select all

Profile := 1 ;default
$1::Profile := 1
$2::Profile := 2

#If Profile = 1
q::
Send, 1
Profile := 2
return

#If Profile = 2
q::
Send, 2
Profile := 1
return
flamingonion
Posts: 20
Joined: 11 Feb 2018, 21:54

Re: Hotkey profiles

23 Jan 2023, 22:35

boiler wrote:
23 Jan 2023, 16:41
flamingonion wrote: So after pressing q to send 1, how do I make it switch to another profile without pressing key associate to that profile?
Do you mean that after pressing q, you want it to not only send 1 but also switch to a different profile number? Something like this?:

Code: Select all

Profile := 1 ;default
$1::Profile := 1
$2::Profile := 2

#If Profile = 1
q::
Send, 1
Profile := 2
return

#If Profile = 2
q::
Send, 2
Profile := 1
return
Thank you for the response, I didn't know it was that straightforward lol, cheer!
User avatar
OrangeCat
Posts: 24
Joined: 14 Jun 2022, 00:47

Re: Hotkey profiles

21 Jul 2023, 23:17

Hello

I've been attempting to create a script similar to this
(for which, after having just now found your script, clarified quite a lot).

Although I've been having trouble with tooltips as they do not want to display/popup.

Even by copy/pasting to then executing this exact-provided script-example as-is, to yet still be facing this very problem.
(this trouble was also a present-factor withing own prior-script's version)

Although, if I create a separate hotkey to create a "non-relative to any variable/what-so-ever" generic-tooltip, then it works.
(a generic tooltip to display a basic direct-string entry).


I was wondering if something had changed since original-date of this provided-example?
Or if there's something else that I'm missing? maybe a "#persistent" or something?

To further elaborate:
My understanding of scripte-example; Ctrl+Tab switches profiles in concurrence of generating a profile-name tooltip.
Changing profile is successful although nothing is happening in terms of tooltip.

Side-Note:
My AHK v1 is configured via a "per-script's tasktray icon". (not sure if this would make a difference).

If anyone would have any ideas to share, it would be greatly appreciated.

Kind regards,


OrangeCat
---------------------------------------------------------------------------------------------------------------------------------------
boiler wrote:
10 Jan 2021, 11:09
You could do something like this:

Code: Select all

Profile := 1 ; default
ProfileName := ["Apple", "Banana", "Cherry"]

^Tab:: ; Ctrl+Tab to cycle through the profiles
	Profile := Profile = ProfileName.Count() ? 1 : Profile + 1
	ToolTip, % "Profile: " ProfileName[Profile]
	SetTimer, ToolTipOff, -1000
return

ToolTipOff:
	ToolTip
return

#If Profile = 1
q::Send, 1

#If Profile = 2
q::Send, 2

#If Profile = 3
q::Send, 3
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: Hotkey profiles

22 Jul 2023, 03:27

OrangeCat wrote: Although I've been having trouble with tooltips as they do not want to display/popup.

Even by copy/pasting to then executing this exact-provided script-example as-is, to yet still be facing this very problem.
(this trouble was also a present-factor withing own prior-script's version)

Although, if I create a separate hotkey to create a "non-relative to any variable/what-so-ever" generic-tooltip, then it works.
(a generic tooltip to display a basic direct-string entry).


I was wondering if something had changed since original-date of this provided-example?
Or if there's something else that I'm missing? maybe a "#persistent" or something?
Nothing is missing, and #Persistent has nothing to do with it in a script that has a hotkey. Write a very simple script that displays a ToolTip. And write the simplest script possible that recreates the problem of not displaying a ToolTip. Post both scripts here if you can’t solve it via that exercise.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: arrondark, kozak, mikeyww and 163 guests