def printtime(): winput.press_key(VK_CONTROL) winput.press_key(VK_LSHIFT) time.sleep(0.1) winput.click_key(VK_OEM_1) winput.release_key(VK_CONTROL) winput.release_key(VK_LSHIFT)
async def play_from_txt(): print("Started replaying from txt!") set_state("REPLAYING_TXT") bps = [] with open(replay_buffer_path / f"{GAME_NAME}.txt", "r") as f: for data in f: vals = data[:-1].split(",") bps.append(vals) bps = np.array(bps) bps = np.char.replace(bps, "lshift", "shiftleft") key_list = list(bps) print(key_list) while key_list: start = time.time() action, value = key_list[0] value = value.strip() if action == "down": # pyautogui.keyDown(value) vk_key = vk_mapping[action] winput.press_key(vk_key) if action == "delay": while (time.time() - start) * 1000 < float(value): await asyncio.sleep(0) if action == "up": # pyautogui.keyUp(value) vk_key = vk_mapping[action] winput.release_key(vk_key) key_list = key_list[1:] await asyncio.sleep(0) set_state("RECORDING") print( "\n\nDone replaying, switching to recording.\nA human is playing now.\n\n" ) await asyncio.sleep(0)
import winput from winput.vk_codes import * import time def slow_click(vk_code): # delay each keypress by 1/10 of a second time.sleep(0.1) winput.click_key(vk_code) # open the RUN menu (WIN + R) winput.press_key(VK_LWIN) winput.click_key(VK_R) winput.release_key(VK_LWIN) time.sleep(0.5) # enter "notepad.exe" slow_click(VK_N) slow_click(VK_O) slow_click(VK_T) slow_click(VK_E) slow_click(VK_P) slow_click(VK_A) slow_click(VK_D) slow_click(VK_OEM_PERIOD) slow_click(VK_E) slow_click(VK_X) slow_click(VK_E) slow_click(VK_RETURN) time.sleep(1)
def copy(): winput.press_key(VK_CONTROL) winput.click_key(VK_C) winput.release_key(VK_CONTROL)
def ctrl_a(): winput.press_key(VK_CONTROL) winput.click_key(VK_A) winput.release_key(VK_CONTROL)
def tab_b(): winput.press_key(VK_MENU) winput.click_key(VK_TAB) time.sleep(0.5) winput.click_key(VK_TAB) winput.release_key(VK_MENU)
def tab(): winput.press_key(VK_MENU) winput.click_key(VK_TAB) winput.release_key(VK_MENU)
def paste(): winput.press_key(VK_CONTROL) winput.click_key(VK_V) winput.release_key(VK_CONTROL)
def execute(self): winput.release_key(self.vk_code)
def copy(): winput.press_key(VK_CONTROL) time.sleep(0.2) winput.click_key(VK_C) time.sleep(0.2) winput.release_key(VK_CONTROL)
def paste(): winput.press_key(VK_CONTROL) time.sleep(0.2) winput.click_key(VK_V) winput.release_key(VK_CONTROL)