# AutoHotkey_L New Features

This document describes features added in the AutoHotkey_L branch of AutoHotkey development, now simply known as "AutoHotkey 1.1".

Caution: This document has been neglected in recent years and may be missing some of the more recent changes.

## Control Flow

Break LoopLabel | Break out of a loop or any number of nested loops.
Continue LoopLabel | Continue a loop, even from within any number of nested loops.
For x,y in z | Loop through the contents of an object.
Loop Until | Loop until a condition is true. Applicable to any type of Loop.
Try...Catch...Finally | Provides structured exception handling.
Throw | Throws an exception.

## Commands

FileEncoding | Sets the default encoding for FileRead, FileReadLine, Loop Read, FileAppend, and FileOpen(). See also: Text Encodings
Gui | See GUI Enhancements below.
IniRead/Write/Delete | Read, write or delete entire sections, or retrieve a list of all section names.
Menu, Icon | Sets or removes a menu item's icon.
Run | Improvements were made to the way parameters are parsed.
SendInput {U+nnnn} | Sends a Unicode character. Unicode characters may be used directly in Unicode builds.
SendLevel | Controls which artificial keyboard and mouse events are ignored by hotkeys and hotstrings.
SetFormat, IntegerFast, h|H | Set lower-case or upper-case hexadecimal format.
SetRegView, RegView | Allows registry commands in a 32-bit script to access the 64-bit registry view and vice versa.
Transform, HTML | Perform code page or HTML transformations.
WinGet, ..., ProcessPath | Retrieves the full path and name of the process that owns a given window.

## Directives

#If expression | Similar to #IfWinActive, but for arbitrary expressions.
#IfTimeout | Sets the maximum time that may be spent evaluating a single #If expression.
#MenuMaskKey | Changes which key is used to mask `Win` or `Alt` keyup events.
#Include <Lib> | Includes a script file from a function library folder.
#InputLevel | Controls which artificial keyboard and mouse events are ignored by hotkeys and hotstrings.
#Warn | Enables or disables warnings for selected conditions that may be indicative of developer errors.

## Functions

ComObj... -- ComObjActive ComObjEnwrap/Unwrap ComObjParameter ComObjType | Retrieves a registered COM object. Wraps/unwraps a COM object. Wraps a value and type to pass as a parameter. Retrieves a COM object's type information.
ComObjArray | Creates a SAFEARRAY for use with COM.
ComObjConnect | Connects a COM object's event sources to functions with a given prefix.
ComObjCreate | Creates a COM object.
ComObjError | Enables or disables notification of COM errors.
ComObjFlags | Retrieves or changes flags which control a COM wrapper object's behaviour.
ComObjGet | Returns a reference to an object provided by a COM component.
ComObjQuery | Queries a COM object for an interface or service.
ComObjType | Retrieves type information from a COM object.
ComObjValue | Retrieves the value or pointer stored in a COM wrapper object.
Exception | Creates an exception object for Throw (also provides limited access to the call stack).
FileOpen | Provides object-oriented file I/O.
Func | Retrieves a reference to a function.
GetKeyName/VK/SC | Retrieves the name or text, virtual key code or scan code of a key.
InStr | Searches for a given occurrence of a string, from the left or the right.
IsByRef | Determines whether a ByRef parameter was supplied with a variable.
IsObject | Determines whether a value is an object.
StrPut / StrGet | Copies a string to or from a memory address, optional converting it between code pages.
Trim | Trims certain characters from the beginning and/or end of a string.
RegEx (?CNum:Func) | Calls a function during evaluation of a regex pattern.
Function Libraries | New "local library" and `#Include <LibName>`.
Variadic Functions | Functions may accept a variable number of parameters via an array.
Static Initializers | Static variables can now be initialized using any expression.

## Objects

General | Behaviour and usage of objects in general.
Object | Associative arrays which can be extended with other functionality.
Enumerator | Allows items in a collection to be enumerated.
File | Provides an interface to access a file. FileOpen() returns an object of this type.
Func | Represents a user-defined or built-in function which can be called by the script.
ComObject | See ComObj functions above.

## Variables

