Profiles Within Applications

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
koolestani
Posts: 78
Joined: 15 Jun 2020, 04:22

Profiles Within Applications

Post by koolestani » 15 May 2024, 23:41

Hello

So I have tried to come up with a script that performs actions on the basis of two criterion. The first criteria is the application whose window is currently active, and after that it looks for what profile is currently active (profile is a variable that I can control with pre defined hotkeys for each profile).

So the idea was to be able to do multiple tasks using the same hotkeys which means as the profile changes, the task performed by the same hotkey changes as well. And all these definitions of hotkeys needs to be different depending on which windows is currently active. I can imagine at most seven profiles for a given application, but let's just say, the entire number row will be used for activating a different profile, so that's ten profiles max.

I imagine this to be similar to a menu bar of an application. Just like we know the items of a menu bar usually go like this File Edit View Help, similarly I hope to get used to these profiles so much that I'll remember which does what after repeated use.

I just have this issue of the tooltip not functioning properly, which is very critical for this script and is also I believe, the final kink that's holding me from incorporating this script into my daily usage.
For some reason the tooltip never appears. I expect it to appear near the cursor for the defined period of time when I press the hotkeys to switch to any given profile.

Anyway here is what I've been working with, and thanks in advance. :D

Code: Select all

XButton1 & 2:: ; Hotkey to activate profile
	ProfileName := "Second"
	ToolTip, % ProfileName[Profile]
	SetTimer, ToolTipOff, -1000
return

XButton1 & 3:: ; Hotkey to activate profile
	ProfileName := "Third"
	ToolTip, % ProfileName[Profile]
	SetTimer, ToolTipOff, -1000
return

XButton1 & 4:: ; Hotkey to activate profile
	ProfileName := "Fourth"
	ToolTip, % ProfileName[Profile]
	SetTimer, ToolTipOff, -1000
return

XButton1 & 5:: ; Hotkey to activate profile
	ProfileName := "Fifth"
	ToolTip, % ProfileName[Profile]
	SetTimer, ToolTipOff, -1000
return

XButton1 & 6:: ; Hotkey to activate profile
	ProfileName := "Sixth"
	ToolTip, % ProfileName[Profile]
	SetTimer, ToolTipOff, -1000
return

XButton1 & 7:: ; Hotkey to activate profile
	ProfileName := "Seventh"
	ToolTip, % ProfileName[Profile]
	SetTimer, ToolTipOff, -1000
return

ToolTipOff:
	ToolTip
return

; Google Chrome
#If WinActive("ahk_exe chrome.exe")
Tab::Tab
Tab & 1::Send !{Left}		;Alt ←			Page ←
Tab & 2::Send !{Right}		;Alt →			Page →

Tab & 3::Send ^+{Tab}		;Ctrl Shift Tab		Tab ←
Tab & 4::Send ^{Tab}		;Ctrl Tab		Tab →

XButton2::Send +{F3} ; Find Previous
XButton1::Send {F3} ; Find Next

;WheelUp::Send {Right}		;
;WheelDown::Send {Left}		;
;MButton::
return

#If WinActive("ahk_exe chrome.exe") && ProfileName = "Second" ;
CapsLock::CapsLock
CapsLock & w::Send ^+{Left}		;Select Text One Word ←
CapsLock & e::Send ^+{Right}		;Select Text One Word →

CapsLock & q::Send +{Left}		;Select Text One Char ←
CapsLock & r::Send +{Right}		;Select Text One Char →

CapsLock & s::Send ^{Left}		;Move Cursor One Word ←
CapsLock & d::Send ^{Right}		;Move Cursor One Word →

CapsLock & a::Send ^{Backspace}		;Remove One Word ←
CapsLock & f::Send ^{Delete}		;Remove One Word →

#If WinActive("ahk_exe chrome.exe") && ProfileName = "Third" ; Reading Text
XButton1 & WheelDown::Send ^+{Left}	;Select Text One Word ←
XButton1 & WheelUp::Send ^+{Right}	;Select Text One Word →

