sendKey - using command line parameters
-
Within [this] thread, several options have been shown sending a single key/multiple keys to your PC using TCMD
I've written a tiny [AutoHotkey] script that can be executed using a TCMD command (line), where its parameters are representing the keys that should be sent to the PC.
Additionally, it allows specifying a delay (sec) after a key has been "pressed"/sent.
So, the following TMCD command line...
autohotkey.exe script.ahk {F2}:1.5 {F3}:5 {F4}:3 "Hello World" {F5}
https://www.autohotkey.com/docs/Scripts.htm#cmd
...will execute 'script.ahk' on the PC that will process the space-separated parameters like '{F2}:1.5' ... into keypresses ...in its consecutive order.
script.ahk
#SingleInstance, Force Loop % A_Args.Count() { param := StrSplit(A_Args[A_Index],":") p := InStr(A_Args[A_Index],":") ? param.1 : A_Args[A_Index] d := InStr(A_Args[A_Index],":") ? param.2 : 1 Send % p Sleep % d*1000 }
In my test case, this would trigger the following hotkeys, set up in an already running script on my PC (myHotkeys.ahk), that are persistently waiting to be triggered via the key presses executed via TCMD.
myHotkeys.ahk
F2::MsgBox % A_Now F3::SoundBeep F4::Run % "notepad.exe" F5::FileAppend,% A_Now, my.log
What means...
...once {F2} has been sent, a message box will be opened showing a timestamp : sleeping for 1.5 sec...once {F3} has been sent, a soundbeep occurs : sleeping for 5 sec
... once {F4} has been sent, notepad opens : sleeping for 3 sec
The string 'Hello World' is sent to the app that has the focus : default delay of 1 sec (bc it wasn't explicitly set)
... finally {F5} has been sent, timestamp will be written to 'my.log' ... *
As you can see, besides triggering AHK Hotkeys you can send generic text strings too (and/or call functions() etc.)
BTw, ATM - no specific error handling!
If, for whatever reason you think it's necessary to "compile" an AutoHotkey script you can do that as well. Help yourself:
https://www.autohotkey.com/docs/Scripts.htm#ahk2exeDisclaimer: you're using the script(s) at your own risk.
* you've to set up TC accordingly to be able to handle 'background'-commands/parameters!
-
This post is deleted! -
Yes indeed, if you're using a delay-flag of '0' ie "trigger:0" (that will multiply 0 with 1000ms = 0s) will overwrite the default delay of '1' second between "keypresses".
Therefore this command (line)...autohotkey.exe sendKey().ahk trigger:0 c(67):0 M:0 c(68)
...will send the string 'trigger' followed (without delay) by ASCII-char 67, the string 'M', and (without delay) ASCII-char 68.
The above script (but with that added ASCII-conversion) is available here ...
https://www.autohotkey.com/boards/viewtopic.php?f=7&t=88308&p=475550#p475550