@@ -4,7 +4,7 @@ Quickstart
4
4
.. module :: ahkpy
5
5
:noindex:
6
6
7
- This page assumes you already have AutoHotkey.py installed . If you do not , head
7
+ This page assumes you've already installed AutoHotkey.py. If you haven't , head
8
8
over to the :doc: `/install ` section. If you need a refresher on Python, check
9
9
out `The Python Tutorial <https://docs.python.org/3/tutorial/index.html >`_.
10
10
@@ -18,14 +18,15 @@ When invoking AutoHotkey.py, you may specify any of these options:
18
18
19
19
ahkpy [-h] [-V] [-q] [--no-tray] [-c CMD | -m MOD | FILE | -] [args]
20
20
21
- The most common use case is , of course, a simple invocation of a script:
21
+ The most common use case, of course, simply invokes a script:
22
22
23
23
.. code-block :: text
24
24
25
25
ahkpy myscript.py
26
26
27
- The REPL interface works best when invoked through the ``python `` executable,
28
- because it enables the arrow keys to traverse the command history.
27
+ The REPL interface works best when you invoke it with the ``python ``
28
+ executable, which allows you to explore your command history with the up and
29
+ down arrow keys.
29
30
30
31
.. code-block :: text
31
32
@@ -37,30 +38,31 @@ To start AutoHotkey.py without the terminal window, use *pyw*:
37
38
38
39
pyw -m ahkpy myscript.py
39
40
40
- The AutoHotkey.py interface resembles that of the Python interpreter. For more
41
- information on the interface options refer to `Python documentation
41
+ The AutoHotkey.py interface resembles that of the Python interpreter. To learn
42
+ more about your interface options, refer to the `Python documentation
42
43
<https://docs.python.org/3/using/cmdline.html#interface-options> `_.
43
44
44
45
The following CLI options are specific to AutoHotkey.py:
45
46
46
47
.. cmdoption :: -q
47
48
48
- Suppress message boxes with errors. If this option is not specified ,
49
- AutoHotkey.py will show unhandled Python errors in message boxes.
49
+ Suppress message boxes with errors. If you don't specify this option ,
50
+ AutoHotkey.py shows unhandled Python errors in message boxes.
50
51
51
52
.. cmdoption :: --no-tray
52
53
53
54
Don't show the AutoHotkey icon in the system tray.
54
55
55
- When started, AutoHotkey.py searches for the AutoHotkey executable in the
56
+ Once started, AutoHotkey.py searches for the AutoHotkey executable in the
56
57
following sequence:
57
58
58
- 1. Check the ``AUTOHOTKEY `` environment variable. If the variable is set,
59
- treat it as the AutoHotkey executable path.
60
- 2. Find the program associated with the ``*.ahk `` files. If the program name
61
- starts with ``autohotkey `` (case-insensitive), treat it as the AutoHotkey
62
- executable path.
63
- 3. Use the default ``C:\Program Files\AutoHotkey\AutoHotkey.exe `` path.
59
+ 1. First, checks whether the ``AUTOHOTKEY `` environment variable is set. If it
60
+ is, AutoHotkey.py uses the environment variable as the AutoHotkey executable
61
+ path.
62
+ 2. If not, checks the Windows Registry to find whether a program's set to run
63
+ when a user opens an AHK file.
64
+ 3. Otherwise, defaults to the path
65
+ ``C:\Program Files\AutoHotkey\AutoHotkey.exe ``.
64
66
65
67
.. note ::
66
68
@@ -74,10 +76,10 @@ following sequence:
74
76
Hotkeys
75
77
-------
76
78
77
- Hotkeys in AutoHotkey.py are registered with the :func: `hotkey ` function. In the
79
+ The :func: `hotkey ` function registers HotKeys . In the
78
80
following example, the hotkey :kbd: `Win ` + :kbd: `N ` is configured to launch
79
- Notepad. The pound sign ``# `` stands for the :kbd: `Win ` key, which is known as a
80
- modifier ::
81
+ Notepad. The pound sign ``# `` stands for the :kbd: `Win ` key, one of the hotkey
82
+ modifiers ::
81
83
82
84
import subprocess
83
85
import ahkpy
@@ -91,19 +93,20 @@ If you want to bind an existing function to a hotkey, pass it as an argument to
91
93
92
94
ahkpy.hotkey("#n", subprocess.Popen, ["notepad"])
93
95
94
- In the example above, the :class: `subprocess.Popen ` object will be created with
95
- the ``["notepad"] `` argument when the user presses :kbd: `Win ` + :kbd: `N `.
96
+ In the preceding example, when a user presses :kbd: `Win ` + :kbd: `N `,
97
+ they create a :class: `subprocess.Popen ` object with the argument
98
+ ``["notepad"] ``.
96
99
97
100
To disable a key or a combination of keys for the entire system, use the
98
101
``lambda: None `` function. For example, this disables the right-side :kbd: `Win `
99
102
key::
100
103
101
104
ahkpy.hotkey("RWin", lambda: None)
102
105
103
- The methods :meth: ` Windows.active_window_context `,
104
- :meth: ` Windows.window_context `, and the :class: ` HotkeyContext ` class can be used
105
- to make a hotkey perform a different action (or none at all) depending on a
106
- specific condition . For example::
106
+ If you want to specify certain conditions when a hotkey performs a different
107
+ action (or no action at all), you can use the methods
108
+ :meth: ` Windows.active_window_context ` and :meth: ` Windows.window_context `,
109
+ or the class :class: ` HotkeyContext ` . For example::
107
110
108
111
notepad_ctx = ahkpy.windows.active_window_context(class_name="Notepad")
109
112
notepad_ctx.hotkey(
@@ -172,16 +175,17 @@ Window Management
172
175
-----------------
173
176
174
177
AutoHotkey.py provides the :class: `Windows ` class and its default instances:
175
- :data: `windows ` and :data: `all_windows `. The :class: `Windows ` class is the
176
- interface to query open windows by multiple criteria , like title and window
177
- class . To query the windows, set the criteria with the :meth: ` ~Windows.filter `
178
- method. For example, this prepares a query of all windows with a class named
179
- ``ConsoleWindowClass ``::
178
+ :data: `windows ` and :data: `all_windows `. With the :class: `Windows ` class
179
+ interface, you can query windows through multiple search parameters , like
180
+ `` title `` and `` window `` . To query the windows, set the criteria with the
181
+ :meth: ` ~Windows.filter ` method. For example, this prepares a query of all
182
+ windows of the class ``ConsoleWindowClass ``::
180
183
181
184
>>> console_windows = ahkpy.windows.filter(class_name="ConsoleWindowClass")
182
185
183
- The :meth: `~Windows.filter ` call doesn't retrieve any windows by itself, it
184
- instructs the subsequent operation::
186
+ The only role of the :meth: `~Windows.filter ` method is to pack the
187
+ query parameters. Once you've filtered the object you want, you can perform
188
+ a real operation, like get the count of matching windows::
185
189
186
190
>>> console_windows
187
191
Windows(class_name='ConsoleWindowClass', hidden_windows=False, hidden_text=True, title_mode='startswith', text_mode='fast')
@@ -196,10 +200,10 @@ instructs the subsequent operation::
196
200
>>> [win.title for win in console_windows]
197
201
['Command Prompt', 'Windows PowerShell', 'C:\\Windows\\py.exe']
198
202
199
- Specifying multiple criteria in the :meth: `~Windows.filter ` call narrows down
200
- the search to the windows where *all * criteria match. In the following example,
201
- the script waits for a window whose title contains `` My File.txt `` and whose
202
- class is ``Notepad ``::
203
+ Specifying multiple criteria for :meth: `~Windows.filter ` narrows the
204
+ the search down to only the windows where *all * criteria match. In the
205
+ following example, the script waits for a window whose title contains
206
+ `` My File.txt `` and whose class is ``Notepad ``::
203
207
204
208
ahkpy.windows.filter("My File.txt", class_name="Notepad").wait()
205
209
# Filter chaining gives the same result.
@@ -213,7 +217,7 @@ following::
213
217
ahkpy.windows.wait("My File.txt", class_name="Notepad")
214
218
215
219
The :meth: `~Windows.exclude ` method is a companion to :meth: `~Windows.filter `
216
- that excludes the windows from the search::
220
+ that excludes a window from a search::
217
221
218
222
non_cmd_windows = ahkpy.windows.exclude(title="Command Prompt")
219
223
@@ -257,7 +261,7 @@ matching windows, ``Window(None)`` is returned. This object is falsy and returns
257
261
>>> win.class_name is None
258
262
True
259
263
260
- Also, a window that existed at some point in time but was closed acts the same
264
+ Also, if a window existed at some point in time but was closed, it acts the same
261
265
as ``Window(None) ``. Thus, be sure to check property values for ``None `` before
262
266
working with them::
263
267
@@ -395,4 +399,4 @@ Follow the `Python debug configurations in Visual Studio Code
395
399
}
396
400
397
401
Now you can set the breakpoints in Visual Studio Code and inspect the
398
- AutoHotkey.py program as you would do with a regular Python program.
402
+ AutoHotkey.py program, as you would with a regular Python program.
0 commit comments