A_Is64bitOS | Contains 1 (true) if the OS is 64-bit or 0 (false) if it is 32-bit.
A_IsUnicode | In Unicode builds, this variable contains 1 (true). In ANSI builds it is not defined, so is effectively false.
A_FileEncoding | Contains the default encoding for various commands; see FileEncoding.
A_OSVersion | Supports Windows 7 and Windows 8; see A_OSVersion.
A_PriorKey | The name of the last key which was pressed prior to the most recent key-press or key-release ... (More)
A_PtrSize | Contains the size of a pointer, in bytes. This is either 4 (32-bit) or 8 (64-bit).
A_RegView | The current registry view as set by SetRegView.
A_ScriptHwnd | The unique ID (HWND/handle) of the script's hidden main window.

## Datatypes

Ptr | Equivalent to Int in 32-bit builds and Int64 in 64-bit builds. Supported by DllCall(), NumPut() and NumGet().
AStr, WStr | Supported only by DllCall(); see Script Compatibility.

## Unicode

Compatibility | How to deal with Unicode in DllCall(), etc.
Script Files | Using Unicode in script files.
SendInput | Using Unicode with SendInput.

## Other

ahk_exe | Windows can be identified by the name or path of the process (EXE file) which owns them.
Debugging | Interactive debugging features (line by line execution etc.).
Error Handling | Try/catch/throw and increased usefulness for A_LastError.
GUI Enhancements | Various enhancements to the Gui command and related.
Icon Support | Resource identifiers and improved support for various icon sizes.
Other Changes | Changes affecting script compatibility.
Version History | History of AutoHotkey_L revisions.

## Error Handling

Many commands support using try/catch instead of ErrorLevel for error handling. For example:

    try
    {
        FileCopy, file1.txt, C:\folder
        FileDelete, C:\folder\old.txt
    }
    catch
        MsgBox An error occured!

Additionally, the following commands now set A_LastError to assist with debugging: FileAppend, FileRead, FileReadLine, FileDelete, FileCopy, FileMove, FileGetAttrib/Time/Size/Version, FileSetAttrib/Time, FileCreateDir, RegRead, RegWrite, RegDelete.

## Function Libraries

In addition to the user library in `%A_MyDocuments%\AutoHotkey\Lib` and standard library in the AutoHotkey directory, functions may be auto-included from the "local library" which resides in `%A_ScriptDir%\Lib`. For more information, see Libraries of Functions.

#Include <LibName> explicitly includes a library file which may be located in any one of the function libraries.

## GUI Enhancements

A number of enhancements have been made to the Gui command and related:

- A name or HWND can be used instead of a number between 1 and 99 when referring to a GUI.
- Gui, New creates a new anonymous GUI.
- Any number of named or anonymous GUIs can be created.
- New GUI options: +HwndOutputVar, +ParentGUI
- A GUI's owner can be any arbitrary window: +Owner%HWND%.
- Gui, Font can control anti-aliasing of text.
- ActiveX controls such as the Internet Explorer WebBrowser control are supported.
- GuiControlGet, OutputVar, Name gets the name of the variable associated with a GUI control.
- Keyboard accelerators such as `Ctrl`+`O` are supported automatically when used in Gui menus.
- Font quality can be controlled by the Font sub-command.

## Static Variables

Static variables can now be initialized using any expression. For example:

    Sleep 500
    MsgBox % Time() "ms since the script started."
    Time() {
        static Tick := A_TickCount
        return A_TickCount - Tick
    }

## Text Encodings

FileRead, FileReadLine, Loop Read and FileAppend support the majority of Windows-supported text encodings, not just the system default ANSI code page. FileEncoding can be used to set the default encoding, which can be overridden for FileRead and FileAppend as follows:

    FileRead, OutputVar, *Pnnn Filename
    FileAppend , Text, Filename, Encoding

While nnn must be a numeric code page identifier, Encoding follows the same format as FileEncoding.

See also: Script Compatibility

## Variadic Functions and Function-Calls

Variadic functions can receive a variable number of parameters via an array, while variadic function-calls can be used to pass a variable number of parameters to a function.

## Improvements to Icon Support

### Unusual Sizes

Icon resources of any size supported by the operating system may be extracted from executable files. When multiple sized icon resources exist within an icon group, the most appropriate size is used. Prior to revision 17, an arbitrary icon resource was selected by the system, scaled to the system large icon size, then scaled back to the requested size.

### Resource Identifiers

Negative icon numbers may be used to identify a group icon resource within an executable file. For example, the following sets the tray icon to the default icon used by ahk files:

    Menu, Tray, Icon, %A_AhkPath%, -160