예제 #1
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
예제 #2
0
 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')
예제 #3
0
def test_env_var_takes_precedence_over_path():
    check_pwd()
    actual_path = AHK().executable_path
    ahk_location = os.path.abspath(os.path.dirname(actual_path))
    with mock.patch.dict(os.environ, {'PATH': ahk_location, 'AHK_PATH':'C:\\expected\\path\\to\\ahk.exe'}):
        ahk = AHK()
        assert ahk.executable_path == 'C:\\expected\\path\\to\\ahk.exe'
예제 #4
0
def test_executable_from_path():
    check_pwd()
    actual_path = AHK().executable_path
    ahk_location = os.path.abspath(os.path.dirname(actual_path))
    with mock.patch.dict(os.environ, {'PATH': ahk_location}, clear=True):
        ahk = AHK()
        assert ahk.executable_path == actual_path
예제 #5
0
    def __init__(self, setToLoad=None):
        super(SolutionBrowser, self).__init__()

        # parse config
        self.parse_config()

        # overwrite default set if provided
        if setToLoad:
            self.default_set = setToLoad

        # set size mainwindow
        self.setWindowTitle('Solution Browser')
        self.resize(self.hsize, self.vsize)
        if self.isStartMaximized:
            self.setWindowState(Qt.WindowMaximized)
        font = QFont()
        font.setPointSize(10)
        self.setFont(font)

        # icon
        app_icon = QIcon()
        app_icon.addFile(os.path.join('icons', 'icon256.png'), QSize(256, 256))
        app_icon.addFile(os.path.join('icons', 'icon128.png'), QSize(128, 128))
        self.setWindowIcon(app_icon)

        # statusbar
        self.statusbar = self.statusBar()
        self.statusbar_style_alert = "QStatusBar{font-size:10pt;background:rgba(250, 128, 114, 1);color:black;font-weight:bold;}"
        self.statusbar_style_normal = "QStatusBar{font-size:10pt;color:black;font-weight:bold;}"
        self.statusbar.setStyleSheet(self.statusbar_style_normal)
        self.statusbar.showMessage('Starting SolutionBrowser')

        # load layout top and bottom frames
        self.layouts = SolutionBrowserLayout(self)
        self.setCentralWidget(self.layouts)

        self.createActions()
        self.createMenus()

        # create par dialog
        self.parDialogOpen = False
        self.parDialog = ParDialog(self)

        # get frames for easy reference.
        self.ImageViewerFrame = self.layouts.ImageViewerFrame
        self.ParameterFrame = self.layouts.ParameterFrame
        self.ParameterFrame.setFont(font)

        # start image viewer
        self.setup_image_viewer()
        # load default image
        self.open_image('default.jpg')

        # start parameter selection tool
        self.setup_parameter_selector()

        # ahk to communicate with matlab
        if AHK:
            self.ahk = AHK(executable_path=self.ahk_executable_path)
예제 #6
0
    def test_show_tooltip(self, ahk: AHK):
        ahk.show_tooltip("hello")
        ahk.show_tooltip("🚀 Hello unicode 🚀", second=2)
        ahk.show_tooltip("⽲ hello3", x=10, y=10)
        ahk.show_tooltip("hello4", second=2, x=10, y=10)

        with raises(ValueError):
            ahk.show_tooltip("hello", id=30)
예제 #7
0
파일: test_gui.py 프로젝트: spyoungtech/ahk
    def test_show_tooltip(self, ahk: AHK):
        ahk.show_tooltip('hello')
        ahk.show_tooltip('🚀 Hello unicode 🚀', second=2)
        ahk.show_tooltip('⽲ hello3', x=10, y=10)
        ahk.show_tooltip('hello4', second=2, x=10, y=10)

        with raises(ValueError):
            ahk.show_tooltip('hello', id=30)
