• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

sendKey - using command line parameters

Windows
1
3
927
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    aaaaa12345
    last edited by aaaaa12345 Sep 6, 2022, 12:28 PM Aug 2, 2022, 1:00 PM

    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#ahk2exe

    Disclaimer: 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!

    A 1 Reply Last reply Aug 2, 2022, 2:52 PM Reply Quote 0
    • A
      aaaaa12345 @aaaaa12345
      last edited by Aug 2, 2022, 2:52 PM

      This post is deleted!
      1 Reply Last reply Reply Quote 0
      • A
        aaaaa12345
        last edited by aaaaa12345 Sep 6, 2022, 12:20 PM Aug 2, 2022, 4:39 PM

        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

        1 Reply Last reply Reply Quote 0
        1 out of 3
        • First post
          1/3
          Last post