Esempio n. 1
0
import pyautogui
import keyboard
import pydirectinput
import time
from ahk import AHK

ahk = AHK()
win = ahk.find_window(title=b'Grand Theft Auto V')
win.activate()
win.maximize()
time.sleep(0.5)
while keyboard.is_pressed("Esc") == False:
    time.sleep(3)
    pydirectinput.press("w")
    pydirectinput.press("enter")
    print("Всё ok")
    time.sleep(0.01)
Esempio n. 2
0
class TestWindow(TestCase):
    def setUp(self):
        self.ahk = AHK()
        self.p = subprocess.Popen('notepad')
        time.sleep(1)
        self.win = self.ahk.win_get(title='Untitled - Notepad')
        self.assertIsNotNone(self.win)

    def test_transparent(self):
        self.assertEqual(self.win.transparent, 255)

        self.win.transparent = 220
        self.assertEqual(self.win.transparent, 220)

        self.win.transparent = 255
        self.assertEqual(self.win.transparent, 255)

    def test_pinned(self):
        self.assertFalse(self.win.always_on_top)

        self.win.always_on_top = True
        self.assertTrue(self.win.always_on_top)

        self.win.always_on_top = False
        self.assertFalse(self.win.always_on_top)

    def test_close(self):
        self.win.close()
        self.assertFalse(self.win.exist)

    def test_show_hide(self):
        self.win.hide()
        time.sleep(0.5)
        self.assertFalse(self.win.exist)

        self.win.show()
        time.sleep(0.5)
        self.assertTrue(self.win.exist)

    def test_kill(self):
        self.win.kill()
        time.sleep(0.5)
        self.assertFalse(self.win.exist)

    def test_max_min(self):
        self.assertTrue(self.win.non_max_non_min)

        self.win.maximize()
        time.sleep(0.5)
        self.assertTrue(self.win.maximized)

        self.win.minimize()
        time.sleep(0.5)
        self.assertTrue(self.win.minimized)

        self.win.restore()
        time.sleep(0.5)
        self.assertTrue(self.win.maximized)

    def test_names(self):
        self.assertEqual(self.win.class_name, b'Notepad')
        self.assertEqual(self.win.title, b'Untitled - Notepad')
        self.assertEqual(self.win.text, b'')

    def test_height_change(self):
        current_height = self.win.height
        self.win.height = current_height + 100
        assert self.win.height == current_height + 100

    def test_width_change(self):
        current_width = self.win.width
        self.win.width = current_width + 100
        assert self.win.width == current_width + 100

    def test_rect_setter(self):
        """
        get rect ;-)
        """
        x, y, width, height = self.win.rect
        self.win.rect = (x + 10, y + 10, width + 10, height + 10)
        assert self.win.rect == (x + 10, y + 10, width + 10, height + 10)

    def test_title_change(self):
        self.win.title = 'foo'
        assert self.win.title == b'foo'

    def tearDown(self):
        self.p.terminate()

    def test_find_window(self):
        win = self.ahk.find_window(title=b'Untitled - Notepad')
        assert win.id == self.win.id

    def test_find_window_nonexistent_is_none(self):
        win = self.ahk.find_window(title=b'This should not exist')
        assert win is None

    def test_winget_nonexistent_window_is_none(self):
        win = self.ahk.win_get(title='This should not exist')
        assert win is None

    def test_winwait_nonexistent_raises_timeout_error(self):
        with pytest.raises(TimeoutError):
            win = self.ahk.win_wait(title='This should not exist')

    def test_winwait_existing_window(self):
        win = self.ahk.win_wait(title='Untitled - Notepad')
        assert win.id == self.win.id
Esempio n. 3
0
class EliteActions:
    def __init__(self):
        self.ahk = AHK(
            executable_path=
            "C:\\Users\\ericd\\Downloads\\AutoHotkey_1.1.33.08\\AutoHotkeyU64.exe"
        )

    def prepare(self):
        win = self.ahk.find_window(title=b'Elite - Dangerous (CLIENT)')
        win.activate()

    def quit_to_menu(self):
        self.prepare()
        self.ahk.key_press('escape')
        time.sleep(1)
        self.ahk.key_press('up')
        time.sleep(1)
        self.ahk.key_press('enter')
        time.sleep(15)
        self.ahk.key_press('enter')
        time.sleep(10)

    def enter_solo_mode(self):
        self.prepare()
        self.ahk.key_press('enter')
        time.sleep(1)
        self.ahk.key_press('right')
        time.sleep(1)
        self.ahk.key_press('right')
        time.sleep(1)
        self.ahk.key_press('enter')
        time.sleep(20)

    def deploy_hardpoints(self):
        self.prepare()
        self.ahk.key_press('u')
        time.sleep(1)

    def launch_fighter(self):
        self.prepare()
        # Open fighter menu
        self.ahk.key_press('3')
        time.sleep(1.5)

        # Reset selection and hover over fighter
        # self.ahk.key_press('q') # tab left
        # time.sleep(1)
        # self.ahk.key_press('e') # tab right
        # time.sleep(1)
        # self.ahk.key_press('s') # move down
        # time.sleep(1)

        # Select fighter to launch
        self.ahk.key_press('space')
        time.sleep(1.5)
        self.ahk.key_press('space')
        time.sleep(1.5)
        self.ahk.key_press('space')
        time.sleep(5)
        self.ahk.key_press('escape')
        time.sleep(1)

        self.set_fighter_engage_at_will()

    def set_fighter_engage_at_will(self):
        self.prepare()
        # Set to engage at will
        self.ahk.key_press('Numpad2')
        time.sleep(1)

    def reload_solo_game(self):
        self.quit_to_menu()
        self.enter_solo_mode()
        self.deploy_hardpoints()
        self.set_fighter_engage_at_will()