Skip to content

Commit

Permalink
Merge bec7fc8 into 6a5be1a
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Dec 18, 2018
2 parents 6a5be1a + bec7fc8 commit 2377740
Show file tree
Hide file tree
Showing 16 changed files with 329 additions and 72 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,57 @@ You should see an output something like
0.873 (100, 100)
```

## Windows

You can do stuff with windows, too.


Getting windows

```python
from ahk import AHK
from ahk.window import Window
ahk = AHK()
win = ahk.active_window # get the active window
win = ahk.win_get(title='Untitled - Notepad') # by title
win = list(ahk.windows()) # list of all windows
win = Window(ahk, ahk_id='0xabc123') # by ahk_id
win = Window.from_mouse_position(ahk) # a window under the mouse cursor
win = Window.from_pid('20366') # by process ID


```

Working with windows
```python
win.move(x=200, y=300, width=500, height=800)
win.activate() # give the window focus
win.disable() # make the window non-interactable
win.enable() # enable it again
win.to_top() # moves window on top of other windows
win.to_bottom()
win.always_on_top = True # make the windows always on top
win.close()

for window in ahk.windows():
print(window.title)
# some more attributes
print(window.text)
print(window.rect) # (x, y, width, height)
print(window.id) # ahk_id
print(window.pid)
print(window.process)
```

## Debugging

You can enable debug logging, which will output script text before execution, and some other potentially useful
debugging information.

```python
import logging
logging.basicConfig(level=logging.DEBUG)
```

## Non-Python Dependencies

Expand Down
2 changes: 1 addition & 1 deletion ahk/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _run_script(self, script_text, **kwargs):
decode = kwargs.pop('decode', False)
script_bytes = bytes(script_text, 'utf-8')
if blocking:
result = subprocess.run(runargs, input=script_bytes, stderr=subprocess.PIPE, stdout=subprocess.PIPE, **kwargs, check=True)
result = subprocess.run(runargs, input=script_bytes, stderr=subprocess.PIPE, stdout=subprocess.PIPE, **kwargs)
if decode:
logger.debug('Stdout: %s', repr(result.stdout))
logger.debug('Stderr: %s', repr(result.stderr))
Expand Down
1 change: 1 addition & 0 deletions ahk/templates/base.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% block directives %}
#NoEnv
{% for directive in directives %}
{{ directive }}
{% endfor %}
Expand Down
5 changes: 5 additions & 0 deletions ahk/templates/window/from_mouse.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "base.ahk" %}
{% block body %}
MouseGetPos,,, MouseWin
FileAppend, %MouseWin%, *
{% endblock body %}
5 changes: 5 additions & 0 deletions ahk/templates/window/get.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "base.ahk" %}
{% block body %}
WinGet, output, {{ subcommand }}, {{ title }}, {{ text }}, {{ exclude_title }}, {{ exclude_text }}
FileAppend, %output%, *
{% endblock body %}
10 changes: 10 additions & 0 deletions ahk/templates/window/id_list.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.ahk" %}
{% block body %}
WinGet windows, List
Loop %windows%
{
id := windows%A_Index%
r .= id . "`n"
}
FileAppend, %r%, *
{% endblock body %}
4 changes: 4 additions & 0 deletions ahk/templates/window/win_activate.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "base.ahk" %}
{% block body %}
WinActivate, ahk_id {{ win.id }}
{% endblock body %}
4 changes: 4 additions & 0 deletions ahk/templates/window/win_close.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "base.ahk" %}
{% block body %}
WinClose, ahk_id {{ win.id }}, {{seconds_to_wait}}
{% endblock body %}
Empty file.
5 changes: 5 additions & 0 deletions ahk/templates/window/win_get_text.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "base.ahk" %}
{% block body %}
WinGetText, text, ahk_id {{ win.id }}
FileAppend, %text%, *
{% endblock body %}
5 changes: 5 additions & 0 deletions ahk/templates/window/win_get_title.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "base.ahk" %}
{% block body %}
WinGetTitle, title, ahk_id {{ win.id }}
FileAppend, %title%, *
{% endblock body %}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends "base.ahk" %}
{% block body %}
WinGet, ExStyle, ExStyle, {{win._title}}, {{win._text}}, {{win._exclude_title}}, {{win._exclude_text}}
WinGet, ExStyle, ExStyle, ahk_id {{ win.id }}
if (ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST.
FileAppend, 1, *
else
FileAppend, 0, *
{% endblock body %}
{% endblock body %}
4 changes: 4 additions & 0 deletions ahk/templates/window/win_move.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "base.ahk" %}
{% block body %}
WinMove, ahk_id {{ win.id }}, , {{ x }}, {{ y }}{% if width %}, {{ width }}{% endif %}{% if height %}, {{ height }}{% endif %}
{% endblock body %}
2 changes: 1 addition & 1 deletion ahk/templates/window/win_position.ahk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.ahk" %}
{% block body %}
WinGetPos, x, y, width, height, {{win.title}}, {{win.text}}, {{win._exclude_title}}, {{win._exclude_text}}
WinGetPos, x, y, width, height, ahk_id {{ win.id }}
s .= Format("({}, {}, {}, {})", x, y, width, height)
FileAppend, %s%, *
{% endblock body %}
2 changes: 1 addition & 1 deletion ahk/templates/window/win_set.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.ahk" %}
{% block body %}
WinSet, {{subcommand}}, {{value}}, {{win.title}}, {{win.text}}, {{win._exclude_title}}, win._exclude_text}}
WinSet, {{subcommand}}, {{value}}, ahk_id {{ win.id }}
{% endblock body %}
Loading

0 comments on commit 2377740

Please sign in to comment.