Page 1 of 1

Hotkey profiles

Posted: 31 Jan 2018, 07:23
by strawberrysteel
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'

Re: Hotkey profiles  Topic is solved

Posted: 31 Jan 2018, 11:12
by boiler
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

Re: Hotkey profiles

Posted: 09 Jan 2021, 10:28
by koolestani
Can just one hotkey cycle through multiple profiles, instead of assigning dedicated hotkey for each profile?

Re: Hotkey profiles

Posted: 09 Jan 2021, 11:41
by boiler
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

Re: Hotkey profiles

Posted: 10 Jan 2021, 02:05
by koolestani
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".

Re: Hotkey profiles

Posted: 10 Jan 2021, 09:32
by boiler
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

Re: Hotkey profiles

Posted: 10 Jan 2021, 10:47
by koolestani
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)?

Re: Hotkey profiles

Posted: 10 Jan 2021, 11:09
by boiler
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

Re: Hotkey profiles

Posted: 12 Jan 2021, 11:15
by koolestani
Thank you for helping, much appreciated.

Re: Hotkey profiles

Posted: 23 Jan 2023, 11:13
by flamingonion
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!

Re: Hotkey profiles

Posted: 23 Jan 2023, 16:41
by boiler
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

Re: Hotkey profiles

Posted: 23 Jan 2023, 22:35
by flamingonion
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!

Re: Hotkey profiles

Posted: 21 Jul 2023, 23:17
by OrangeCat
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

Re: Hotkey profiles

Posted: 22 Jul 2023, 03:27
by boiler
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.