How to make a batch file to run a hotkey

点点圈 提交于 2019-12-01 02:42:19

问题


Every time I start my Windows I want to execute a hotkey (Ctrl+Alt+1) using a batch file and putting it in startup folder. Is that even possible? Is there a command for that?


回答1:


You can't send keys directly from a batch file, instead you can create a VB script to send the keys and call this script from a .bat file

Put the following code to a VB script, for example sendkeys.vbs (^ is Ctrl and % is Alt)

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^%1"

Put the following code to a batch file, for example sendkeys.bat(required full path of the VB script if they are not in the same folder)

wscript "sendkey.vbs"

Finally, put sendkeys.bat to Windows startup folder.

SendKeys in VB Script




回答2:


The original question was tagged autohotkey.

You can, indeed, use a batch file to run a autohotkey script.

In your batch file, just run autohotkey and send the path to your script as the parameter.

"c:\program files (x86)\autohotkey\autohotkey.exe" "c:\scripts\hotkey.ahk"

And in your autohotkey script, do something like this:

send ^!1
exit

That's it.

Of course, if autohotkey is installed on the computer, you could just put a link to the script in your startup folder in the start menu. That's what I do.




回答3:


The Batch file below do what you want:

@if (@CodeSection == @Batch) @then
@echo off
CScript //nologo //E:JScript "%~F0"
goto :EOF
@end
WScript.CreateObject("WScript.Shell").SendKeys("^%1");

For further details, see this post




回答4:


You can use AutoIt to create a binary that you can launch in a batch file.

It seems like you tagged autohotkey without realising that there is a tool called autohotkey which can probably help you too.



来源:https://stackoverflow.com/questions/22836457/how-to-make-a-batch-file-to-run-a-hotkey

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