Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top