AutoHotKey script for copying source to target, changing status to rejected and lock segment

Hello everyone,

I am fairly new to the world of AutoHotKey, so I apologize in advance if my question is a bit stupid, or if the code I have below is not very efficient!
I tried composing a script that would copy source to target (F4), change status segment to rejected and lock segments (CTRL+L) all at once, but it seems using the succession of keys ALT, H, U and R poses a problem while in the editor. When I do it without the script, it works just fine, but when I use AHK it does not work. Any idea how to solve (or bypass) this? Is it because mnemonic keys cannot be used efficiently without a sleep time?
We have a lot of projects where we need to do this a great number of times, so I think a (working) script would help! Here is what I am using:

^r::
Send {F4}
Send !
Send h
Send u
Send r
Send ^l
Return

Anyone has an idea?
Thanks!
Émile

Parents
  • Salut Émile,

    When sending keyboard shortcuts to a program, it can easily happen that your script is too fast for the concerned program which isn't able to digest all the commands it receives quickly enough. Adding a small break ("Sleep" command) between the individual shortcuts you send helps with that and provides enough time for Studio to handle each command.

    #IfWinActive, ahk_exe SDLTradosStudio.exe
    ^r::
    SendInput ^{Ins}
    Sleep, 150
    SendInput !h
    Sleep, 150
    SendInput, u
    Sleep, 150
    SendInput, r
    Sleep, 150
    SendInput, ^l
    Return

    You might have to adjust the sleep duration (e.g. from 150 to 200 or 300 milliseconds) if it doesn't work out of the box.

    I have also added the "#IfWinActive" command, which makes all hotkeys beneath it context sensitive, i.e. they only work when the Studio window is active.
    If anything is unclear or still doesn't work as expected, please let me know.

    Cordialement de Bruxelles,
    Raphaël

  • Thank you so much Raphaël, it works well with your suggestion! This opens the door to so many possibilities with mnemonic keys. Out of curiosity, I noticed that you kept "!h" on the same line (ALT and h), but separated the other keys. After testing this, it appears to be necessary to keep those two keys on the same line, but I am not sure why. Would you happen to know why? Merci encore!
Reply Children