Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign VBS Script to a Keyboard Shortcut

I have a very basic VBS script that I plan on using frequently on my Windows 7 machine. Is there any way I can bind it to a keyboard shortcut so I don't have to navigate to it through Explorer obnoxiously.

I realize this question does not directly pertain to programming, or even scripting for that matter, but I could not find a straight answer online or through my own experimentation. I'm sure that there is a simple solution somewhere...

Thank you for taking the time to read, and hopefully respond to my inquiry. Evin Ugur.

like image 325
deadboy Avatar asked Nov 14 '12 01:11

deadboy


People also ask

How do I create a shortcut in VBScript?

Create shortcuts on desktop with Visual Basic ScriptInsert VBScript lines by Copy Paste into Notepad and save them as create-shortcut. vbs , then douple-click to execute the VBScript will create the shortcut on desktop. Last but not least, enjoy to edit the Const lines in the script to use any other applications.

How do I assign hotkeys for my keyboard?

To reassign a keyConnect the keyboard that you want to configure. Select the Start button, and then select Microsoft Mouse and Keyboard Center. From the displayed list of key names, select the key that you want to reassign. In the command list of the key that you want to reassign, select a command.

What is the keyboard shortcut to run a script?

Go to the Shortcut tab, click inside the 'Shortcut key' field, and record the keyboard shortcut that you want to use to run the app. You only need to enter a letter or number. The Ctrl+Alt keys are added by default and will be part of all keyboard shortcuts for running apps/shortcuts to apps. That should do the trick.


1 Answers

Windows does have built-in support for shell shortcut keys, where a keypress is used to invoke an *.lnk file that launches your VBScript (using either cscript or wscript).

Create a shortcut file, have it invoke your VBScript file directly or run cscript or wscript with the appropriate arguments, then save it and open its Properties sheet and set a keystroke in the "Shortcut key" field (I suggest something like Ctrl+Alt+K).

Like so:

Screenshot of Windows' shortcut properties window

Then, whenever you press Ctrl+Alt+K, regardless of the active application, your script will be invoked.

A more heavy-duty alternative is AutoHotKey: http://www.autohotkey.com/

like image 104
Dai Avatar answered Oct 13 '22 12:10

Dai