; Set default location and name convention for compiled scripts to use ;@Ahk2Exe-ExeName %A_MyDocuments%\AutoHotkey\bin\AHK-%A_ScriptName% ; Install hooks to make sure script can get physical state of keys instead of logical state. #InstallKeybdHook #InstallMouseHook ; Settings #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. #UseHook ; All hotkeys are implemented through keyboard hook to avoid script activating itself. #MenuMaskKey vkFF ; ; Function definitions ; Hold(Primary, Secondary) { Send {%Primary% down} if ( Secondary.Length() != 0 ) { ThisLoop := Func("HoldLoop").bind(Primary,Secondary) SetTimer, %ThisLoop%, 50 } } HoldLoop(Primary, Secondary) { if GetKeyState(Primary,"P") { SetTimer, , Delete } for index,key in Secondary { if GetKeyState(key,"P") { Send {%Primary% up} SetTimer, , Delete } } } Repeat(Primary, Secondary) { Send {%Primary% up} Sleep 100 RepeatVar := 0 Loop { if GetKeyState(Primary,"P") { return } for index,key in Secondary { if GetKeyState(key,"P") { return } } if (RepeatVar == 2) { SendEvent, {%Primary%} RepeatVar := 1 } else { RepeatVar++ } Sleep 50 } }