Appendix

Python Equivalents of AutoHotkey Keywords

This section lists the relevant AHK keywords (Commands, Function, Directives, and Variables) and their Python counterparts.

AHK Keyword

Python Implementation

#If

ahkpy.HotkeyContext

#IfWinActive

ahkpy.windows.filter().active_window_context().hotkey()

#IfWinExist

ahkpy.Window.filter().window_context().hotkey()

#Include

The import statement

1, 2, 3, etc

sys.argv

A_AhkPath

ahk.executable

A_AppData

os.getenv("APPDATA")

A_AppDataCommon

os.getenv("ALLUSERSPROFILE")

A_ComputerName

os.getenv("COMPUTERNAME")

A_DD

datetime.datetime.now().day

A_DDD

datetime.datetime.now().strftime("%a")

A_DDDD

datetime.datetime.now().strftime("%A")

A_DefaultMouseSpeed

ahkpy.Settings.mouse_speed

A_Hour

datetime.datetime.now().hour

A_IconFile

ahkpy.TrayMenu.tray_icon_file

A_IconHidden

ahkpy.TrayMenu.is_tray_icon_visible

A_IconNumber

ahkpy.TrayMenu.tray_icon_number

A_Is64bitOS

platform.architecture()

A_MDay

datetime.datetime.now().day

A_Min

datetime.datetime.now().minute

A_MM

datetime.datetime.now().month

A_MMM

datetime.datetime.now().strftime("%b")

A_MMMM

datetime.datetime.now().strftime("%B")

A_Mon

datetime.datetime.now().month

A_MouseDelay

ahkpy.Settings.mouse_delay

A_MouseDelayPlay

ahkpy.Settings.mouse_delay_play

A_MSec

datetime.datetime.now().microsecond / 1000

A_Now

datetime.datetime.now()

A_NowUTC

datetime.datetime.utcnow()

A_OSVersion

platform.win32_ver()

A_ProgramFiles

os.getenv("PROGRAMFILES")

A_PtrSize

struct.calcsize("P") * 8

A_ScriptDir

os.path.dirname(__file__) or pathlib.Path(__file__).parent

A_ScriptFullPath

ahkpy.script_full_path

A_ScriptHwnd

ahkpy.all_windows.first(pid=os.getpid)

A_ScriptName

__file__

A_Sec

datetime.datetime.now().second

A_Space

" "

A_Tab

"\t"

A_Temp

os.getenv("TEMP")

A_TickCount

time.perf_counter()

A_TitleMatchMode

ahkpy.Windows.title_mode

A_UserName

os.getenv("USERNAME")

A_WDay

(datetime.datetime.now().weekday() + 2) % 7

A_WinDir

os.getenv("WINDIR")

A_WorkingDir

os.getcwd()

A_YDay

datetime.datetime.now().strftime("%j").lstrip("0")

A_Year

datetime.datetime.now().year

A_YWeek

datetime.datetime.now().strftime("%Y%U")

A_YYYY

datetime.datetime.now().year

Abs()

abs()

ACos()

math.acos()

Asc()

ord()

ASin()

math.asin()

ATan()

math.atan()

BlockInput

ahkpy.block_input(), ahkpy.block_input_while_sending(), ahkpy.block_mouse_move() context managers

Ceil()

math.ceil()

Chr()

chr()

Click

ahkpy.click(), also right_click(), double_click(), mouse_press(), mouse_release(), mouse_scroll(), mouse_move()

Clipboard

ahkpy.get_clipboard() and ahkpy.set_clipboard()

ClipWait

ahkpy.wait_clipboard()

ComSpec

os.getenv("COMSPEC")

Control, Check

ahkpy.Control.check(), also try setting ahkpy.Control.is_checked property

Control, Choose

ahkpy.Control.choose_item_index()

Control, ChooseString

ahkpy.Control.choose_item()

Control, Disable

ahkpy.Control.disable(), also try setting ahkpy.Control.is_enabled property

Control, EditPaste

ahkpy.Control.paste()

