6

I am running windows 10. Is there a possibility to send (from the command line) a keycode to a windows application that is already running? (such that this application will think that I pressed a certain key?)

The request is to send keys from the command line or other, to control application tab menu command. For example to open or close file or close the application itself.

Malitta N
  • 3,384
  • 22
  • 30
mnr
  • 604
  • 2
  • 7
  • 15
  • What you asked is not a programming question, so it should be directed to [Super User](http://superuser.com/) instead. A programmable way to handle this is to write a console app that parses its command line parameters and generates corresponding calls to [`SendInput()`](https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendinput). – Remy Lebeau Sep 24 '18 at 18:34

1 Answers1

8
(echo with createobject^("wscript.shell"^)
echo .run "notepad.exe"
echo wscript.sleep 1000
echo .sendkeys "IN-THE-NAME-OF-ALLAH"
echo wscript.sleep 300
echo .sendkeys "(%%F)S"
echo  wscript.sleep 2000
echo  .sendkeys "myText.txt"
echo .sendkeys "{enter}" 
echo wscript.sleep 1000
echo .sendkeys "%%{F4}"
echo end with) > %temp%\sk.vbs
start /w %temp%\sk.vbs

This example show how can send key from cmd to application like Notepad.exe to control .

in your situation no need for this line 2 echo .run "notepad.exe" because you already run your application if you like to run your application through this batch file you will remove notepad.exe and add Full path for your application instead .

and then increase in line 3 sleep time as you like remember 1000 mean 1 sec

in line 6 (%%F)S mean send key Alt+F to open File tab menu then Send key S to choose Save from this menu

in line 11 %%{F4} mean send key Alt+F4 to close the application