def on_press(self, key): if len(self.key_identifier) == 1: if key == KeyCode(char=self.key_identifier): return False elif key == Key(self.key_identifier): if key == KeyCode(char=self.key_identifier): return False
def __init__(self, key): """Initialize ARKey class.""" self.isctrl = False self.ischar = False if isinstance(key, (Key, KeyCode)): self.isctrl = (key == Key.ctrl_l) or (key == Key.ctrl_r) self.key = key elif isinstance(key, int): try: self.key = Key(KeyCode.from_vk(key)) except ValueError: self.key = KeyCode.from_vk(key) elif isinstance(key, str): self.key = KeyCode.from_char(key)
def on_release(key): print('{0} release'.format(key)) if key == Key.esc(): # Stop listener return False """
def main(): # voice_note = "calculate 2000 minus 127" voice_note = voice_cmd().lower() #print("Listening..") print("cmd: {}".format(voice_note)) global count count += 1 if count <= 1: t3 = Thread(target=key1) t3.start() else: pass for phrase in walk: if phrase in voice_note: print("Yes") speak("Ok Sir") print("Ok Sir") #main1(True, True) walking(False, False) walking(True, True) for phrase in object1: if phrase in voice_note: speak("Sure Sir") print("Sure Sir") #main1(True, True) #t1 = Thread(target=main1(True)) #t1.start() walking(False, False) walking(True) for phrase in read: if phrase in voice_note: reading() for phrase in WOLFRAMCMD: if phrase in voice_note: try: query = voice_note.replace('drishti ', '') #speak_text_cmd("Give me a minute sir") res = client.query(query) results = next(res.results).text speak("Give me a minute sir") #speak('WOLFRAM-ALPHA says - ') #speak_text_cmd('Got it.') print(results) speak(results) except: print("ERROR") speak("I don't know sir. Google is smarter than me") # webbrowser.open('https://www.google.co.in/search?q={}'.format(voice_note)) for phrase in SOS: if phrase in voice_note: print("Alert Mode Activated. SOS started") speak("Alert Mode Activated. SOS started") print("Sir The Messages are been sent") speak("Sir The Messages are been sent") if 'stop' in voice_note: #t3.join() Key.press('q') Key.release('q') #t1.join() speak("Sure Sir")
def on_release(key): if hasattr(key, attr[0]): print time.time(), 1, key.char elif hasattr(key, attr[1]) or hasattr(key, attr[2]) or hasattr(key, attr[3]) or hasattr(key, attr[4]): k = ('{0}'.format(key)) z = k.split('.') print time.time(), 1, z[1] class Key (threading.Thread): def run(self): with Listener( on_press=on_press, on_release=on_release) as listener: listener.join() if __name__ == '__main__': config = CONFIG('.') play = Play() key = Key() play.start() key.start() play.join() key.join()
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket.bind((HOST, PORT)) socket.listen(0) conn, addr = socket.accept() print('Connected by', addr) while True: data = conn.recv(1024) if not data: break print(repr(data)) events = data.decode('utf-8').split(';') for event in events: if event == '': continue event = json.loads(event) if event['type'] == 'press': if len(event['key']) == 1: keyboard.press(event['key']) else: keyboard.press(Key.__getattr__(event['key'])) elif event['type'] == 'release': if len(event['key']) == 1: keyboard.release(event['key']) else: keyboard.release(Key.__getattr__(event['key']))
def format_modifier_key(key: keyboard.Key) -> str: key = strip_apostrophe(key) key = key.replace("Key.", "") return f"[{key}]"