Autohotkey is executing everything past my loop's end

2

I'm using autohotkey to make (hjkl) my arrow keys, and scroll faster without doing pagedowns/ups, which makes reading textbooks with large illustrations easier.

The problem is that ahk is executing everything once my "spacebar" loop is finished. Ex. in the code below, it will go 16 spaces down, and one space up. It shouldn't go one space up unless I press "z".

Suspend On

h::Left
j::Down
k::Up
l::Right

space::
    Loop,8{
        Send {Down}
        Send {Down}
    }

z::
    Send {Up}

+Capslock::
CapsLock::Suspend Off
CapsLock Up::Suspend On

I've watched a few tutorials on loops now and I don't see how I could be doing anything wrong. The rest of the code works.

CornSmith

Posted 2012-03-04T02:35:14.143

Reputation: 133

Answers

4

You need to return at the end of each multi-line method or hotkey. Otherwise, by logic, you haven't specified when a certain method ends. Note that single line methods have an implied return statement.

I've cleaned up and fixed your script (I have strict style on commas, capitalization, indentation/whitespace, and placing brackets on their own line):

Suspend, On

h::Left
j::Down
k::Up
l::Right

Space::
    Loop, 8
    {
        Send, {Down}
        Send, {Down}
    }
    return

z::
    Send, {Up}
    return

+CapsLock::
CapsLock::Suspend, Off
CapsLock Up::Suspend, On

iglvzx

Posted 2012-03-04T02:35:14.143

Reputation: 21 611

Hm and you're right about the indentation. I just fixed that. – CornSmith – 2012-03-04T02:56:41.140

1@CornSmith I do not think that indentation will make a difference. Not having a space here or there might, but indentation is just for readability. – iglvzx – 2012-03-04T02:58:40.140

1Anyway, Welcome to Super User! You can accept my answer if it is satisfactory. This will help the community know to move on to other questions :) – iglvzx – 2012-03-04T03:03:23.473