Thank you both for your reply. However, I apologize for not stating my needs more clearly.
I am actually trying to achieve 16 hotkeys through 2-key combinations of 1, 2, 3, 4. In other words, I need 11, 12, 13, 14, 21, 22, 23, 24, ..., 41, 42, 43, 44.
I tried modifying both of your codes but I couldn't get either to work how I want.
First I tried to modify buttshark's code into a function.
Code: Select all
*$1::Shortcut("{F1}1", "{F1}2", "{F1}3", "{F1}4")
*$2::Shortcut("{F1}5", "{F1}6", "{F1}7", "{F1}8")
*$3::Shortcut("{F2}1", "{F2}2", "{F2}3", "{F2}4")
*$4::Shortcut("{F2}5", "{F2}6", "{F2}7", "{F2}8")
Shortcut(ks1, ks2, ks3, ks4, t = 200) {
CurrentKey := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
t := A_TickCount + t
while(getkeystate(CurrentKey, "p"))
{}
while(A_TickCount < t)
{
Loop 4
{
key := A_Index
if(getkeystate(key, "p"))
goto, lbl%key%
}
}
return
lbl1:
;Send %ks1%
MsgBox %CurrentKey% %key% lbl1
return
lbl2:
;Send %ks2%
MsgBox %CurrentKey% %key% lbl2
return
lbl3:
;Send %ks3%
MsgBox %CurrentKey% %key% lbl3
return
lbl4:
;Send %ks4%
MsgBox %CurrentKey% %key% lbl4
return
}
When running this script, only 11, 22, 33, 44 worked.
Next I tried to write out the script manually without using function.
Code: Select all
*$1::
t := A_TickCount + 200
while(getkeystate("1", "p"))
{}
while(A_TickCount < t)
{
Loop 4
{
key := A_Index
if(getkeystate(key, "p"))
goto, lbl1_%key%
}
}
return
*$2::
t := A_TickCount + 200
while(getkeystate("2", "p"))
{}
while(A_TickCount < t)
{
Loop 4
{
key := A_Index
if(getkeystate(key, "p"))
goto, lbl2_%key%
}
}
return
lbl1_1:
MsgBox 11
return
lbl1_2:
MsgBox 12
return
lbl1_3:
MsgBox 13
return
lbl1_4:
MsgBox 14
return
lbl2_1:
MsgBox 21
return
lbl2_2:
MsgBox 22
return
lbl2_3:
MsgBox 23
return
lbl2_4:
MsgBox 24
return
I only had 11 through 24, and like before 12 and 21 doesn't work. 13, 14, 23, 24 works but I suspect if I wrote in hotkeys for 3 and 4 they will stop working as well.
Then I tried modifying swagfag's code.
Code: Select all
*$1::
SetTimer 1Timeout, -200
1Next := true
return
*$2::
SetTimer 2Timeout, -200
2Next := true
return
1Timeout:
1Next := false
return
2Timeout:
2Next := false
return
#If 1Next
*$1::
MsgBox 11
1Next := false
return
*$2::
MsgBox 12
1Next := false
return
*$3::
MsgBox 13
1Next := false
return
*$4::
MsgBox 14
1Next := false
return
#If 2Next
*$1::
MsgBox 21
2Next := false
return
*$2::
MsgBox 22
2Next := false
return
*$3::
MsgBox 23
2Next := false
return
*$4::
MsgBox 24
2Next := false
return
This actually works. But I want to use those as shortcuts in a game so I tried to add this in the beginning.
Code: Select all
#IfWinActive ahk_exe MonsterHunterWorld.exe
And suddenly 11, 12, 21, 22 won't work anymore. Same as before 13, 14, 23, 24 still works but if I added the hotkeys for 3 and 4 then everything probably would stop working.
What baffles me is that, if I comment out the #IfWinActive, then the script works perfectly in game. When I replaced the MsgBox with actual game commands, they trigger the in-game actions flawlessly.