0

What's a good way to reorganize the longer script into a more efficient solution and retain the same functionality? I thought the above solution using a While loop will do, but the input of the keys is conflicting in a way now which I don't understand anymore.

Any alternative ways that would be better to recreate the functionality of the longer script?
I'm wondering if it wold be necessary to define the keys in an array and then retrieve the input for each key press held down or up, but I'm unsure about the right syntax for AutoHotkey.

$Up::
$Down::
$Left::
$Right::
While, GetKeyState(LTrim(A_ThisHotkey, "$"), "P")
{
    SendInput, % "{" . LTrim(A_ThisHotkey, "$") . " down}"
    ControlSend,, % "{" . LTrim(A_ThisHotkey, "$") . " down}"
}
SendInput, % "{" . LTrim(A_ThisHotkey, "$") . " up}"
ControlSend,, % "{" . LTrim(A_ThisHotkey, "$") . " up}"
Return

Up::
SendInput {Up down}
ControlSend,, {Up down}
Return
Up up::
SendInput {Up up}
ControlSend,, {Up up}
Return

Down::
SendInput {Down down}
ControlSend,, {Down down}
Return
Down up::
SendInput {Down up}
ControlSend,, {Down up}
Return

Left::
SendInput {Left down}
ControlSend,, {Left down}
Return
Left up::
SendInput {Left up}
ControlSend,, {Left up}
Return

Right::
SendInput {Right down}
ControlSend,, {Right down}
Return
Right up::
SendInput {Right up}
ControlSend,, {Right up}
Return
0

Some things you could look at:

  • Making it a function called by each hotkey (vs. a single set of code that executes in the main script)
  • Calling via SetTimer--this can put things on separate threads
  • Looking at the Critical command--this may help you understand what can be interrupted or not (and how subsequent hotkey interruptions might work on your code setup)

These may not actually get you there 100% but will give you things to try...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.