Skip to content

Commit

Permalink
initial screen work
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Dec 27, 2018
1 parent 49c6111 commit abaa760
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ahk/autohotkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from ahk.mouse import MouseMixin
from ahk.window import Window, WindowMixin
from ahk.script import ScriptEngine
from ahk.screen import ScreenMixin

class AHK(WindowMixin, MouseMixin):
class AHK(WindowMixin, MouseMixin, ScreenMixin):
pass


Expand Down
61 changes: 61 additions & 0 deletions ahk/screen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import ast

from ahk.script import ScriptEngine


class ScreenMixin(ScriptEngine):
def image_search(self, image_path, upper_bound=(0, 0), lower_bound=None,
coord_mode='Screen', scale_height=None, scale_width=None):
x1, y1 = upper_bound
if lower_bound:
x2, y2 = lower_bound
else:
x2, y2 = ('%A_ScreenWidth%', '%A_ScreenHeight%')
script = self.render_template('screen/image_search.ahk',
x1=x1, x2=x2, y1=y1, y2=y2,
coord_mode=coord_mode,
image_path=image_path)
resp = self.run_script(script)
try:
return ast.literal_eval(resp)
except SyntaxError:
return None

def pixel_get_color(self, x, y, coord_mode='Screen', alt=False, slow=False, rgb=True):
options = []
if slow:
options.append('Slow')
elif alt:
options.append('Alt')
if rgb:
options.append('RGB')
script = self.render_template('screen/pixel_get_color.ahk',
x=x, y=y,
coord_mode=coord_mode,
options=options)
resp = self.run_script(script)
return resp

def pixel_search(self, color, variation=0, upper_bound=(0, 0), lower_bound=None, coord_mode='Screen', fast=False, rgb=True):
options = []
if fast:
options.append('Fast')
if rgb:
options.append('RGB')
x1, y1 = upper_bound
if lower_bound:
x2, y2 = lower_bound
else:
x2, y2 = ('%A_ScreenWidth%', '%A_ScreenHeight%')

script = self.render_template('screen/pixel_search.ahk',
x1=x1, y1=y1, x2=x2, y2=y2,
coord_mode=coord_mode,
color=color,
variation=variation,
options=options)
resp = self.run_script(script)
try:
return ast.literal_eval(resp)
except SyntaxError:
return None
7 changes: 7 additions & 0 deletions ahk/templates/screen/image_search.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.ahk" %}
{% block body %}
CoordMode Pixel, {{ coord_mode }}
ImageSearch, xpos, ypos, {{ x1 }}, {{ y1 }}, {{ x2 }}, {{ y2 }}, {{ image_path }}
s .= Format("({}, {})", xpos, ypos)
FileAppend, %s%, *
{% endblock body %}
7 changes: 7 additions & 0 deletions ahk/templates/screen/pixel_get_color.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.ahk" %}
{% block body %}
CoordMode Pixel, {{ coord_mode }}
PixelGetColor, color, {{ x }}, {{ y }}{% if options %},{% for option in options %} {{ option }}{% endfor %}{% endif %}

FileAppend, %color%, *
{% endblock body %}
8 changes: 8 additions & 0 deletions ahk/templates/screen/pixel_search.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.ahk" %}
{% block body %}
CoordMode Pixel, {{ coord_mode }}
PixelSearch, xpos, ypos, {{ x1 }}, {{ y1 }}, {{ x2 }}, {{ y2 }}, {{ color }} , {{ variation }}{% if options %},{% for option in options %} {{ option }}{% endfor %}{% endif %}

s .= Format("({}, {})", xpos, ypos)
FileAppend, %s%, *
{% endblock body %}

0 comments on commit abaa760

Please sign in to comment.