Как через командную строку нажать любую клавишу
Перейти к содержимому

Как через командную строку нажать любую клавишу

  • автор:

Батник, имитирующий нажатие клавиши клавиатуры?

Нужен батник, который будет нажимать клавишу клавиатуры, и запускать софт. Действия вообще не связаны между собой никак, просто надо, что бы я это всё запускал через один файл. Если с запуском программы всё понятно — обычный батник

То с нажатием клавиши не понятно вообще ничего. Как её имитировать? Пытался гуглить, но там всё программисты друг у друга спрашивают, готового кода нет, и мне, простому пчелу ничего не понятно, я даже так и не понял, возможно ли это вообще сделать.

В общем, подскажите пожалуйста, что вписать в тот батник, на примере любой клавиши.

Press Keyboard keys using a batch file [closed]

I am trying to develop a batch file which can automatically press left arrow and right arrow key for n number of times with some pause in between. Could anybody please help me with this?

P.S: I tried installing auto keyboard software but I couldn’t install them since I was at work. I need this program to work on my office PC.

2 Answers 2

Wow! Mean this that you must learn a different programming language just to send two keys to the keyboard? There are simpler ways for you to achieve the same thing. 🙂


The Batch file below is an example that start another program (cmd.exe in this case), send a command to it and then send an Up Arrow key, that cause to recover the last executed command. The Batch file is simple enough to be understand with no problems, so you may modify it to fit your needs.

Aacini's user avatar

F0" ; the first one is clearer. For further information about JScript, see this site.

Just to be clear, you are wanting to launch a program from a batch file and then have the batch file press keys (in your example, the arrow keys) within that launched program?

If that is the case, you aren’t going to be able to do that with simply a «.bat» file as the launched would stop the batch file from continuing until it terminated—

My first recommendation would be to use something like AutoHotkey or AutoIt if possible, simply because they both have active forums where you’d find countless examples of people launching applications and sending key presses not to mention tools to simply «record» what you want to do. However you said this is a work computer and you may not be able to load a 3rd party program.. but you aren’t without options.

You can use Windows Scripting Host from something like a .vbs file to launch a program and send keys to that process. If you’re running a version of Windows that includes PowerShell 2.0 (Windows XP with Service Pack 3, Windows Vista with Service Pack 1, Windows 7, etc.) you can use Windows Scripting Host as a COM object from your PS script or use VB’s Intereact class.

The specifics of how to do it are outside the scope of this answer but you can find numerous examples using the methods I just described by searching on SO or Google.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *