コード例 #1
0
ファイル: test_screen.py プロジェクト: spyoungtech/ahk
class TestScreen(TestCase):
    def setUp(self):
        """
        Record all open windows
        :return:
        """
        self.ahk = AHK()
        self.before_windows = self.ahk.windows()
        im = Image.new('RGB', (20, 20))
        for coord in product(range(20), range(20)):
            im.putpixel(coord, (255, 0, 0))
        self.im = im
        im.show()
        time.sleep(2)

    def tearDown(self):
        for win in self.ahk.windows():
            if win not in self.before_windows:
                win.close()
                break

    def test_pixel_search(self):
        result = self.ahk.pixel_search(0xFF0000)
        self.assertIsNotNone(result)

    def test_image_search(self):
        self.im.save('testimage.png')
        position = self.ahk.image_search('testimage.png')
        self.assertIsNotNone(position)

    def test_pixel_get_color(self):
        x, y = self.ahk.pixel_search(0xFF0000)
        result = self.ahk.pixel_get_color(x, y)
        self.assertIsNotNone(result)
        self.assertEqual(int(result, 16), 0xFF0000)
コード例 #2
0
class WindowInteraction:
    """ low level key pressing interface with xflr windows """

    def __init__(self, app_load_time : int = 2):
        self.ahk = AHK(executable_path = r'ahk\AutoHotkeyU64.exe')
        self.ahk.run_script('Run, xflr/xflr5.exe')
        time.sleep(app_load_time)
        self.win = self.ahk.find_window(title=b'xflr')

    """
    Public methods
    """

    def reset_window(self):
        self.win = self.ahk.find_window(title=b'xflr')
    

    def field_selector(self, index : int, window = None):
        logging.info(f"selecting index: {index}")
        wing_edit = self.ahk.find_window_by_title(b'Wing Edition - xflr5 v6.47')
        if window == None:
            window = self.win
        for _ in range(index):
            time.sleep(0.01)
            #wing_edit.send("{Tab}")
            self.press(r'{Tab}', wing_edit)


    def get_window(self, title : str):
        return self.ahk.find_window_by_title(title)
    

    def list_windows(self):
        return [window.title for window in self.ahk.windows()]
    

    def ctrl_press(self, key : str):
        self.press(f"^{key}")


    def press(self, key : str, window = None):
        
        self.list_windows()

        if window == None:
            window = self.win
        window.activate()
        logging.info(key)
        window.send(f"{key}")
    

    def check_window_exists(self, name : str):
        return True if name in [window.title for window in self.ahk.windows()] else False
コード例 #3
0
class WindowInteraction:
    """ low level key pressing interface with xflr windows """
    def __init__(self, app_load_time: int = 2):
        self.ahk = AHK(
            executable_path=
            r'C:\Users\olive\Documents\GitHub\pyxfl\ahk\AutoHotkeyU64.exe')
        self.ahk.run_script('Run, xflr/xflr5.exe')
        time.sleep(app_load_time)
        self.win = self.ahk.find_window(title=b'xflr')

    def field_selector(self, index: int):
        self.win.activate()
        for _ in range(index):
            self.win.send("{Tab}")

    def get_window(self, title: str):
        return self.ahk.find_window(title=title)

    def ctrl_press(self, key: str):
        self.win.activate()
        self.win.send(f"^{key}")

    def press(self, key: str):
        self.win.activate()
        self.win.send(f"{key}")

    def check_window_exists(self, name: str):
        return True if name in [window.title
                                for window in self.ahk.windows()] else False
コード例 #4
0
ファイル: test_keyboard.py プロジェクト: More2Chi/ahk
class TestKeyboard(TestCase):
    def setUp(self):
        """
        Record all open windows
        :return:
        """
        self.ahk = AHK()
        self.before_windows = self.ahk.windows()
        self.p = subprocess.Popen("notepad")
        time.sleep(1)
        self.notepad = self.ahk.find_window(title=b"Untitled - Notepad")

    def tearDown(self):
        self.p.terminate()
        time.sleep(0.2)

    def test_window_send(self):
        self.notepad.send("hello world")
        time.sleep(1)
        self.assertIn(b"hello world", self.notepad.text)

    def test_send(self):
        self.notepad.activate()
        self.ahk.send("hello world")
        assert b"hello world" in self.notepad.text

    def test_send_key_mult(self):
        self.notepad.send(KEYS.TAB * 4)
        time.sleep(0.5)
        self.assertEqual(self.notepad.text.count(b"\t"), 4, self.notepad.text)

    def test_send_input(self):
        self.notepad.activate()
        self.ahk.send_input("Hello World")
        assert b"Hello World" in self.notepad.text

    def test_type(self):
        self.notepad.activate()
        self.ahk.type("Hello, World!")
        assert b"Hello, World!" in self.notepad.text

    def test_type_escapes_equals(self):
        """
        https://github.com/spyoungtech/ahk/issues/96
        """
        self.notepad.activate()
        self.ahk.type("=foo")
        assert b"=foo" in self.notepad.text

    def test_sendraw_equals(self):
        """
        https://github.com/spyoungtech/ahk/issues/96
        """
        self.notepad.activate()
        self.ahk.send_raw("=foo")
        assert b"=foo" in self.notepad.text

    def test_set_capslock_state(self):
        self.ahk.set_capslock_state("on")
        assert self.ahk.key_state("CapsLock", "T")