XButton1 & LButton::Send {Backspace}
XButton1 & RButton::Send {Delete}

;CapsLock & q::Send +{Left}		;Select Text One Char ←
;CapsLock & r::Send +{Right}		;Select Text One Char →

#If WinActive("ahk_exe chrome.exe") && ProfileName = "Fourth" ;
XButton1 & WheelDown::Send ^{Left}	;Move Cursor One Word ←
XButton1 & WheelUp::Send ^{Right}	;Move Cursor One Word →

#If WinActive("ahk_exe chrome.exe") && ProfileName = "Fifth" ;
XButton1 & WheelDown::Send ^{Backspace}	;Remove One Word ←
XButton1 & WheelUp::Send ^{Delete}	;Remove One Word →

#If WinActive("ahk_exe chrome.exe") && ProfileName = "Sixth" ; YouTube
XButton1 & WheelUp::Send {Right}
XButton1 & WheelDown::Send {Left}

XButton1 & LButton::Send +{<} ; Decrease Speed
XButton1 & RButton::Send +{>} ; Increase Speed

#If WinActive("ahk_exe chrome.exe") && ProfileName = "Seventh" ; Zoom
XButton1 & WheelUp::Send ^{+} ; Zoom Out
XButton1 & WheelDown::Send ^- ; Zoom In

;Windows Explorer
#If WinActive("ahk_class CabinetWClass")

#If WinActive("ahk_class CabinetWClass") && ProfileName = "Second" ;
XButton1 & WheelDown::Send +{Down}	;Selection Contiguous Text/Item ↓
XButton1 & WheelUp::Send +{Up}		;Selection Contiguous Text/Item ↑

#If WinActive("ahk_class CabinetWClass") && ProfileName = "Third" ;
XButton1 & WheelDown::Send +{Left}	;Selection Contiguous Text/Item ←
XButton1 & WheelUp::Send +{Right}	;Selection Contiguous Text/Item →

#If WinActive("ahk_class CabinetWClass") && ProfileName = "Fourth" ;
XButton1 & WheelDown::Send ^{Down}	;Selection Non-Contiguous Item ↓
XButton1 & WheelUp::Send ^{Up}		;Selection Non-Contiguous Item ↑

#If WinActive("ahk_class CabinetWClass") && ProfileName = "Fifth" ;
XButton1 & WheelDown::Send ^{Left}	;Selection Non-Contiguous Item ←
XButton1 & WheelUp::Send ^{Right}	;Selection Non-Contiguous Item →

XButton1 & LButton::Send ^{Space}	;Select/Deselect Item
Last edited by gregster on 16 May 2024, 02:02, edited 1 time in total.
Reason: Moved topic from AHK v2 help since this is v1 code.

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

Re: Profiles Within Applications

Post by boiler » 16 May 2024, 03:10

I don’t understand how these two lines would make sense:

Code: Select all

	ProfileName := "Second"
	ToolTip, % ProfileName[Profile]
The first line assigns a string to ProfileName, and the second line treats ProfileName as if it were an array object.

It would make sense if you assigned a string to Profile, and somewhere there is the definition of an associative array named ProfileName with the key Second as one of its elements, as this stand-alone script demonstrates:

Code: Select all

ProfileName := {First: "Value1", Second: "Value2"}
Profile := "Second"
MsgBox, % ProfileName[Profile]

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

Re: Profiles Within Applications

Post by koolestani » 16 May 2024, 08:02

I probably should have mentioned that I don't really have a clue about what some lines of my script do, at all. But after reading your reply, I kind of got what you meant and was able to make it work, although I did not try the method you suggested. I simply changed the two lines you pointed out into the following

Code: Select all

ProfileName := "Second"
ToolTip, % ProfileName
Thanks again :D

Post Reply

Return to “Ask for Help (v1)”