Control, Enable

ahkpy.Control.enable(), also try setting ahkpy.Control.is_enabled property

Control, ExStyle

ahkpy.Control.ex_style

Control, Hide

ahkpy.Control.hide(), also try setting ahkpy.Control.is_visible property

Control, Show

ahkpy.Control.show(), also try setting ahkpy.Control.is_visible property

Control, Style

ahkpy.Control.style

Control, Uncheck

ahkpy.Control.uncheck(), also try setting ahkpy.Control.is_checked property

ControlFocus

ahkpy.Control.focus()

ControlGet, Checked

ahkpy.Control.is_checked

ControlGet, Choice

ahkpy.Control.list_choice, also ahkpy.Control.list_choice_index

ControlGet, CurrentCol

ahkpy.Control.current_column

ControlGet, CurrentLine

ahkpy.Control.current_line_number

ControlGet, Enabled

ahkpy.Control.is_enabled

ControlGet, ExStyle

ahkpy.Control.ex_style

ControlGet, FindString

ahkpy.Control.list_item_index()

ControlGet, Hwnd

ahkpy.Control.id

ControlGet, Line

ahkpy.Control.get_line()

ControlGet, LineCount

ahkpy.Control.line_count

ControlGet, List

ahkpy.Control.list_items, also see ahkpy.Control.selected_list_items, ahkpy.Control.focused_list_item, ahkpy.Control.get_list_items(), ahkpy.Control.list_item_count, ahkpy.Control.selected_list_item_count, ahkpy.Control.focused_list_item_index, ahkpy.Control.list_view_column_count

ControlGet, Selected

ahkpy.Control.selected_text()

ControlGet, Style

ahkpy.Control.style

ControlGet, Visible

ahkpy.Control.is_visible

ControlGetFocus

ahkpy.Window.get_focused_control()

ControlGetPos

ahkpy.Control.rect, also position, size, x, y, width, height properties

ControlGetText

ahkpy.Control.text

ControlMove

Window.get_control(class_name).rect = ..., also try setting ahkpy.Control’s x, y, width, height properties

ControlSend

ahkpy.window.BaseWindow.send()

ControlSendRaw

ahkpy.Window.get_control(class_name).send("{Raw}...")

ControlSetText

ahkpy.Control.text

Cos()

math.cos()

DetectHiddenText

ahkpy.Windows.exclude_hidden_text()

DetectHiddenWindows

ahkpy.all_windows

DllCall()

ctypes

EnvGet

os.environ or os.getenv()

EnvSet

os.environ or os.putenv()

ExitApp

sys.exit()

Exp()

math.exp()

FileAppend

open().write()

FileCopy

glob.glob() with shutil.copy() or shutil.copytree()

FileCopyDir

glob.glob() with shutil.copy() or shutil.copytree()

FileCreateDir

os.mkdir() or os.makedirs()

FileDelete

os.remove()

FileEncoding

open(encoding="...")

FileGetSize

os.path.getsize()

FileGetTime

os.path.getatime(), os.path.getmtime(), or os.path.getctime()

FileMove

shutil.move()

FileMoveDir

shutil.move()

FileOpen()

open()

FileRead

open().read()

FileReadLine

open().readline()

FileRemoveDir

shutil.rmtree()

FileSetTime

Can set atime and mtime with os.utime(), cannot set ctime

Floor()

math.floor()

Format()

f-strings or str.format()

FormatTime

format() or datetime.datetime.strftime()

GetKeyName()

ahkpy.get_key_name()

GetKeySC()

ahkpy.get_key_sc()

GetKeyState

ahkpy.is_key_pressed() or ahkpy.is_key_pressed_logical()

GetKeyState()

ahkpy.is_key_pressed() or ahkpy.is_key_pressed_logical(), ahkpy.get_caps_lock_state(), ahkpy.get_num_lock_state(), ahkpy.get_scroll_lock_state(), ahkpy.get_insert_state()

GetKeyVK()

ahkpy.get_key_vk()

