Changing Variable From Key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aweinberg
Posts: 52
Joined: 08 Feb 2019, 15:38

Changing Variable From Key

14 Dec 2020, 21:18

Instead of repeating the code (below) over and over as the only thing that changes are the keys c, a, b, y, h, p, r but the rest of the code is identical.

How do I make the code pull form a variable key for (c, a, b, y, h, p, r) and insert that variable into the code.

Below the c variable could be (c, a, b, y, h, p, r)

Code: Select all

#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$c:: ; $ prevents the next line from triggering this hotkey
send, c
keywait, c
return 
Original code

Code: Select all

#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$c:: ; $ prevents the next line from triggering this hotkey
send, c
keywait, c
return  

c up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class73")
	Send, v ; I assume you meant 'Send, v' and not 'Send v,' like you had
return



#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$a:: 
send, a
keywait, a
return  

a up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class73")
	Send, v 
return



#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$b:: 
send, b
keywait, b
return  

b up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class73")
	Send, v 
return



#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$y:: 
send, y
keywait, y
return  

y up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class73")
	Send, v 
return




#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$h:: 
send, h
keywait, h
return  

h up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class73")
	Send, v 
return




#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$p:: 
send, p
keywait, p
return  

p up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class73")
	Send, v 
	
	
	
	#IfWinActive, ahk_exe Adobe Premiere Pro.exe
$r:: 
send, r
keywait, r
return  

r up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class73")
	Send, v
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Changing Variable From Key

14 Dec 2020, 21:32

Code: Select all

$a::
$b::
$c::
$h::
$p::
$r::
$y::
Send % hk := StrReplace(A_ThisHotkey, "$")
KeyWait, %hk%
Return
aweinberg
Posts: 52
Joined: 08 Feb 2019, 15:38

Re: Changing Variable From Key

14 Dec 2020, 22:03

Thanks for the reply Mike, I am getting an error at the line %hk% up::
Not sure how to make repeat the variable for the key wait command.

Code: Select all

$a::
$b::
$c::
$h::
$p::
$r::
$y::

#IfWinActive, ahk_exe Adobe Premiere Pro.exe
Send % hk := StrReplace(A_ThisHotkey, "$")
KeyWait, %hk%
Return

%hk% up::
ControlGetFocus, FocusedCtrl , ahk_exe Adobe Premiere Pro.exe
if (FocusedCtrl = "DroverLord - Window Class73")
	Send, v ; I assume you meant 'Send, v' and not 'Send v,' like you had
return
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Changing Variable From Key

14 Dec 2020, 22:15

Code: Select all

#IfWinActive ahk_exe Adobe Premiere Pro.exe
$a::
$b::
$c::
$h::
$p::
$r::
$y::
Send % hk := StrReplace(A_ThisHotkey, "$")
KeyWait, %hk%
Return

a Up::
b Up::
c Up::
h Up::
p Up::
r Up::
y Up::
ControlGetFocus, FocusedCtrl
Send % FocusedCtrl = "DroverLord - Window Class73" ? "v" : ""
Return
#IfWinActive
aweinberg
Posts: 52
Joined: 08 Feb 2019, 15:38

Re: Changing Variable From Key

14 Dec 2020, 22:25

Hmm broke the code. I''ll try to figure out how to get it working, thanks for the help, very appreciated.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Changing Variable From Key

14 Dec 2020, 22:27

An additional way. Ensure that your old scripts are not still running.

Code: Select all

#SingleInstance Prompt
key = abchpry
Hotkey, IfWinActive, ahk_exe Adobe Premiere Pro.exe
Loop, Parse, key
 Hotkey, $%A_LoopField%, keyDown
Hotkey, IfWinActive
Return

keyDown:
Send % hk := StrReplace(A_ThisHotkey, "$")
KeyWait, %hk%
ControlGetFocus, FocusedCtrl
Send % FocusedCtrl = "DroverLord - Window Class73" ? "v" : ""
Return
Last edited by mikeyww on 14 Dec 2020, 22:40, edited 4 times in total.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Changing Variable From Key

14 Dec 2020, 22:39

I simplified a bit above. If you have a KeyWait, you probably don't also need a separate Up routine.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 329 guests