Page 1 of 1

define hotkey with modifier in loop

Posted: 21 Jul 2018, 04:36
by kurti
I'm sorry if this is a stupid question, but I can't find the solution for the life of me.

I have a loop that defines a hotkey for each character a-z:

Loop, 26
Hotkey, % Chr(A_Index + 64), DoSomething

What I can't figure out is how to do this with a modifier symbol, e.g. "+" (Shift), so that the hotkey is only triggerd when I have Shift pressed together with the character.

Re: define hotkey with modifier in loop

Posted: 21 Jul 2018, 05:17
by GEV

Code: Select all

Loop, 26
{
	key := % Chr(A_Index + 64)
	Hotkey, %key%, DoSomething
	Hotkey, +%key%, DoSomethingElse
}
return

DoSomething:
DoSomethingElse:
	MsgBox, % A_ThisHotkey
return

Re: define hotkey with modifier in loop

Posted: 21 Jul 2018, 18:01
by lexikos
You can simply concatenate.

Code: Select all

Loop, 26
    Hotkey, % "+" Chr(A_Index + 64), DoSomething
key := % Chr(A_Index + 64)
This is tolerated by the program, but invalid. The percent sign should be removed.