GroupClose

ahkpy.Windows.close_all()

Hotkey

ahkpy.hotkey()

Hotstring()

ahkpy.hotstring()

IfMsgBox

if ahkpy.message_box(...) == "...": ...

IniDelete

configparser module

IniRead

configparser module

IniWrite

configparser module

InStr()

"..." in str or str.find()

KeyWait

ahkpy.wait_key_pressed() or ahkpy.wait_key_released()

Ln()

math.log()

Log()

math.log10()

Loop

The for statement

Loop, Files

os.scandir() or os.listdir()

Loop, Read

open().read()

Loop, Reg

winreg module

LTrim()

str.lstrip()

Mod()

The % (modulo) operator

Menu, $, Add

ahkpy.Menu.add()

Menu, $, Insert

ahkpy.Menu.insert()

Menu, $, Delete

ahkpy.Menu.delete_item(), ahkpy.Menu.delete_menu()

Menu, $, DeleteAll

ahkpy.Menu.delete_all_items()

Menu, $, Rename

ahkpy.Menu.rename()

Menu, $, Check

ahkpy.Menu.check()

Menu, $, Uncheck

ahkpy.Menu.uncheck()

Menu, $, ToggleCheck

ahkpy.Menu.toggle_checked()

Menu, $, Enable

ahkpy.Menu.enable()

Menu, $, Disable

ahkpy.Menu.disable()

Menu, $, ToggleEnable

ahkpy.Menu.toggle_enabled()

Menu, $, Default

ahkpy.Menu.set_default()

Menu, $, NoDefault

ahkpy.Menu.remove_default()

Menu, $, Icon

ahkpy.Menu.set_icon()

Menu, $, NoIcon

ahkpy.Menu.remove_icon()

Menu, $, Show

ahkpy.Menu.show()

Menu, $, Color

ahkpy.Menu.set_color()

Menu, Tray, Icon

ahkpy.TrayMenu.set_tray_icon(), ahkpy.TrayMenu.toggle_tray_icon(), ahkpy.TrayMenu.show_tray_icon()

Menu, Tray, NoIcon

ahkpy.TrayMenu.hide_tray_icon()

Menu, Tray, Tip

ahkpy.TrayMenu.tip

Menu, Tray, Click

ahkpy.TrayMenu.set_clicks()

MouseClick

ahkpy.click(), also right_click(), double_click(), mouse_press(), mouse_release(), mouse_scroll(), mouse_move()

MouseClickDrag

Use ahkpy.mouse_press(), ahkpy.mouse_move(), and ahkpy.mouse_release()

MouseGetPos

ahkpy.get_mouse_pos(), get_window_under_mouse(), get_control_under_mouse()

MouseMove

ahkpy.mouse_move()

NumGet()

struct.unpack()

NumPut()

struct.pack()

OnClipboardChange

ahkpy.on_clipboard_change()

OnMessage()

ahkpy.on_message()

OutputDebug

ahkpy.output_debug()

PostMessage

ahkpy.window.BaseWindow.post_message()

Process

psutil package

ProgramFiles

os.getenv("PROGRAMFILES")

Random

random module

RegDelete

winreg module

RegExMatch()

re.search()

RegExReplace()

re.sub()

RegisterCallback()

ctypes.CFUNCTYPE()

RegRead

winreg module

RegWrite

winreg module

Reload

ahkpy.restart()

Round()

round()

RTrim()

str.rstrip()

Run

subprocess.Popen

RunWait

subprocess.run()

Send

ahkpy.send()

SendEvent

ahkpy.send_event()

SendInput

ahkpy.send_input()

SendLevel

Set the level argument in ahkpy.send() or via ahkpy.Settings.send_level

SendMessage

ahkpy.window.BaseWindow.send_message()

SendMode

Set the mode argument in ahkpy.send() or via ahkpy.Settings.send_mode

SendPlay

ahkpy.send_play()

SetCapslockState

ahkpy.set_caps_lock_state()

SetControlDelay

ahkpy.Settings.control_delay

