# -*- coding: utf-8 -*- """ Created on Sun Feb 2 07:51:09 2020 @author: marks """ from pynput import keyboard COMBINATIONS = [{keyboard.KeyCode(char="a")}, {keyboard.KeyCode(char="A")}, {keyboard.KeyCode(char="b")}, {keyboard.KeyCode(char="B")}, {keyboard.KeyCode(char="c")}, {keyboard.KeyCode(char="C")}, {keyboard.KeyCode(char="d")}, {keyboard.KeyCode(char="D")}, {keyboard.KeyCode(char="e")}, {keyboard.KeyCode(char="E")}, {keyboard.KeyCode(char="f")}, {keyboard.KeyCode(char="F")}, {keyboard.KeyCode(char="g")}, {keyboard.KeyCode(char="G")}, {keyboard.KeyCode(char="h")}, {keyboard.KeyCode(char="H")}, {keyboard.KeyCode(char="i")}, {keyboard.KeyCode(char="I")}, {keyboard.KeyCode(char="j")}, {keyboard.KeyCode(char="J")}, {keyboard.KeyCode(char="k")}, {keyboard.KeyCode(char="K")}, {keyboard.KeyCode(char="l")}, {keyboard.KeyCode(char="L")}, {keyboard.KeyCode(char="m")}, {keyboard.KeyCode(char="M")}, {keyboard.KeyCode(char="o")}, {keyboard.KeyCode(char="O")}, {keyboard.KeyCode(char="p")}, {keyboard.KeyCode(char="P")}, {keyboard.KeyCode(char="q")}, {keyboard.KeyCode(char="Q")}, {keyboard.KeyCode(char="r")}, {keyboard.KeyCode(char="R")}, {keyboard.KeyCode(char="s")}, {keyboard.KeyCode(char="S")}, {keyboard.KeyCode(char="t")}, {keyboard.KeyCode(char="T")}, {keyboard.KeyCode(char="u")}, {keyboard.KeyCode(char="U")}, {keyboard.KeyCode(char="v")}, {keyboard.KeyCode(char="V")}, {keyboard.KeyCode(char="w")}, {keyboard.KeyCode(char="W")},
def hotkey(gui): """Слушаем в отдельном потоке глобальный хоткей""" COMBO_1 = [keyboard.Key.tab, keyboard.KeyCode(char='1')] COMBO_2 = [keyboard.Key.tab, keyboard.KeyCode(char='2')] COMBO_3 = [keyboard.Key.tab, keyboard.KeyCode(char='3')] COMBO_4 = [keyboard.Key.tab, keyboard.KeyCode(char='4')] current = set() def browser_checker(func): def check(*args, **kwargs): if gui.web_thread: gui.web_thread.web.exit = False func(*args, **kwargs) else: gui.chat_print_signal.emit('Браузер закрыт') return check @browser_checker def execute_tab1(): try: gui.web_thread.web.start_data = gui.date_start.toPlainText() gui.web_thread.web.end_data = gui.date_end.toPlainText() gui.web_thread.web.url = gui.url.toPlainText() gui.web_thread.web.add_banner() except Exception as exc: gui.log.error('Возникла ошибка при загрузке баннеров') gui.log.error(exc) gui.log.info( '\n *** Нажата комбинация клавиш: tab + 1 \n *** Должна вызваться функция :)' ) @browser_checker def execute_tab2(): try: gui.web_thread.web.parser() except Exception as exc: gui.log.error('Возникла ошибка при выгрузке акций') gui.log.error(exc) gui.log.info( '\n *** Нажата комбинация клавиш: tab + 2 \n *** Должна вызваться функция :)' ) @browser_checker def execute_tab3(): try: gui.web_thread.web.download_banners() except Exception as exc: gui.log.error('Возникла ошибка при выгрузке баннеров') gui.log.error(exc) gui.log.info( '\n *** Нажата комбинация клавиш: tab + 3 \n *** Должна вызваться функция :)' ) @browser_checker def execute_tab4(): try: gui.web_thread.web.add_actions() except Exception as exc: gui.log.error('Возникла ошибка при загрузке акций') gui.log.error(exc) gui.log.info( '\n *** Нажата комбинация клавиш: tab + 4 \n *** Должна вызваться функция :)' ) def get_key_name(key): """Определяем имя нажатой клавишы""" if isinstance(key, keyboard.KeyCode): return key.char else: return str(key) def on_press(key): """Проверка на комбинацию""" # key_name = get_key_name(key) if key == keyboard.Key.esc: # gui.log.info(f'--- Нажата клавиша: {key_name}') gui.set_exit_signal.emit() elif key == keyboard.Key.tab: current.add(key) # gui.log.info(f'--- Нажата клавиша: {key_name}') # elif (key == keyboard.KeyCode.from_char('1')) or (key == keyboard.KeyCode.from_char('2')) or \ # (key == keyboard.KeyCode.from_char('3')) or (key == keyboard.KeyCode.from_char('4')): # gui.log.info(f'--- Нажата клавиша: {key_name}') else: # gui.log.info(f'Информационно. Вы нажали: {key_name}') current.clear() if any([key in COMBO_1 + COMBO_2 + COMBO_3 + COMBO_4]): current.add(key) if all(key in current for key in COMBO_1): execute_tab1() current.clear() elif all(key in current for key in COMBO_2): execute_tab2() current.clear() elif all(key in current for key in COMBO_3): execute_tab3() current.clear() elif all(key in current for key in COMBO_4): execute_tab4() current.clear() with keyboard.Listener(on_press=on_press) as listener: listener.join()
#!/usr/bin/env python3 import subprocess from pynput import keyboard # The shortcuts triggering switch SWITCH_SHORTCUTS = [ # For some reason Alt pressed after Shift gets registered as a different # key code on my system. {keyboard.KeyCode(65511)}, # Shift + Alt {keyboard.Key.alt, keyboard.Key.shift}, # Alt + Shift # Examples # {keyboard.Key.shift, keyboard.Key.ctrl}, # Shift + Ctrl # {keyboard.Key.cmd, keyboard.Key.space}, # Super + Space # {keyboard.Key.caps_lock}, # CapsLock ] # How many layouts do you have? LAYOUTS_COUNT = 2 # If you're having troubles configuring SWITCH_SHORTCUTS, set this to True. # Script will output pressed keys so you could copy-paste them. DEBUG = False def format_key(key): """ Formats a key the way it should be written in SWITCH_SHORTCUTS list. """ if isinstance(key, keyboard.Key):
import time import threading from pynput.mouse import Button, Controller import pynput.keyboard as kb import random delay = 30 button = Button.left start_stop_key = kb.KeyCode(char='s') exit_key = kb.KeyCode(char='e') def action(self): arrow_keys = [kb.Key.up,kb.Key.down,kb.Key.right,kb.Key.left] return random.choice(arrow_keys) class ClickMouse(threading.Thread): def __init__(self, delay, button): super(ClickMouse, self).__init__() self.delay = delay self.button = button self.running = False self.program_running = True def start_clicking(self): self.running = True def stop_clicking(self): self.running = False def exit(self):
from pynput import keyboard # Keys currently pressed current = set() hotkeys = [ {keyboard.Key.ctrl, keyboard.KeyCode(char='`')} ] def on_press(key): if any([key in hotkey for hotkey in hotkeys]): current.add(key) if any(all(k in current for k in hotkey) for hotkey in hotkeys): execute() def on_release(key): if any([key in hotkey for hotkey in hotkeys]): current.remove(key) def execute(): print("Taking screenshot") with keyboard.Listener(on_press=on_press, on_release=on_release) as listener: listener.join()
import pynput from pynput import keyboard from pynput.keyboard import Key, Listener import logging #Key stroke listening code. COMBINATION = {keyboard.Key.ctrl_l, keyboard.KeyCode(char='b')} current = set() def on_press(key): logging.info(str(key)) print('{0} key pressed'.format(key)) if key in COMBINATION: current.add(key) if all(k in current for k in COMBINATION): print("That's a bingo!") if key == keyboard.Key.esc: print('Closing Listener') listener.stop() def on_release(key): logging.info(str(key)) print('{0} key released'.format(key)) with Listener(on_press=on_press, on_release=on_release) as listener: listener.join()
def playing(self): self.play = True while self.play: self.key_handler(self.snake1, self.key, keyboard.KeyCode(char='w'), keyboard.KeyCode(char='e'), keyboard.KeyCode(char='z'), keyboard.KeyCode(char='x'), keyboard.KeyCode(char='a'), keyboard.KeyCode(char='d')) self.key_handler(self.snake2, self.key2, keyboard.KeyCode(char='u'), keyboard.KeyCode(char='i'), keyboard.KeyCode(char='n'), keyboard.KeyCode(char='m'), keyboard.KeyCode(char='h'), keyboard.KeyCode(char='k')) # snake 1 if not self.snake1.ate: self.cut_tail(self.snake1) else: self.snake1.score += 1 myApp.score1.setText('Score 1: ' + str(self.snake1.score)) self.snake1.ate = False self.add_treat() # snake 2 if not self.snake2.ate: self.cut_tail(self.snake2) else: self.snake2.score += 1 myApp.score2.setText('Score 2: ' + str(self.snake2.score)) self.snake2.ate = False self.add_treat() self.printuj() # updating the window self.app.processEvents() time.sleep(0.9) self.show()
def down(): cb.press(keyboard.KeyCode(98)) cb.release(keyboard.KeyCode(98)) time.sleep(wait_time)
def right(): cb.press(keyboard.KeyCode(102)) cb.release(keyboard.KeyCode(102)) time.sleep(wait_time)
def effects_off(controller): controller.press(keyboard.KeyCode(off)) # F5 sleep(0.1) # need this for obs to read macro controller.release(keyboard.KeyCode(off))
def up(): cb.press(keyboard.KeyCode(104)) cb.release(keyboard.KeyCode(104)) time.sleep(wait_time)
def effect_on(controller, key: int): controller.press(keyboard.KeyCode(key)) sleep(0.1) # need this for obs to read macro controller.release(keyboard.KeyCode(key))
from pynput import keyboard import pyperclip import datetime VAL = ['source_%Y_%m_%d_%H_%M_%S', '%Y_%m_%d_%H_%M_%S_result'] KEYS = [keyboard.KeyCode(char='S'), keyboard.KeyCode(char='D')] def get_text(text_template): today = datetime.datetime.today() print(type(today)) return today.strftime(text_template) # The key combination to check COMBINATIONS = [{keyboard.Key.shift, KEYS[0]}, {keyboard.Key.shift, KEYS[1]}] # The currently active modifiers current = set() def execute(): pyperclip.copy(get_text(VAL[0] if KEYS[0] in current else VAL[1])) # pyperclip.copy('The text to be copied to the clipboard.') # spam = pyperclip.paste() def on_press(key): if any([key in COMBO for COMBO in COMBINATIONS]): current.add(key) if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
GPIO.output(motor["IN_1"], GPIO.LOW) GPIO.output(motor["IN_2"], GPIO.HIGH) motor["PWM"].ChangeDutyCycle(powerInPercent) def stop(): for index in range(len(motors)): motors[index]["PWM"].ChangeDutyCycle(0) #Delay 2s time.sleep(0.5) # The key combination to check COMBINATIONS = [{keyboard.Key.shift, keyboard.KeyCode(char='c')}, {keyboard.Key.shift, keyboard.KeyCode(char='a')}, {keyboard.Key.shift, keyboard.KeyCode(char='d')}, {keyboard.Key.shift, keyboard.KeyCode(char='w')}, {keyboard.Key.shift, keyboard.KeyCode(char='s')}, {keyboard.Key.shift, keyboard.KeyCode(char='q')}, {keyboard.Key.shift, keyboard.KeyCode(char='e')}, {keyboard.Key.shift, keyboard.KeyCode(char='r')}, {keyboard.Key.shift,
conf = config_parser.configParser('druid_config.xml') '''Global Cooldown''' GLOBAL_CD = 1 '''peripherals configuration''' mouse = ms.Controller() keyboard = kb.Controller() leftbutton = ms.Button.left rightbutton = ms.Button.right arrowUp = kb.Key.up arrowDown = kb.Key.down arrowRight = kb.Key.right arrowLeft = kb.Key.left actionKeys = {"1": kb.KeyCode(0, "1"), "2": kb.KeyCode(0, "2"), "3": kb.KeyCode(0, "3"), "4": kb.KeyCode(0, "4"), "5": kb.KeyCode(0, "5"), "6": kb.KeyCode(0, "6"), "7": kb.KeyCode(0, "7"), "8": kb.KeyCode(0, "8"), "9": kb.KeyCode(0, "9"), "0": kb.KeyCode(0, "0"), "q": kb.KeyCode(0, "q"), "w": kb.KeyCode(0, "w"), "e": kb.KeyCode(0, "e"), "a": kb.KeyCode(0, "a"), "s": kb.KeyCode(0, "s"), "z": kb.KeyCode(0, "z"), "x": kb.KeyCode(0, "x")} '''Keyboard control over the CombatAssistant Bot''' start_stop_key = kb.KeyCode(char='f') exit_key = kb.KeyCode(char='c') change_fight_stance = kb.KeyCode(char='g') def keyboardclick(value): keyboard.press(value) keyboard.release(value) time.sleep(GLOBAL_CD)
def left(): cb.press(keyboard.KeyCode(100)) cb.release(keyboard.KeyCode(100)) time.sleep(wait_time)
import re import subprocess import serial import pyautogui import pytesseract import serial.tools.list_ports import unidecode from pynput import keyboard linux_port_dir = "/dev/" baud_rate = 57600 current = set() hotkeys = [] if 'linux' in sys.platform: hotkeys = [{keyboard.Key.ctrl, keyboard.KeyCode(char='`')}] elif 'win32' in sys.platform: hotkeys = [{keyboard.Key.ctrl_l, keyboard.Key.tab}] def usage(): print("Usage: python3 {}".format(sys.argv[0])) raise SystemExit def get_port_name(): ''' Retrieves port name of Arduino for Linux or Windows OS ''' # If Linux: /dev/ttyUSB* or /dev/ttyACM* if sys.platform == 'posix' or 'linux' in sys.platform:
def enter(): cb.press(keyboard.KeyCode(96)) cb.release(keyboard.KeyCode(96)) time.sleep(wait_time)
import os from pynput import keyboard import socket import threading # Startup file statics STARTUP_FILE = os.getenv( 'APPDATA' ) + '\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\multi-clipboard.vbs' STARTUP_COMMAND = 'python ' + os.path.dirname( os.path.realpath(__file__)) + '\\multi_clipboard.py' # Key listener statics LISTENER_COMBINATION = [ keyboard.Key.ctrl_l, keyboard.Key.cmd, keyboard.KeyCode(char='c') ] # Server statics SERVER_ARE_YOU_RUNNING = b'Running?' SERVER_YES = b'Yes' SERVER_STOP = b'Stop' SERVER_LOCK_FILE = os.path.dirname( os.path.realpath(__file__)) + '\.server_lock' # Setup calls for the MainThread to catch to keep the GUI in the MainThread openGUIEvent = threading.Event() openGUIEvent.openGUI = False def start_listener():
def control_test(): controlboard = Controller() controlboard.press(keyboard.KeyCode(98)) controlboard.release(keyboard.KeyCode(98))
def on_press(self, key): if key in [ keyboard.KeyCode(char='w'), keyboard.KeyCode(char='e'), keyboard.KeyCode(char='a'), keyboard.KeyCode(char='d'), keyboard.KeyCode(char='z'), keyboard.KeyCode(char='x') ]: self.key = key elif key in [ keyboard.KeyCode(char='u'), keyboard.KeyCode(char='i'), keyboard.KeyCode(char='h'), keyboard.KeyCode(char='k'), keyboard.KeyCode(char='m'), keyboard.KeyCode(char='n') ]: self.key2 = key
import pyperclip from pynput import keyboard DEBUG = sys.flags.debug or False def debug(*args): if not DEBUG: return print(*args) # The key combination to check COMBINATIONS = [{keyboard.Key.ctrl_l, keyboard.KeyCode(char='v')}, {keyboard.Key.ctrl_l, keyboard.KeyCode(char='V')}] # The currently active modifiers pressedButtons = set() strings = sys.argv[1:] i = 0 def execute(): debug("execute()") global i pyperclip.copy(strings[i]) i += 1
from pynput import keyboard # the key combination to look for COMBINATIONS = [{keyboard.Key.shift, keyboard.KeyCode(vk=65)}] def execute(): """function to execute when a combination is pressed""" print("do something") # The currently pressed key (initially empty) pressed_vks = set() def get_vk(key): """ Get the virtual key code form a key. these are used so case/shift modifications are ignored """ return key.vk if hasattr(key, 'vk') else key.value.vk def is_combination_pressed(combination): """check if the combination is satisifed using the keys pressed in pressed_vks """ return all([get_vk(key) in pressed_vks for key in combination]) def on_press(key):
def main(): # Attempt to sync with the MCU if not sync(): print('Could not sync!') return print("READY") notDone = True while notDone: command = NO_INPUT lx = 128 ly = 128 rx = 128 ry = 128 for key in current: if(key == keyboard.KeyCode(char='l')): command += BTN_A if(key == keyboard.KeyCode(char='k')): command += BTN_B if(key == keyboard.KeyCode(char='j')): command += BTN_X if(key == keyboard.KeyCode(char='i')): command += BTN_Y if(key == keyboard.KeyCode(char='3')): command += BTN_PLUS if(key == keyboard.KeyCode(char='1')): command += BTN_MINUS if(key == keyboard.KeyCode(char='h')): command += BTN_HOME if(key == keyboard.KeyCode(char='c')): command += BTN_CAPTURE if(key == keyboard.KeyCode(char='q')): command += BTN_ZL if(key == keyboard.KeyCode(char='u')): command += BTN_ZR if(key == keyboard.KeyCode(char='e')): command += BTN_L if(key == keyboard.KeyCode(char='o')): command += BTN_R if(key == keyboard.KeyCode(char='x')): command += BTN_LCLICK if(key == keyboard.KeyCode(char=',')): command += BTN_RCLICK if(key == Key.left): command += DPAD_L if(key == Key.right): command += DPAD_R if(key == Key.up): command += DPAD_U if(key == Key.down): command += DPAD_D if Key.esc in current: notDone=False break if(key == keyboard.KeyCode(char='t')): command += BTN_L command += BTN_R if(key == keyboard.KeyCode(char='w')): ly-=127 if(key == keyboard.KeyCode(char='a')): lx-=127 if(key == keyboard.KeyCode(char='s')): ly+=127 if(key == keyboard.KeyCode(char='d')): lx+=127 send_cmd(command,lx,ly,rx,ry) p_wait(1/30) frameNo = -3 frameLength = 1/60 f = open("script0.txt","r") f1 = f.readlines(); for line in f1: startTime = time.perf_counter() parts = line.split(" ") while frameNo != int(parts[0]): startTime = time.perf_counter() send_cmd(pressKeys(""),128,128,128,128) p_waitNew(frameLength,startTime) frameNo+=1 print(frameNo) com = pressKeys(parts[1]) left = parts[2].split(";") right = parts[3].split(";") send_cmd(com,toValidJox(left[0]),toValidJoy(left[1]),toValidJox(right[0]),toValidJoy(right[1])) frameNo+=1 p_waitNew(frameLength,startTime) send_cmd(pressKeys(""),128,128,128,128)
import subprocess from pynput import keyboard # The key combination being used COMBINATIONS = [{keyboard.Key.shift, keyboard.KeyCode(char='e')}, {keyboard.Key.shift, keyboard.KeyCode(char='E')}] # The currently active modifiers pressed = set() def execute(): subprocess.call( 'python.exe firefoxScript.py' ) # excecutes the firefoxScript file as a different process def on_press(key): if any([key in COMBO for COMBO in COMBINATIONS]): pressed.add(key) if any(all(k in pressed for k in COMBO) for COMBO in COMBINATIONS): execute() #executes the script def on_release(key): if any([key in COMBO for COMBO in COMBINATIONS]): pressed.discard(key)
import pyautogui, time, clipboard from pynput import keyboard COMBINATIONS = [{keyboard.Key.ctrl, keyboard.KeyCode(char='c')}, {keyboard.Key.ctrl, keyboard.KeyCode(char='C')}] current = set() coor = [[434, 529, 41], [370, 515, 39], [405, 458, 45], [401, 377, 45], [435, 521, 45], [372, 386, 45], [336, 372, 53], [355, 343, 53], [320, 368, 53], [352, 420, 53], [315, 360, 53], [380, 352, 55], [334, 356, 53], [272, 330, 43], [348, 370, 53], [349, 385, 53], [432, 487, 43], [359, 431, 43], [401, 348, 53], [385, 348, 53]] paises = [ 'argentina', 'chile', 'bolívia', 'venezuela', 'uruguai', 'colômbia', 'costa rica', 'cuba', 'el salvador', 'equador', 'guatemala', 'haiti', 'honduras', 'méxico', 'nicarágua', 'panamá', 'paraguai', 'peru', 'porto rico', 'república dominicana' ] def execute(x, y, z): pyautogui.click(983, 384) pyautogui.click(134, 54) time.sleep(0.5) pyautogui.click(135, 97) time.sleep(0.5) pyautogui.click(x, y) time.sleep(0.5)
from pynput import keyboard import clipboard import pyttsx3 # The key combination to check COMBINATIONS = [ {keyboard.Key.ctrl, keyboard.KeyCode(char='s'), keyboard.KeyCode(char='t')}, {keyboard.Key.ctrl, keyboard.KeyCode(char='S'), keyboard.KeyCode(char='T')} ] # The currently active modifiers engine = pyttsx3.init() current = set() cont = keyboard.Controller() def execute(): print("function activated!") cont.press(keyboard.Key.ctrl) cont.press(keyboard.KeyCode(char='c')) time.sleep(0.25) cont.release(keyboard.Key.ctrl) cont.release(keyboard.KeyCode(char='c')) engine.runAndWait() content = clipboard.paste() engine.say(content) def on_press(key): if any([key in COMBO for COMBO in COMBINATIONS]): current.add(key) if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
def key_translator(string): if len(string) == 1: return kb.KeyCode(char=string) elif len(string) > 1: return kb.Key.__members__.get(string, None)
from pynput import keyboard # The key combination to check COMBINATIONS = [{keyboard.Key.shift, keyboard.KeyCode(char='a')}, {keyboard.Key.shift, keyboard.KeyCode(char='A')}] # The currently active modifiers current = set() print('Recording Script executing...') print('Press Shift+a to stop recording.') # this function substitutes a recording process, which is rather long and continuous, and needs to be stopped by some external interrupt. def recording_op(): print('just stalling...') for i in range(10000): for j in range(1000): pass recording_op() def execute(): print("Stopping recording...") exit()
pp = 15 farmAll = True catchPokemon = ["ralts"] SPATK_EVPokemon = [ "gastly", "aaunter", "abra", "natu", "mareep", "gengar", "budew", "magmar" ] SPD_EVPokemon = [ "rattata", "spearow", "zubat", "poliwag", "raticate", "pideotto", "fearow", "poliwag" "weedle", "aipom", "yanma", "eeoc" ] runPokemon = ["tangela", "onphan"] stop = True '''--------------INPUTS--------------''' '''--------------LISTENER--------------''' COMBO_farmAll = [{keyboard.KeyCode(char='g'), keyboard.KeyCode(char='o')}] COMBO_stop = [{keyboard.KeyCode(char='s')}] current = set() log = [] controller = Controller() def farm(): #FarmFunctions.farmAndCatch(farmAll=True, catch=catchPokemon, run=runPokemon) FarmFunctions.farmAll(direction=1) def on_press(key): #Check for farmALL combo if any([key in COMBO for COMBO in COMBO_farmAll]): current.add(key)