예제 #8
0
class TestMouse(TestCase):
    def setUp(self) -> None:
        self.ahk = AHK()

    def test_mouse_move(self):
        x, y = self.ahk.mouse_position
        self.ahk.mouse_move(10, 10, relative=True)
        assert self.ahk.mouse_position == (x + 10, y + 10)
예제 #9
0
 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')
예제 #10
0
def test_env_var_takes_precedence_over_path():
    check_pwd()
    actual_path = AHK().executable_path
    ahk_location = os.path.abspath(os.path.dirname(actual_path))
    with mock.patch.dict(os.environ, {
            'PATH': ahk_location,
            'AHK_PATH': sys.executable
    }):
        # using sys.executable as a standin for any file with exe extension
        ahk = AHK()
        assert ahk.executable_path == sys.executable
예제 #11
0
def handler(key):
    ahk = AHK(directives=[NoTrayIcon], executable_path=ahk_path)
    win = ahk.find_window(process=kindle_path)
    try:
        win.activate()
        win.to_top()
        ahk.key_press(key)
    except AttributeError:
        print(
            "Could not find kindle window, make sure kindle application is running and check kindle executable path"
        )
예제 #12
0
    def __init__(self, stream_name: str, json_dict):
        """
            Stream name
        """
        self.decoder = json_dict
        self.stream_title = stream_name

        self.ahk = AHK()
        self.get_OBS()
        self.get_ProPresenter()
        #self.start_hotkeys()
        atexit.register(self.stop_hotkeys)
예제 #13
0
    def __init__(self):
        self.ahk = AHK()
        self.BuffCheck = False  # no check buff
        self.Counter = 0
        self.IsFullScreen = 0
        self.SkillEnable1 = False  # True
        self.SkillEnable2 = False  # True
        self.SkillEnable3 = False  # True
        self.SkillEnable4 = False  # True
        self.PickUpEnable = 1
        self.IsFullScreenX = 0
        self.IsFullScreenY = 0

        self.AnyKeyPress = False
        self.SpacebarChecker = False
        self.CountDownTime = 0
        self.Active = False
        self.Exit = False
        self.wpercent = 100
        self.hpercent = 100

        '''
        keyboard.add_hotkey('spacebar', self.triggeredSpace)
        keyboard.add_hotkey('esc', self.triggeredEsc)
        keyboard.add_hotkey('z', self.triggeredZ)
        '''
        '''
        cv2.namedWindow('SoulSaverOnline_cv')
        cv2.createTrackbar('axis_X', 'SoulSaverOnline_cv', 0, 255,self.nothing)
        cv2.createTrackbar('axis_Y', 'SoulSaverOnline_cv', 0, 255,self.nothing)
        '''
        self.maintask = threading.Thread(target=self.maintask_thread)
        self.maintask.start()  # start new threading
        self.CountUpTime = 0
        while self.Exit is False:
            self.checkKey('space', self.triggeredSpace)
            self.checkKey('esc', self.triggeredEsc)
            self.checkKey('z', self.triggeredZ)
            self.checkKey('up')
            self.checkKey('down')
            self.checkKey('control')
            self.checkKey('left')
            self.checkKey('right')

            if self.AnyKeyPress is True:
                self.CountUpTime = self.CountUpTime + 1
            if self.CountUpTime > 10:  # 0.1sec cooldown
                self.CountUpTime = 0
                self.AnyKeyPress = False
            # print(self.CountUpTime)
            # print(self.Active)
            time.sleep(0.01)  # prevent CPU high processing
예제 #14
0
 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)
예제 #15
0
def resetar():
    for i in re.sub('[^0-9]', '', cortar_e_ocr((1350, 380, 50, 20))):
        busca_por_imagem(i)
    ahk = AHK(executable_path='./ahk_folder/AutoHotkeyA32.exe')
    ahk.mouse_move(x=1149, y=649)
    ahk.click(direction='down')
    time.sleep(0.008)
    ahk.click(direction='up')
예제 #16
0
def api_init():
    global WINDOW

    WINDOW = AHK.find_window(process=config.DF_EXE_P)

    if WINDOW == None:
        raise RuntimeError
예제 #17
0
def uppar():
    ahk = AHK(executable_path='./ahk_folder/AutoHotkeyA32.exe')
    while True:
        if re.sub('[^0-9]', '', cortar_e_ocr((930, 200, 50, 20))) != '600':
            ahk.mouse_move(1828, 791)
            ahk.click(direction='down')
        else:
            ahk.click(direction='up')
            break
예제 #18
0
class Holder:
    def __init__(self, yaml):
        self.ahk = AHK()
        self.options = yaml
        self.delay = self.options['delay']
        self.get_window()

    def get_window(self):
        self.window = self.ahk.find_window(title=b'Minecraft',
                                           process='javaw.exe')
        # print(self.window.title)
        self.crossbow()

    def crossbow(self):
        while True:
            # print('Sending RButton down')
            self.ahk.run_script('ControlClick, , ' +
                                self.window.title.decode() + ', ,Right, , NAD')
            time.sleep(float(self.options['draw_time']))
            # print('Sending RButton up')
            self.ahk.run_script('ControlClick, , ' +
                                self.window.title.decode() + ', ,Right, , NAU')
            time.sleep(0.2)
            # print('Sending RButton')
            self.ahk.run_script('ControlClick, , ' +
                                self.window.title.decode() + ', ,Right, , NA')
            # print(f'Waiting for {self.delay}s')
            time.sleep(float(self.delay))
예제 #19
0
 def set_copy(self, setting):
     if setting is not self.copy:
         self.copy = setting
         if self.copy:
             self.close_ahk()
             set_clip(self.systems[self.route_index])
         else:
             self.ahk = AHK(executable_path=self.hub.get_ahk_path())
             self.reset_ahk()
예제 #20
0
def api_init():
    """Grab both engine and console windows. Thanks to run for this code"""
    global CONSOLE
    global WINDOW

    if environ["DEVELOPMENT"]:
        CONSOLE = AHK.run_script("WinShow," + CONSOLEWINDOW + \
                   "\nControlGet, console, Hwnd ,, Edit1, " + CONSOLEWINDOW + \
                   "\nFileAppend, %console%, * ;", blocking=True)
    else:
        CONSOLE = AHK.run_script("WinShow," + CONSOLEWINDOW + \
                    "\nControlGet, console, Hwnd ,, Edit1, " + CONSOLEWINDOW + \
                    "\nWinHide," + CONSOLEWINDOW + \
                    "\nFileAppend, %console%, * ;", blocking=True)
    WINDOW = AHK.find_window(process=config.DF_EXE_PATH,
                             title=b"TwitchBot Engine")

    if CONSOLE is None or WINDOW is None:
        raise WindowNotFoundError
예제 #21
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
예제 #22
0
class TestKeysAsync(IsolatedAsyncioTestCase):
    def setUp(self):
        self.ahk = AsyncAHK()
        self._normal_ahk = AHK()
        self.thread = None
        self.hotkey = None

    def tearDown(self):
        if self.thread is not None:
            self.thread.join(timeout=3)
        if self._normal_ahk.key_state('a'):
            self._normal_ahk.key_up('a')
        if self._normal_ahk.key_state('Control'):
            self._normal_ahk.key_up('Control')

        notepad = self._normal_ahk.find_window(title=b'Untitled - Notepad')
        if notepad:
            notepad.kill()

        if self.hotkey and self.hotkey.running:
            self.hotkey.stop()

    async def a_key_wait_pressed(self):
        await self.ahk.key_wait('a', timeout=5)

    def test_key_wait_pressed(self):
        start = time.time()
        self.thread = threading.Thread(target=a_down)
        self.thread.start()
        asyncio.run(self.a_key_wait_pressed())
        end = time.time()
        assert end - start < 5

    async def a_key_wait_released(self):
        await self.ahk.key_wait('a', timeout=2)

    def test_key_wait_released(self):
        start = time.time()
        a_down()
        self.thread = threading.Thread(target=release_a)
        self.thread.start()
        asyncio.run(self.a_key_wait_released())
        end = time.time()
        assert end - start < 2

    async def a_key_wait_timeout(self):
        await self.ahk.key_wait('f', timeout=0.1)

    def test_key_wait_timeout(self):
        self.assertRaises(TimeoutError, asyncio.run, self.a_key_wait_timeout())

    async def test_key_state_when_not_pressed(self):
        self.assertFalse(await self.ahk.key_state('a'))

    async def test_key_state_pressed(self):
        await self.ahk.key_down('Control')
        self.assertTrue(await self.ahk.key_state('Control'))
