2

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.

2 Answers 2

2

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
0
0

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

1
  • 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, 2012 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .