Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a batch file to run a hotkey

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?

like image 303
g Void Avatar asked Apr 03 '14 11:04

g Void


People also ask

How do I run a shortcut in a batch file?

Right-click the desktop and select New > Shortcut. Choose a location, ideally the same as your batch file, and click Next. Then enter a name for the shortcut and click Finish. Now right-click your new shortcut file, select Properties, and update the Target field to point to your batch file.

Can batch files press keys?

Introduction. In Windows operating system, any program can run through a batch program. Also, it is very hard to press any key through a batch program. But it is possible indirectly by a batch program using VBScript.

How do I run hotkeys?

The quickest way to access the Run command window is to use this keyboard shortcut: Windows + R. Simply hold down the Windows key and press R on your keyboard.


2 Answers

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.

like image 99
bgmCoder Avatar answered Sep 16 '22 16:09

bgmCoder


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

like image 23
zdd Avatar answered Sep 18 '22 16:09

zdd