Page 1 of 1

Hold down ALT, press few keys, release the ALT key. Script completes an action. How do I do this?

Posted: 26 Jul 2016, 11:16
by AverageBrick
Basically I want a script that will allow me to open programs. How? I want to press and hold down ALT key, while holding ALT I would enter 1, 2, 1 and then release the ALT key. That's it

Simplified:

{Alt down}
{1}
{2}
{1}
{Alt up}
*script opens a program (for example: "C:\Dropbox\text.txt")*

Re: Hold down ALT, press few keys, release the ALT key. Script completes an action. How do I do this?

Posted: 26 Jul 2016, 14:18
by megnatar
This is explained at the very beginning of the help file. It's actually the first topic. You should read it for it will be you're guide in understanding AHK and programing in general.
Read topic Basic Usage and Syntax -> Hotkeys.

The most basic way to do what you want is:

Code: Select all

#NoEnv
#Persistent

!1::Run "C:\WINDOWS\hh.exe" C:\Program Files\AutoHotkey\AutoHotkey.chm
!2::Run Iexplore.exe
!3::Run cmd /k Ipconfig /all
!4::Run explorer shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{00000000-0000-0000-0000-123456749822}
!5::Send {Rwin down}{d down}{Rwin up}{d up}
!6::ExitApp
or

Code: Select all

#NoEnv
#Persistent
SetWorkingDir %A_ScriptDir%


LAlt::
Keywait, 1, D			;Wait forever for key 1 to be pressed down.
If errorlevel = 0		;Errorlevel is set to zero the moment key 1 is down.
Keywait, 2, D
If errorlevel = 0
Keywait, LAlt			;Wait forever for the alt key to be released.
If errorlevel = 0		;On release errorlevel = 0
FileAppend, Many ways to achieve the same goals`, Consult the help file!, %A_ScriptDir%\SomeFile.txt
Run Notepad  %A_ScriptDir%\SomeFile.txt
exitapp
ps: code is not tested