SetDefaultMouseSpeed

Set the speed argument in ahkpy.mouse_move() or via ahkpy.Settings.mouse_speed

SetKeyDelay

ahkpy.Settings.key_delay

SetMouseDelay

Set the delay argument in ahkpy.click() or via ahkpy.Settings.mouse_delay and ahkpy.Settings.mouse_delay_play

SetNumLockState

ahkpy.set_num_lock_state()

SetScrollLockState

ahkpy.set_scroll_lock_state()

SetTimer

ahkpy.set_timer()

SetTitleMatchMode

Set the match argument in ahkpy.Windows.filter()

SetWinDelay

ahkpy.Settings.win_delay

SetWorkingDir

os.chdir()

Sin()

math.sin()

Sleep

ahkpy.sleep()

Sort

sorted() or list.sort()

SplitPath

os.path.basename(), os.path.dirname(), os.path.splitext(), os.path.splitdrive()

Sqrt()

math.sqrt()

StatusBarGetText

ahkpy.Window.get_status_bar_text()

StatusBarWait

ahkpy.Window.wait_status_bar()

StrGet()

bytes.decode() or struct module

StringGetPos

"..." in str or str.find()

StringLeft

str[:count]

StringLen

len(str)

StringLower

str.lower()

StringMid

str[left:left+count]

StringReplace

str.replace()

StringRight

str[-count:]

StringSplit()

str.split()

StringTrimLeft

str[count:]

StringTrimRight

str[:-count]

StringUpper

str.upper()

StrLen()

len()

StrPut()

str.encode() or struct module

StrSplit()

str.split()

SubStr()

str[start:start+len]

Suspend

ahkpy.suspend(), ahkpy.resume(), ahkpy.toggle_suspend()

Tan()

math.tan()

ToolTip

ahkpy.ToolTip

Transform

html.escape()

Trim()

str.strip()

UrlDownloadToFile

urllib.request.urlopen() or requests package

WinActivate

ahkpy.Window.activate()

WinActivateBottom

ahkpy.Windows.last().activate()

WinActive()

ahkpy.Windows.get_active()

WinClose

ahkpy.Window.close()

WinExist()

ahkpy.Windows.first()

WinGet, ControlList

ahkpy.Window.control_classes

WinGet, ControlListHwnd

ahkpy.Window.controls

WinGet, Count

len(ahkpy.windows.filter())

WinGet, ExStyle

ahkpy.Window.ex_style

WinGet, ID

ahkpy.Window.id

WinGet, IDLast

ahkpy.windows.last().id

WinGet, List

list(ahkpy.windows.filter())

WinGet, MinMax

ahkpy.Window.is_minimized, ahkpy.Window.is_maximized, ahkpy.Window.is_restored

WinGet, PID

ahkpy.Window.pid

WinGet, ProcessName

ahkpy.Window.process_name

WinGet, ProcessPath

ahkpy.Window.process_path

WinGet, Style

ahkpy.Window.style

WinGet, TransColor

ahkpy.Window.transparent_color

WinGet, Transparent

ahkpy.Window.opacity

WinGetClass

ahkpy.Window.class_name

WinGetPos

ahkpy.Window.rect, also position, size, x, y, width, height properties

WinGetText

ahkpy.Window.text

WinGetTitle

ahkpy.Window.title

WinHide

ahkpy.Window.hide()

WinKill

ahkpy.Window.kill()

WinMaximize

ahkpy.Window.maximize()

WinMinimize

ahkpy.Window.minimize()

WinMinimizeAll

ahkpy.Windows.minimize_all()

WinMove

ahkpy.Window.move()

WinRestore

ahkpy.Window.restore()

WinSetTitle

ahkpy.Window.title

WinShow

ahkpy.Window.show()

WinWait

ahkpy.Windows.wait()

WinWaitActive

ahkpy.Windows.wait_active()

WinWaitClose

ahkpy.Windows.wait_close()

WinWaitNotActive

ahkpy.Window.wait_inactive()