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.

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
  • 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 Nov 21 '16 at 17:27
  • 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 Nov 21 '16 at 17:40
  • 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 Nov 21 '16 at 18:42
  • Does it work if you remove the 1::-hotkey? – user3419297 Nov 21 '16 at 19:04
  • BTW, "SC029 & 1::" means that you press 1 while you're holding down the "`"-key. – user3419297 Nov 21 '16 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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