Autohotkey

From wikinotes
Revision as of 15:50, 28 September 2019 by Will (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Autohotkey is a scripting language designed primarily for binding custom hotkeys in windows, but can grab/manipulate detailed information from windows' GUI.

NOTE:

python pyautogui almost entirely replicates this library, but is also crossplatform.

Documentation

builtin variables https://www.autohotkey.com/docs/Variables.htm#BuiltIn
list of commands https://www.autohotkey.com/docs/commands.htm


Hotkeys

;; Modifier Keys
;;
#  ||; Windows Key
+  ||; Shift
!  ||; Alt
^  ||; Ctrl
`  ||; Escape Character
;  ||; Comment
/* ||; (multiLine comments must be first )
*/ ||; (characters on the line           )


;; How to bind Keys
;;
#+t::Run, "%HOMEDRIVE%%HOMEPATH%\Documents\program.exe" /?			;; Hotkeys to Run Program

Capslock::LCtrl																	;; Bind Alternate Modifier Key

#p::^u																				;; Bind Key Sequence

#-::																					;; Bind Multiple Keysequences
send,{ctrldown}-{ctrlup}
send,{ctrldown}-{ctrlup}
send,{ctrldown}-{ctrlup}
return


;; Class/Name Specific Hotkeys
;;
#^y::																					;; Get Current Window Class/Title
	WinGetClass,class,A
	WinGetTitle,title,A
	MsgBox, Class: "%class%" 	Title: "%title%"
	Return

#IfWinActive ahk_class IrfanView												;; Hotkeys Specific to a class or name of window
j::Send, {right}
k::Send, {left}
q::Send, {Esc}




Variables

Autohotkey does not have variable types. Math operations are allowed if a variable type consists of only numbers. Variables are also not case sensitive. To expand a variable, surround it in '%' signs.


#### Variable Types
num = 123											;; Numbers  (no int/float types)
str = abcdefg										;; Strings  (no string/char types)
array = winGet List

## Arrays
array = winGet List								;; Autohotkey arrays work similarly to bash,
echo array%1%										;; they are defined by a separator char.
echo array%2%
var=3
echo array%var%

;;how to assign your own arrays? 
Loop %ArrayCount%{								;; Iterate through array
    element := Array%A_Index%  ; A_Index is a built-in variable.
    MsgBox % "Element number " . A_Index . " is " . Array%A_Index%
}


#### Working With Variables
concat = %num% . %str%							;; Concatenate with a '.'

NetPrice := Price * (1 - Discount/100)		;; Save Result of expression to variable



Operators

In autohotkey, operators are named 'Expressions', which have some syntactical implications of their own.

OR			|| or
AND/&&	|| and
,			|| endline ( similar to ';'


var++																;;Increase Variable Value by 1
var+=


if ( num > onum )

Built In Variables

There are several builtin variables for accessing:

  • system information
  • window information
  • date information
  • contents of the clipboard

and much more. I'll fill this in if I find the API difficult to use.

https://www.autohotkey.com/docs/Variables.htm#BuiltIn