Is there a way to use sendkeys (or something equivalent) from (not to) the command prompt?
Asked
Active
Viewed 5.0k times
3 Answers
12
Here is a one line solution: This line will type "Testing 123" and then hit Enter.
echo >script.vbs set shell = CreateObject("WScript.Shell"):shell.SendKeys "Testing 123{ENTER}" & script.vbs

Michael Haephrati
- 3,660
- 1
- 33
- 56
11
You can use vbscript. For example, this script will mute the speakers.
set shell = CreateObject("WScript.Shell")
shell.run"Sndvol"
WScript.Sleep 1500
shell.SendKeys"{TAB}"
shell.SendKeys" "
shell.SendKeys"%{F4}"
You launch it from the console with
cscript mute.vbs

sideshowbarker
- 81,827
- 26
- 193
- 197

RealHowTo
- 34,977
- 11
- 70
- 85
-
I'm using : `Dim WshShell: Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.SendKeys WScript.Arguments(0)` – Eugene Mar 15 '12 at 18:21
1
Without creating temporary files. The 'loop' was shown only so that you could open a notebook for output. Remove it after.
@echo off
:loop
::------------begin main code------------
set command=new ActiveXObject('WScript.Shell').SendKeys('WoW{ENTER}{ENTER}');
for /f "delims=" %%i in ('mshta "javascript:%command%close(new ActiveXObject('Scripting.FileSystemObject'));"') do set "var=%%i"
::-------------end main code-------------
timeout /t 1 /nobreak >nul
goto :loop

Garric
- 591
- 3
- 10