def main(): session = asyncio.run(get_media_session()) keyboard = Controller() if sys.argv[2] in ['play', 'pause', 'next', 'previous']: if session: info = asyncio.run(get_media_info(session)) title = info.__getattribute__('title') artist = info.__getattribute__('artist') status = session.get_playback_info().playback_status if sys.argv[2] == 'play' and status != 4: print("Started: ->", title if title != "" else "Unknown", "<- by ->", artist if artist != "" else "Unknown", "<-") session.try_play_async() elif sys.argv[2] == 'pause' and status != 5: print("Paused: ->", title if title != "" else "Unknown", "<- by ->", artist if artist != "" else "Unknown", "<-") session.try_pause_async() elif sys.argv[2] == 'next': print("Skipping: ->", title if title != "" else "Unknown", "<- by ->", artist if artist != "" else "Unknown", "<-") session.try_skip_next_async() elif sys.argv[2] == 'previous': print("Playing previous song:") session.try_skip_previous_async() else: print(int(sys.argv[1])) keyboard.tap(KeyCode.from_vk(int(sys.argv[1]))) else: print(int(sys.argv[1])) keyboard.tap(KeyCode.from_vk(int(sys.argv[1])))
class Resetter: def __init__(self, delay=0.07, world_name=None): self._keyboard = Controller() self._delay = delay self._world_name = world_name def reset(self): raise NotImplementedError def _tap(self, sequence: list): for key in sequence: self._keyboard.tap(key) sleep(self._delay)
class Resetter: def __init__(self, delay=0.07, world_name=None, seed=None): self._keyboard = Controller() self._delay = delay self._world_name = world_name self.set_seed(seed) def set_seed(self, seed): self._seed = seed if seed is None: self._category = "rsg" else: self._category = "ssg" def reset(self): raise NotImplementedError def _tap(self, sequence: list): for key in sequence: self._keyboard.tap(key) sleep(self._delay)
# pynputv1.7 by .py to .exe defect, use "pip install pynput==1.6.8" import time from pynput.keyboard import Key, Controller keyboard = Controller() #time.sleep(2) keyboard.press(Key.alt_l) keyboard.tap(Key.tab) #keyboard.press(Key.cmd) #keyboard.release(Key.cmd)
class GameController(): def __init__(self): self.kb = Controller() self.current_move = None def confirm(self): self.stop() k = KEYS.get('start') self.kb.press(key=k) time.sleep(0.5) self.kb.release(key=k) def reset(self): self.stop() print(f'Game resetted at {datetime.datetime.now()}') k = KEYS.get('reset') self.kb.press(key=k) time.sleep(0.5) self.kb.release(key=k) def stop(self): if self.current_move: self.kb.release(key=self.current_move) def move(self, direction): assert direction in set(['left', 'right', 'up', 'down']) k = KEYS.get(direction) if self.current_move == k: pass self.stop() self.kb.press(key=k) self.current_move = k def kick(self, direction): assert direction in set(['right', 'left']) k = KEYS.get(direction) kick_k = KEYS.get('B') if self.current_move == kick_k: pass self.stop() self.kb.tap(key=k) # switch direction # kick self.kb.press(key=kick_k) self.current_move = kick_k def sit_kick(self, direction): assert direction in set(['right', 'left']) k = KEYS.get(direction) kick_k = KEYS.get('B') if self.current_move == kick_k: pass self.stop() self.kb.tap(key=k) # switch direction # kick with self.kb.pressed(KEYS.get('down')): self.kb.press(kick_k) self.current_move = kick_k def sit(self): k = KEYS.get('down') if self.current_move == k: pass self.stop() self.kb.press(key=k) self.current_move = k
def process_line(line, currentChat, playerLookup): if line == "": return #print(line) line = line.rstrip().split() if len(line) == 0: print("this condition is necessary") return ismod = False userId = -1 if line[0][0] == "@": tags = line.pop(0) tmp8 = tags.split("mod=") if len(tmp8) > 1: if tmp8[1][0] == "1": ismod = True tmp9 = tags.split("user-id=") if len(tmp9) > 1: userId = tmp9[1].split(";")[0] user = "" command = [] channel = "" for index, word in enumerate(line): if index == 0: user = word.split('!')[0] #user = user[0:24] # what's this for? if user == "PING": currentChat.pong() return if len(line) < 4: return if index == 2: channel = word if index == 3: if len(word) <= 1: return command.append(word.lower()[1:]) if index >= 4: command.append(word) if len(channel) <= 1: channel = "00-main" if channel[0] != "#": channel = "00-main" path = f"irc/{channel[1:]}.log" with open(os.path.join(settings.baseDir,path), 'a') as f: f.write(datetime.datetime.now().isoformat().split(".")[0] + " " + " ".join(line) + "\n") #print("[user]", user, "[command]", command, "[userid]", userid, "[ismod]", ismod) if command[0] not in ['!ping','!roles','!racecommands','!whitelist','!unwhitelist','!add','!set','!rejoin','!quit','!start','!forcequit','!dq','!noshow', '!revive', '!settime', '!blacklist', '!unblacklist', '!admin', '!debugquit', '!togglestream']: return user = user.lower()[1:] print("[In chat "+channel+"] "+user+":"+str(command)) # global commands if command[0] == "!ping": currentChat.message(channel, "Hi. Bot is alive.") if command[0] == "!racecommands": currentChat.message(channel, "Command list: https://pastebin.com/d7mPZd13") if command[0] == "!roles": if len(command) == 1: statusMsg = users.status(user, playerLookup) else: statusMsg = users.status(command[1], playerLookup) if statusMsg is not None: currentChat.message(channel, statusMsg) # shared commands if (user in users.admins) or (user in users.racersL): if command[0] == "!whitelist" and len(command) == 2: subject = command[1].lower() if subject in users.blacklist: currentChat.message(channel, "Sorry, " + command[1] + " is on the blacklist.") elif subject not in users.updaters: users.add(subject,users.Role.UPDATER) currentChat.message(channel, command[1] + " is now an updater.") else: currentChat.message(channel, command[1] + " is already an updater.") elif command[0] == "!unwhitelist" and len(command) == 2: subject = command[1].lower() if subject in users.updaters: users.remove(subject,users.Role.UPDATER) currentChat.message(channel, command[1] + " is no longer an updater.") else: currentChat.message(channel, command[1] + " is already not an updater.") # racer commands if user in users.racersL: if (command[0] == "!add" or command[0] == "!set") and len(command) == 2: try: number = int(command[1]) if user in playerLookup.keys(): response = "" if command[0] == "!add": response = playerLookup[user].update(playerLookup[user].collects + number) elif command[0] == "!set": response = playerLookup[user].update(number) if response != "": currentChat.message(channel, response) settings.redraw = True except ValueError: pass if (command[0] == "!rejoin"): if playerLookup[user].status == "quit": playerLookup[user].status = "live" currentChat.message(channel, playerLookup[user].nameCaseSensitive +" has rejoined the race.") elif playerLookup[user].status == "done": playerLookup[user].collects -= 1 playerLookup[user].status = "live" currentChat.message(channel, playerLookup[user].nameCaseSensitive +" has rejoined the race.") settings.redraw = True if command[0] == "!quit" and playerLookup[user].status == "live": playerLookup[user].fail("quit") settings.redraw = True currentChat.message(channel, playerLookup[user].nameCaseSensitive + " has quit.") # updater commands if ((user in users.updaters) or (ismod==True) or (user in users.racersL)) and (user not in users.blacklist): if (command[0] == "!add" or command[0] == "!set") and len(command) == 3: player = command[1].lower() try: number = int(command[2]) if player in playerLookup.keys(): response = "" if command[0] == "!add": response = playerLookup[player].update(playerLookup[player].collects + number) elif command[0] == "!set": response = playerLookup[player].update(number) if response != "": currentChat.message(channel, response) settings.redraw = True except ValueError: pass # admin commands if user in users.admins: if command[0] == "!start": newTime = -1 if len(command)==1: newTime = datetime.datetime.now() elif len(command)==2: newTime = command[1] try: newTime = datetime.datetime.fromisoformat(newTime) except ValueError: currentChat.message(channel, "Invalid date format. Must be of this format: 2018-12-29@09:00") else: currentChat.message(channel, "Invalid date format. Must be of this format: 2018-12-29@09:00") if type(newTime) == datetime.datetime: settings.startTime = newTime with open(os.path.join(settings.baseDir,'settings.json'), 'r+') as f: j = json.load(f) j['start-time'] = settings.startTime.isoformat().split(".")[0] f.seek(0) json.dump(j, f, indent=4) f.truncate() currentChat.message(channel, "The race start time has been set to " + settings.startTime.isoformat().split(".")[0]) for player in playerLookup.keys(): playerLookup[player].calculateCompletionTime(settings.startTime) settings.redraw = True elif command[0] == "!forcequit" and len(command) == 2: player = command[1].lower() if player in playerLookup.keys(): if playerLookup[player].status == "live" or playerLookup[player].status == "done": playerLookup[player].fail("quit") settings.redraw = True currentChat.message(channel, command[1] + " has been forcequit.") elif command[0] == "!noshow" and len(command) == 2: player = command[1].lower() if player in playerLookup.keys(): playerLookup[player].fail("noshow") settings.redraw = True currentChat.message(channel, command[1] + " set to No-show.") elif command[0] == "!dq" and len(command) == 2: player = command[1].lower() if player in playerLookup.keys(): if playerLookup[player].status == "live" or playerLookup[player].status == "done": playerLookup[player].fail("disqualified") settings.redraw = True currentChat.message(channel, command[1] + " has been disqualified.") elif command[0] == "!revive" and len(command) == 2: player = command[1].lower() if player in playerLookup.keys(): if playerLookup[player].status == "done": playerLookup[player].collects -= 1 playerLookup[player].status = "live" settings.redraw = True currentChat.message(channel, command[1] + " has been revived.") elif command[0] == "!settime" and len(command) == 3: subject = command[1].lower() if subject in playerLookup.keys(): player = playerLookup[subject] stringTime = command[2] newTime = command[2].split(":") if len(newTime) != 3: currentChat.message(channel, "Invalid time string.") return try: duration = int(newTime[2]) + 60*int(newTime[1]) + 3600*int(newTime[0]) except ValueError: currentChat.message(channel, "Invalid time string.") return if int(newTime[1]) >= 60 or int(newTime[2]) >= 60: currentChat.message(channel, "Invalid time string.") return player.duration = duration player.completionTime = stringTime player.manualDuration(settings.startTime) settings.redraw = True currentChat.message(channel, player.nameCaseSensitive+"'s time has been updated.") elif command[0] == "!blacklist" and len(command) == 2: subject = command[1].lower() if subject not in users.blacklist: users.add(subject,users.Role.BLACKLIST) if subject in users.updaters: users.remove(subject,users.Role.UPDATER) currentChat.message(channel, command[1] + " has been blacklisted.") else: currentChat.message(channel, command[1] + " is already blacklisted.") elif command[0] == "!unblacklist" and len(command) == 2: subject = command[1].lower() if subject in users.blacklist: users.remove(subject,users.Role.BLACKLIST) currentChat.message(channel, command[1] + " is no longer blacklisted.") else: currentChat.message(channel, command[1] + " is already not blacklisted.") elif command[0] == "!admin" and len(command) == 2: subject = command[1].lower() if subject not in users.admins: users.add(subject,users.Role.ADMIN) currentChat.message(channel, command[1] + " is now an admin.") else: currentChat.message(channel, command[1] + " is already an admin.") elif command[0] == "!debugquit": currentChat.message(channel, "Quitting program.") settings.doQuit = True elif command[0] == "!togglestream": #pyautogui.hotkey("ctrl","5") kb = Controller() with kb.pressed(Key.ctrl): kb.tap("5") currentChat.message(channel, "Toggled stream.")
#testprozedur def proz(z): file = open(newpath_tmp + r'\keyboardtest.txt', 'a+') file.write(str(z) + "\n") file.close() #os.system(r'cmd /c "C:\Users\danie\Git\Python\sonstiges\sound_rec\displaydown.exe monitor off"') #os.system(r'cmd /c ""') # Ausführung öffnen keyboard.press(Key.cmd) keyboard.press('r') keyboard.release('r') keyboard.release(Key.cmd) time.sleep(dst) keyboard.type('taskschd.msc') keyboard.press(Key.enter) keyboard.release(Key.enter) time.sleep(5) print("scheduled task musste nun bearbeitet werden") #os.system(r'cmd /c "C:\Users\danie\Git\Python\sonstiges\sound_rec\displaydown.exe monitor off"') keyboard.tap(Key.cmd) #keyboard.press('t') #keyboard.release('t')
files = os.listdir(directory) files.sort() # sort normally files.sort(key=lambda x: len(x)) # sort by length to aboid 1 10 2 placements for filename in files: # wait a bit and retrieve filename sleep(TIME) name = f"\"{directory}\\{filename}\"" # insert image press_multiple([Key.ctrl, "a"]) # wait a bit and select the image sleep(TIME) keyboard.tap(Key.backspace) sleep(TIME) keyboard.type(name) sleep(TIME) keyboard.tap(Key.enter) # wait a bit and anchor it as a character sleep(TIME) press_multiple([Key.ctrl, "w"]) # wait a bit and advance to the next line sleep(TIME) for i in [Key.esc, Key.left, Key.enter]: # maybe Key.down keyboard.tap(i) sleep(0.15) keyboard.press(Key.page_down)
class Keylogger: def __init__(self): self.current_command = "" self.commands = read_to_list("macros.json") self.commands.sort(key=lambda x: len(x.name), reverse=True) self.categories = self.get_categories() self.listener = keyboard.Listener(on_press=self.on_key_press) self.controller = Controller() self.sending_command = False def start(self, category=None): if category is not None: self.commands = self.get_commands_by_category(category) self.listener.start() self.listener.join() def on_key_press(self, key): if not self.sending_command: if key == keyboard.Key.space: for command in self.commands: if command.matches(self.current_command): params = self.current_command.split( command.name)[1].split("$") for i in range(len(self.current_command) + 1): self.controller.tap(Key.backspace) self.controller.type(command.get_response(params)) break self.current_command = "" elif key == keyboard.Key.backspace: pass elif key == keyboard.Key.shift: pass elif key == keyboard.Key.enter: pass elif key == keyboard.Key.f8: exit(0) else: try: self.current_command += key.char except: self.current_command = "" def get_categories(self): return list(set([command.category for command in self.commands])) def check_command(self): for command in self.commands: if self.current_command == command.name: self.send_command(command) def get_commands_by_category(self, category): return [ command for command in self.commands if command.category == category ] def get_commands_except_category(self, category): return [ command for command in self.commands if command.category != category ] def add_macro(self, name, parameters, response): self.commands.append(Command(name, parameters, response)) write("macros.json", self.commands) def send_command(self, command): self.current_command = "" self.sending_command = True self.controller.press(Key.backspace) self.controller.release(Key.backspace) self.controller.type(command.response) self.sending_command = False