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.

For example when I press #1 it sends hey

#1::
send hey

When I press #1 again within 900 milliseconds I want it to send hi and so forth.

So what I want to achieve is to bind several commands by pressing the same button within a given time span.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

To chain key presses together as N key presses per X milliseconds you can use the following structure:

key::
    x = ;milliseconds

    if n > 0
    {
        n += 1
        return
    }

    n = 1
    SetTimer, Chain, %x%
    return

    Chain:
        SetTimer, Chain, off

        if n = 1
        {
            ;if key was pressed 1x
        }
        else if n = 2
        {
            ;if key was pressed 2x
        }
        else if n > 2
        {
            ;if key was pressed 3x or more
        }

    n = 0
    return

So, based on your example, we have:

#1::
    x = 900

    if n > 0
    {
        n += 1
        return
    }

    n = 1
    SetTimer, Chain, %x%
    return

    Chain:
        SetTimer, Chain, off

        if n = 1
        {
            Send, hey
        }
        else if n = 2
        {
            Send, hi
        }

    n = 0
    return
share|improve this answer
    
this worked perfect. Thanks a bunch! –  Mikey Mar 14 '12 at 18:16

Simple, just use the Sleep command and pass milliseconds to it.

#1::
Send hey
Sleep, 900 ; 1 second
Send hi
return

For your last sentence, use a global variable and an if expression. So, instead of "Send hey" you would have an if where you select which string you send. Then you set a global variable to 1 after which you sleep, after sleeping you set it back to 0...

See also: If, Hotkeys, Sleep and Variables

share|improve this answer
1  
Thanks, I will try that. My Question has been answered though. I just started with scripting and glad about your help –  Mikey Mar 14 '12 at 18:18

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.