How to i make a .bat that targets a program and types in a text box

本秂侑毒 提交于 2019-12-02 11:52:17

This is not possible using a batch file alone. There are two main ways to get input to another program in the system (in this case, java.exe):

  1. Get your program to listen for a special signal. There are several administrative plugins for Minecraft which will run in the Java process and will do what you need.
  2. Spoof user input to the program. In the case of a console app, you would probably use a SendKeys() based solution. See How to send input to the console as if the user is typing for some examples.

In the case of Minecraft, I think the first solution is going to be significantly easier, because the modding community has already supplied a number of solutions to this exact problem. @Frxstrem recommended mcrcon, which I suppose is as good a solution as any.

Most probably the console client you are using is scriptable and this is not good aproach.

Any way here's a sendKeys.bat. You can use it like:

call sendKeys.bat "Minecraft console title" "stop{enter}"

Batch files can't do this without calling out to something else; if you're going to call to something else, use AutoHotkey - that's what it's good at.

WinActivate "the title of the Minecraft server window"

https://www.autohotkey.com/docs/commands/WinActivate.htm

Send stop{Enter}

https://www.autohotkey.com/docs/commands/Send.htm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!