Help with code

Get help with using AutoHotkey and its commands and hotkeys
Jess Und
Posts: 1
Joined: 16 Jul 2020, 15:36

Help with code

16 Jul 2020, 16:09

I am a newbe with autohotkey. I have some experience programming in Basic, but have no experience here. What I need help with is: I have a keyboard that has several extra keys on it, that I would like to use to launch various programs.
I determined the VK and SC codes of the keys in question by opening a running AHK script and opening the "Key history and script info". Below is a test script that I created that would show that I could indeed RUN some desired programs instead of using the MsgBox. When I pressed the keys in question it would indeed run the desired MsgBox. However could not determine how to exit the script after runinng one of the desired. The VK of each of the keys in question was "FF", the scan codes (SC) is shown below. I thought maybe the test VK for not being "FF" that it woul exit. Any help would be appreciated. Jess U. Mail: (jesseund @ gmail.com).

Code: Select all

if vk<>FF
return
if SC=11F ;1
SC11F:: 
	MsgBox, MidiHost key was pressed.
if SC=116 ;2
SC116:: 
	MsgBox,Cakewalk key was pressed.
if SC=139 ;3
SC139:: 
	MsgBox,Soundfont key was pressed.
if SC=114 ;4
SC114:: 
	MsgBox,Virtual Synth key was pressed.
if SC=126 ;6
SC126:: 
	MsgBox,VLC key was pressed.
if SC=11E ;8
SC11E:: 
	MsgBox,Audacity key was pressed.
return
Last edited by joedf on 17 Jul 2020, 08:54, edited 1 time in total.
Reason: code tags
User avatar
SyntaxTerror
Posts: 24
Joined: 23 May 2017, 12:55

Re: Help with code

16 Jul 2020, 16:55

Hello Jess Und

"ExitApp" terminates the script unconditionally.

But you don't need to exit the script, it will continue to run in the background, waiting for new keys to be pressed.
Small scripts like yours use only a tiny part of your computer memory/processor.

By the way, you don't need all these "If"s in your code:

Code: Select all

SC11F:: MsgBox, MidiHost key was pressed.
is enough.

If you really want to exit the script after a hotkey is pressed, just write

Code: Select all

SC11F::
MsgBox, MidiHost key was pressed.
ExitApp
return
So the first time you press MidiHost, it'll display the message, but not the second time.

Also, don't put your email address like this, it can be retrieved by bots that will send you spam email.

Good luck

Return to “Ask For Help”

Who is online

Users browsing this forum: ader5429, Albireo, boiler, btonasse, Visioneer, Xtra and 36 guests