Source code for ahk.screen

import ast
from ahk.script import ScriptEngine, AsyncScriptEngine
from typing import Tuple, Union, Optional


[docs]class ScreenMixin(ScriptEngine): def _image_search( self, image_path: str, upper_bound: Tuple[int, int] = (0, 0), lower_bound: Tuple[int, int] = None, color_variation: int = None, coord_mode: str = 'Screen', scale_height: int = None, scale_width: int = None, transparent: str = None, icon: int = None, ) -> str: if scale_height and not scale_width: scale_width = -1 elif scale_width and not scale_height: scale_height = -1 options = [] if icon: options.append(f'Icon{icon}') if color_variation: options.append(color_variation) if transparent: options.append(f'Trans{transparent}') if scale_width: options.append(f'w{scale_width}') options.append(f'h{scale_height}') 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, options=options, ) return script def _pixel_get_color( self, x: int, y: int, coord_mode: str = 'Screen', alt: bool = False, slow: bool = 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) return script
[docs] def pixel_get_color(self, *args, **kwargs): """ `AutoHotkey PixelGetColor reference`_ .. _AutoHotkey PixelGetColor reference: https://autohotkey.com/docs/commands/PixelGetColor.htm :param x: x coordinate :param y: y coordinate :param coord_mode: :param alt: :param slow: :param rgb: returns :return: the color as an RGB hexidecimal string; """ script = self._pixel_get_color(*args, **kwargs) return self.run_script(script)
def _pixel_search( self, color: Union[str, int], variation: int = 0, upper_bound: Tuple[int, int] = (0, 0), lower_bound: Tuple[int, int] = None, coord_mode: str = 'Screen', fast: bool = True, rgb: bool = True, ) -> str: 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, ) return script
[docs]class AsyncScreenMixin(AsyncScriptEngine, ScreenMixin):