예제 #23
0
def busca_por_imagem(name_img):
    pos = imagesearch(f"./data/{name_img}.JPG")
    img = cv2.imread(f"./data/{name_img}.JPG")
    size = img.shape
    print(size)
    if pos[0] != -1:
        ahk = AHK(executable_path='./ahk_folder/AutoHotkeyA32.exe')
        ahk.mouse_move(x=pos[0] + (size[1] / 2), y=pos[1] + (size[0] / 2))
        ahk.click(direction='down')
        time.sleep(0.008)
        ahk.click(direction='up')
    else:
        busca_por_imagem(name_img)
예제 #24
0
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)
class RBoxTilt:
    def __init__(self, port:str):
        self.ahk = AHK(executable_path=resource_path("AutoHotkeyU64.exe"))
        self.pi = midi_driver.SerialController(port)
        self.__running = False

        with open("tiltconfig.json", "r") as file:
            self.config = json.loads(file.read())
    
    def run_tilt_engine(self):
        printd("STARTING TILT ENGINE")
        while True:
            if not self.__running: break

            button = self.pi.read_button()

            if(button != None):
                printd(f"MOTION TRIGGER: {button}")
                try:
                    key = self.config[button]
                    if(len(key) == 1):
                        printd(f"\t>> SINGLE ACTION {key}")
                        self.ahk.key_press(key[0])
                    else:
                        pyautogui.hotkey(*key)
                        printd(f"\t>> DOUBLE ACTION {key}")
                except:
                    pass

        printd("STOPPING TILT ENGINE")
    
    def start(self):
        self.__running              = True
        self.tiltengine             = threading.Thread(target=self.run_tilt_engine)
        self.tiltengine.daemon      = True
        self.tiltengine.start       ()
    
    def stop(self):
        self.__running      = False
        self.tiltengine     .join()
예제 #26
0
class Controller:
    def __init__(self):
        self.mouse = AHK()

        self.keyboard = None  #KeyboardController()

    def random_walk(self):
        offset_x = 3
        offset_y = 22

        center_x = (1024 + offset_x) / 2
        center_y = (768 + offset_y) / 2

        range = 150
        x = center_x + randint(-range, range)
        y = center_y + randint(-range, range)
        self.mouse.mouse_move(x=x, y=y, speed=3, blocking=True)
        time.sleep(0.5)
        self.mouse.click(x, y)
        time.sleep(0.5)

    def atacar(self, x, y):
        x += 25
        y += 25

        print("About to  attack")

        self.mouse.mouse_position = (x, y)
        time.sleep(0.2)
        self.mouse.click()
        time.sleep(5)

    def skill_F1(self):

        self.mouse.mouse_position = (235, 41)
        time.sleep(0.2)
        self.mouse.click()
        time.sleep(0.2)
        self.mouse.click()
