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" )
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()
class TestKeys(TestCase): def setUp(self): self.ahk = AHK() self.thread = None self.hotkey = None def tearDown(self): if self.thread is not None: self.thread.join(timeout=3) if self.ahk.key_state('a'): self.ahk.key_up('a') if self.ahk.key_state('Control'): self.ahk.key_up('Control') self.ahk.set_capslock_state('off') notepad = self.ahk.find_window(title=b'Untitled - Notepad') if notepad: notepad.close() if self.hotkey and self.hotkey.running: self.hotkey.stop() def test_key_wait_pressed(self): start = time.time() self.thread = threading.Thread(target=a_down) self.thread.start() self.ahk.key_wait('a', timeout=5) end = time.time() assert end - start < 5 def test_key_wait_released(self): start = time.time() a_down() self.thread = threading.Thread(target=release_a) self.thread.start() self.ahk.key_wait('a', timeout=2) def test_key_wait_timeout(self): self.assertRaises(TimeoutError, self.ahk.key_wait, 'f', timeout=1) def test_key_state_when_not_pressed(self): self.assertFalse(self.ahk.key_state('a')) def test_key_state_pressed(self): self.ahk.key_down('Control') self.assertTrue(self.ahk.key_state('Control')) def test_hotkey(self): self.hotkey = self.ahk.hotkey(hotkey='a', script='Run Notepad') self.thread = threading.Thread(target=a_down) self.thread.start() self.hotkey.start() time.sleep(1) self.assertIsNotNone(self.ahk.find_window(title=b'Untitled - Notepad')) def test_hotkey_stop(self): self.hotkey = self.ahk.hotkey(hotkey='a', script='Run Notepad') self.hotkey.start() assert self.hotkey.running self.hotkey.stop() self.ahk.key_press('a') self.assertIsNone(self.ahk.find_window(title=b'Untitled - Notepad'))
def press_a(): time.sleep(0.5) ahk = AHK() ahk.key_press('a')
ahk.click(357, 749) #open dolphin time.sleep(3) #win = ahk.find_window(title=b'Dolphin 5.0-10222') time.sleep(5) #win.move(x=865, y=0, width=500, height=500) time.sleep(1) #(1058, 153)#select game. #(1015, 94) play button ahk.click(1058, 153) time.sleep(1) ahk.click(1015, 94) time.sleep(15) ahk.key_press('.') time.sleep(2) #click on play ahk.key_press('.') time.sleep(10) ahk.key_press('F1') time.sleep(10) pm = pymem.Pymem(procname) time.sleep(4) base = pm.process_base.lpBaseOfDll time.sleep(4)
# Keys coord0 = (907, 401) coord1 = (1016, 399) coord2 = (1098, 488) coord3 = (1082, 594) coord4 = (1016, 675) coord5 = (895, 686) coord6 = (837, 590) coord7 = (838, 482) center = (960, 540) coords = [coord0, coord1, coord2, coord3, coord4, coord5, coord6, coord7] index = -1 ## Experiment ## # Calibration time.sleep(10) ahk.key_press('space') # Press and release a key while index < 345: index = index + 1 resp = random.randint(0, 7) time.sleep(1.2) ahk.click(coords[resp][0], coords[resp][1]) time.sleep(0.5) ahk.click(center[0], center[1])
def inventory(foo, argu1): ahk = AHK() if "active" not in target: if "tog" not in foo: if "a1" in foo: op = 2586, 589 elif "a2" in foo: op = 2664, 593 elif "a3" in foo: op = 2734, 591 elif "a4" in foo: op = 2806, 583 elif "a5" in foo: op = 2898, 583 elif "a6" in foo: op = 2950, 577 elif "a7" in foo: op = 3030, 580 elif "a8" in foo: op = 3171, 586 elif "a9" in foo: op = 3171, 586 elif "b1" in foo: op = 2591, 646 elif "b2" in foo: op = 2664, 645 elif "b3" in foo: op = 2735, 647 elif "b4" in foo: op = 2809, 645 elif "b5" in foo: op = 2880, 646 elif "b6" in foo: op = 2955, 646 elif "b7" in foo: op = 3024, 646 elif "b8" in foo: op = 3099, 647 elif "b9" in foo: op = 3168, 646 elif "c1" in foo: op = 2591, 719 elif "c2" in foo: op = 2663, 717 elif "c3" in foo: op = 2737, 717 elif "c4" in foo: op = 2806, 717 elif "c5" in foo: op = 2881, 718 elif "c6" in foo: op = 2952, 717 elif "c7" in foo: op = 3025, 717 elif "c8" in foo: op = 3096, 720 elif "c9" in foo: op = 3169, 720 else: None if argu1 == "1": po = 1 if argu1 == "2": po = 2 if argu1 == "3": po = 3 if argu1 == "4": po = 4 if argu1 == "5": po = 5 if argu1 == "6": po = 6 if argu1 == "7": po = 7 if argu1 == "8": po = 8 if argu1 == "9": po = 9 ahk.key_press('e') ahk.mouse_move(2121, 241) ahk.mouse_drag(op) ahk.key_press(str(po)) ahk.key_press('e') else: ahk.key_press('e') target.append('active') print(target) else: if "active" in target: ahk.key_press('e') target.clear() print(target)
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()