コード例 #5
0
ファイル: test_keyboard.py プロジェクト: wanqiuchansheng/ahk
class TestKeyboard(TestCase):
    def setUp(self):
        """
        Record all open windows
        :return:
        """
        self.ahk = AHK()
        self.before_windows = self.ahk.windows()
        self.p = subprocess.Popen('notepad')
        time.sleep(1)
        self.notepad = self.ahk.find_window(title=b'Untitled - Notepad')

    def tearDown(self):
        self.p.terminate()
        time.sleep(0.2)

    def test_window_send(self):
        self.notepad.send('hello world')
        time.sleep(1)
        self.assertIn(b'hello world', self.notepad.text)

    def test_send(self):
        self.notepad.activate()
        self.ahk.send('hello world')
        assert b'hello world' in self.notepad.text

    def test_send_key_mult(self):
        self.notepad.send(KEYS.TAB * 4)
        time.sleep(0.5)
        self.assertEqual(self.notepad.text.count(b'\t'), 4, self.notepad.text)

    def test_send_input(self):
        self.notepad.activate()
        self.ahk.send_input('Hello World')
        assert b'Hello World' in self.notepad.text

    def test_type(self):
        self.notepad.activate()
        self.ahk.type('Hello, World!')
        assert b'Hello, World!' in self.notepad.text

    def test_type_escapes_equals(self):
        '''
        https://github.com/spyoungtech/ahk/issues/96
        '''
        self.notepad.activate()
        self.ahk.type('=foo')
        assert b'=foo' in self.notepad.text

    def test_sendraw_equals(self):
        '''
        https://github.com/spyoungtech/ahk/issues/96
        '''
        self.notepad.activate()
        self.ahk.send_raw('=foo')
        assert b'=foo' in self.notepad.text
コード例 #6
0
import pyautogui
from ahk import AHK
import time

ahk = AHK()

print(f"Active window: {ahk.active_window}")
print(f"Position: {ahk.active_window.rect}")
print(f"Title: {ahk.active_window.title}")
print(f"Windows: {ahk.windows()}")
# ahk.active_window.title = "Bashash"
# time.sleep(0.5)
# ahk.active_window.hide()
# time.sleep(0.5)
# ahk.active_window.show()
for w in ahk.windows():
    if b"bash" in w.title:
        w.restore()
ahk.mouse_move(
    x=100, y=100,
    blocking=True)  # Blocks until mouse finishes moving (the default)
ahk.mouse_move(
    x=150, y=150, speed=1,
    blocking=True)  # Moves the mouse to x, y taking 'speed' seconds to move
print(ahk.mouse_position)  #  (150, 150)
コード例 #7
0
ファイル: test_keyboard.py プロジェクト: spyoungtech/ahk
class TestKeyboard(TestCase):
    def setUp(self):
        """
        Record all open windows
        :return:
        """
        self.ahk = AHK()
        self.before_windows = self.ahk.windows()
        self.p = subprocess.Popen('notepad')
        time.sleep(1)
        self.notepad = self.ahk.find_window(title=b'Untitled - Notepad')

    def tearDown(self):
        self.p.terminate()
        time.sleep(0.2)

    def test_window_send(self):
        self.notepad.send('hello world')
        time.sleep(1)
        self.assertIn(b'hello world', self.notepad.text)

    @pytest.mark.flaky(reruns=5)
    def test_window_send_raw(self):
        self.notepad.send('{Tab 4}', raw=True, delay=10, press_duration=10)
        time.sleep(0.5)
        assert b'{Tab 4}' in self.notepad.text

    def test_send(self):
        self.notepad.activate()
        self.ahk.send('hello world')
        assert b'hello world' in self.notepad.text

    def test_send_key_mult(self):
        self.notepad.send(KEYS.TAB * 4)
        time.sleep(0.5)
        self.assertEqual(self.notepad.text.count(b'\t'), 4, self.notepad.text)

    def test_send_input(self):
        self.notepad.activate()
        self.ahk.send_input('Hello World')
        time.sleep(0.5)
        assert b'Hello World' in self.notepad.text

    def test_type(self):
        self.notepad.activate()
        self.ahk.type('Hello, World!')
        assert b'Hello, World!' in self.notepad.text

    def test_type_escapes_equals(self):
        """
        https://github.com/spyoungtech/ahk/issues/96
        """
        self.notepad.activate()
        self.ahk.type('=foo')
        assert b'=foo' in self.notepad.text

    def test_sendraw_equals(self):
        """
        https://github.com/spyoungtech/ahk/issues/96
        """
        self.notepad.activate()
        self.ahk.send_raw('=foo')
        assert b'=foo' in self.notepad.text

    def test_set_capslock_state(self):
        self.ahk.set_capslock_state('on')
        assert self.ahk.key_state('CapsLock', 'T')