Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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
share|improve this answer
    
Oh! That makes perfect sense, thank you! –  CornSmith Mar 4 '12 at 2:53
    
Hm and you're right about the indentation. I just fixed that. –  CornSmith Mar 4 '12 at 2:56
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 Mar 4 '12 at 2:58
1  
Anyway, 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 Mar 4 '12 at 3:03
1  
What a warm welcome : ) answer accepted. –  CornSmith Mar 4 '12 at 3:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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