Autohotkey `1 key sequence

1

In MSword I would like to set

`1

to be a key sequence to trigger a script but I also have other scripts in MSword with the hotkeys

1

and key sequence

11    ; (one pressed twice fast)

the code goes like this

; The following hotkeys work only if MS-WORD is the active window:
#If WinActive("ahk_exe WINWORD.EXE")    ; (1)

1::
if 1_presses > 0
{
    1_presses += 1
    SetTimer Key1, 300
    return
}
1_presses = 1
SetTimer Key1, 300
return

Key1:
SetTimer Key1, off
if 1_presses = 2
  SendInput, BYE
else
  SendInput, HELLOW
1_presses = 0
return

How can I set the `1 keysequence trigger without interfere with the other hotkeys???

Thanks Advanced.

litu16

Posted 2016-11-21T16:44:28.180

Reputation: 143

Answers

2

#If WinActive("ahk_exe WINWORD.EXE") 

    ; SC029 is the scancode of the key "`"

    ; SC029::
    ; KeyWait, SC029
    ; return

    SC029 Up::
    Send {SC029}
    return

    ; press 1 while you're holding down the "`"-key, to send a
    SC029 & 1:: Send a

    1::
    ; press 1 in less than 300 ms after pressing the "`"-key, to send b
    If (A_PriorHotKey = "SC029 Up" AND A_TimeSincePriorHotkey < 300)
    {
        Send {BS}b
        return
    }
    ; otherwise:
    if 1_presses > 0
    {
        1_presses += 1
        SetTimer Key1, 300
        return
    }
    1_presses = 1
    SetTimer Key1, 300
    return

    Key1:
    SetTimer Key1, off
    if 1_presses = 2
      SendInput, BYE
    else
      SendInput, HELLOW
    1_presses = 0
    return

#If

user3419297

Posted 2016-11-21T16:44:28.180

Reputation: 2 055

yes, I mean exactly that key, but the code above doesn't work, lets say I wan't to display a msg box when pressing the SC029 & 1, I put your script above but it doesn't do that, it just run the script that uses the 1 key as a trigger, I mean it prints HELLOW. – litu16 – 2016-11-21T17:27:10.373

You don't have to run two scripts. Of course the other script interferes. Copy the above (modified) code in one script and run it first of all as standalone script. – user3419297 – 2016-11-21T17:40:29.513

Hi user 3419297 I must tipe very fast 1 in order to get "a", otherwise it will type HELLOW, I have tried to change SetTimer Key1, 600 but tha same result, the script is kinda unstable? – litu16 – 2016-11-21T18:42:27.340

Does it work if you remove the 1::-hotkey? – user3419297 – 2016-11-21T19:04:21.737

BTW, "SC029 & 1::" means that you press 1 while you're holding down the "`"-key. – user3419297 – 2016-11-21T19:25:23.790

Oh I see, I have notice that (as you just said in your last comment) "SC029 & 1::" means that you press 1 while you're holding down the key. So in that manner the script works fine, but that is a "key combination" trigger, I would like the trigger to be a "key sequence" 1, I mean, press down press up and then continue in less than 400 to press the key 1, is it possible? thanks advanced. – litu16 – 2016-11-22T13:21:26.083

Let us continue this discussion in chat.

– user3419297 – 2016-11-22T14:51:17.193

thanks it works fine, but I'm having problems in response (kind of glitch) when using the (bb) and (11) keysequnces scripts together. I specified my problem here http://superuser.com/questions/1148598/some-response-problems-using-two-key-sequence-scripts-in-autohotkey Hope you could check it, thanks advanced.

– litu16 – 2016-11-22T15:04:56.203

by the way, I kinda understand how the script works, but I don't quite get what does Key1: mean, I mean, I know that settimer set it, but is it a kind of function?? does the colom is used only by settimer or the colom sign is used in other cases too, Thanks Advanced. – litu16 – 2016-11-23T00:48:34.243

Key1 is a Label.https://autohotkey.com/docs/commands/SetTimer.htm#Parameters – user3419297 – 2016-11-23T11:11:04.880

Hi user3419297, please could you check this question? http://superuser.com/questions/1149519/use-space-alt-q-to-trigger-some-actions-in-autohotkey thanks advanced.

– litu16 – 2016-11-24T22:14:55.997