예제 #27
0
class BlobEnv:
    SIZE = 10
    RETURN_IMAGES = True
    MOVE_PENALTY = 1
    ENEMY_PENALTY = 300
    FOOD_REWARD = 25
    OBSERVATION_SPACE_VALUES = (SIZE, SIZE, 3)  # 4
    ACTION_SPACE_SIZE = 4
    PLAYER_N = 1  # player key in dict
    FOOD_N = 2  # food key in dict
    ENEMY_N = 3  # enemy key in dict
    # the dict! (colors)
    d = {1: (255, 175, 0),
         2: (0, 255, 0),
         3: (0, 0, 255)}

    def __init__(self):
        self.ahk = AHK()
        self.location_memory = set()
        self.episode_step = 0

    def reset(self):
        self.episode_step = 0
        self.location_memory = set()
        self.ahk.run_script(open('ahk_scripts/get_state.ahk').read())
        pos_x = open('states/AX.txt').read()
        pos_y = open('states/AY.txt').read()
        observation = (float(pos_x), float(pos_y))
        map = open('states/AMap.txt').read()
        print('Current map id:', map)
        self.location_memory.add(observation)
        self.ahk.run_script(open('ahk_scripts/reset.ahk').read())
        return observation

    def step(self, current_state, action):
        self.episode_step += 1
        self.ahk.run_script(f'action := {action}\n' + open('ahk_scripts/step.ahk').read())
        pos_x = open('states/BX.txt').read()
        pos_y = open('states/BY.txt').read()
        new_observation = (float(pos_x), float(pos_y))
        map_id = int(open('states/BMap.txt').read())
        print('Map id after action:', map_id)
        if map_id == 25 or self.episode_step >= 200:
            reward = 0
            done = True
        elif new_observation == current_state:
            reward = -1.0
            done = False
        elif new_observation not in self.location_memory:
            reward = 0.3
            self.location_memory.add(new_observation)
            done = False
        else:
            done = False
            reward = -0.2

        return new_observation, reward, done
예제 #28
0
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
예제 #29
0
    def __init__(self, parent, journal, data_values, settings, start_index):
        super(AhkWorker, self).__init__(parent)
        self.hub = parent
        self.journal = journal
        self.data_values = data_values
        self.systems = [data[0].casefold() for data in data_values]
        self.settings = settings
        self.script, self.bind, self.copy, ahk_path = settings

        if not self.copy:
            self.ahk = AHK(executable_path=ahk_path)
        self.loop = True
        # set index according to last saved route or new plot, default index 1
        self.route_index = start_index if start_index != -1 else 1

        # connect parent signals
        parent.double_signal.connect(self.set_index)
        parent.edit_signal.connect(self.update_sys)
        parent.script_settings.connect(self.update_script)
        parent.window_quit_signal.connect(self.exit_and_save)
        parent.save_route_signal.connect(self.save_route)
        parent.quit_worker_signal.connect(self.quit_loop)
        parent.script_mode_signal.connect(self.set_copy)
    def __init__(self):
        self.AHK = AHK()
        self.application = self.start_game()
        self.process_id = self.application.process
        self.process = Process(pid=self.process_id)
        self.dialog = self.get_window_dialog()
        self.handle = self.dialog.handle
        self.window = Window.from_pid(self.AHK, self.process_id)

        left, top, right, bot = GetClientRect(self.handle)
        w = right - left
        h = bot - top

        self.hwndDC = GetWindowDC(self.handle)
        self.mfcDC = CreateDCFromHandle(self.hwndDC)
        self.saveDC = self.mfcDC.CreateCompatibleDC()
        self.saveDC_handle = self.saveDC.GetSafeHdc()

        self.saveBitMap = CreateBitmap()
        self.saveBitMap.CreateCompatibleBitmap(self.mfcDC, w, h)
        self.bmpinfo = self.saveBitMap.GetInfo()
        self.saveDC.SelectObject(self.saveBitMap)

        self.navigate_main_menu()
        self.enter_avoidance()
        self.process.suspend()

        self.PREVIOUS_ACTION = 0
        self.deathcount = self.get_game_deathcount()
        self.action_space = spaces.Discrete(6)
        self.elapsed_time = 0.0

        self.observation_space = spaces.Dict({"window":
                                                  spaces.Box(low=0, high=255, shape=self.get_observation_space_size(),
                                                             dtype=np.uint8),
                                              "time": spaces.Box(low=0, high=900, shape=(1,))})