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?
-
2All I found was how to run shortcuts!– g VoidApr 3, 2014 at 12:10
-
21) If you did research (successful or not), provide what you have tried in your question. 2) Your is question very unclear to me. You tagged [autohotkey], but you didn't mention it once. What role does AHK play here? Do you want to run an AHK script which sends keys? Do you want a batch file to send keys? Should AHK start the batch file or vice versa? Or do you want to create a hotkey that starts the batch file?What are you trying to achieve in general? You're giving too little info about your whole problem. Please spend more effort explaining it.– MCLApr 3, 2014 at 12:39
-
2MCL has said it right. You must "get into the spirit" of Stack Exchange. Once you do, the site will become very valuable to you!– bgmCoderApr 3, 2014 at 13:47
4 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.
-
3+1 the only answer that was "loyal" to the "AutoHotkey-tagged" question.– Joe DFApr 4, 2014 at 5:47
-
@bgmCoder, I tried your syntax, but it seems that: 1. I cannot run more than one
*.ahk
scripts through your syntax? (In the command prompt window that gets started, it shall keep displaying the first line that goes in the*.bat
file; 2. the command window keeps hanging around no matter what.– llinfengOct 25, 2017 at 20:49 -
Well, if you want to run more than one autohotkey script, you have to put more than one call in the batch file. Also, in your batch file, you might have to add an
exit
there, too. I think the batch file will not end until the autohotkey script is complete. However, there are utilities that will let your batch files be compiled into invisible exe files. Maybe that can get rid of the black box. I don't really understand why you need a batch file to run an ahk script though. Why not just put the ahk file in your startup and forget about the batch file?– bgmCoderOct 26, 2017 at 2:03
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.
-
That was exactly what I wanted, thank you! I'm sorry for my condensed version of a problem listed above. Live and learn :)– g VoidApr 3, 2014 at 12:59
-
@gVoid If you improve your question, I'll upvote it. If you leave it as it is I'm going to vote it down because it is a poor question in its current state.– bgmCoderApr 3, 2014 at 14:41
-
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
-
very elegant, thanks! Beats the VB script solution by not having to set up a second script file.– AlbinDec 5, 2018 at 19:13
-
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.