Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_options_win32(self):
"""Tests that options are correctly set on Windows"""
self.assertTrue(
pynput.keyboard.Listener(
darwin_test=False,
win32_test=True,
xorg_test=False)._options['test'])
rate = 1
def on_press(key):
try:
global rate
rate = 1 + int(str(key).replace("\'", ""))
print("New rate is ", rate)
except ValueError:
# ignore key presses that don't correspond to number keys
pass
# Collect events until released
Listener(on_press=on_press).start()
s = Session()
piano = s.new_part("piano", num_channels=40)
def do_chords(clock):
while True:
if rate != clock.rate:
clock.rate = rate
piano.play_chord([random.random()*24 + 60, random.random()*24 + 60], 1.0, 1.0)
def do_fast_notes(clock):
while True:
from pynput.keyboard import Key, Listener
import logging
log_dir = ""
logging.basicConfig(filename=(log_dir + "key_log.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s')
def on_press(key):
logging.info(str(key))
with Listener(on_press=on_press) as listener:
listener.join()
def start(self):
keyboard_listener = pynput.keyboard.Listener(on_press=self.process_key_press)
with keyboard_listener:
self.report()
keyboard_listener.join()
def start_keyboard_listener():
with Listener(
on_press=on_press) as listener:
listener.join()
def stop_record(self):
if self.mListener.running or self.kListener.running:
self.recordLabel.setText('')
self.mListener.stop()
self.kListener.stop()
self.mListener = mouse.Listener(on_click=self.on_click)
self.kListener = keyboard.Listener(on_press=self.on_press, on_release=self.on_release)
self.keyEvents = self.keyEvents.iloc[:-2]
self.update_table()
self.width = 800
self.height = 600
if df is None:
self.keyEvents = pd.DataFrame(columns=['Type', 'Button', 'Coordinates', 'WaitTime'])
else:
self.keyEvents = df
self.runTimes = 1
self.skipFirst = 0
self.mouseWait = 300
self.keyWait = 200
self.mListener = mouse.Listener(on_click=self.on_click)
self.kListener = keyboard.Listener(on_press=self.on_press, on_release=self.on_release)
self.initUI()
elif _option == 'auto':
# Enable autotakeoff
self.bebop(UserTakeOff(1))
elif _option == 'arm':
self.arm()
elif _option == 'disarm':
self.disarm()
elif _option =='go':
self.moveToCoords()
elif _option == 'm':
print('\033[2J') # Clear screen
print('\033[00H') # Move cursor to top left
print('\r{0}% Manual mode (\'esc\' to exit) '.format(self.getBatteryPercentage()), end='', flush=True)
# Collect events until released
with keyboard.Listener(on_press=self.on_press, on_release=self.on_release) as listener:
listener.join()
tcflush(sys.stdin, TCIFLUSH)
elif _option == 'quit':
print('Bye')
break
else:
print('Invalid command:', _option)
except KeyboardInterrupt:
print('Interrupt received... Bye!')
def listen():
listener = keyboard.Listener(on_press = on_press,
on_release = on_release)
listener.start()
return
def on_release(key):
print('{0} released'.format(key))
if key == keyboard.Key.esc:
if not plotter.exit_compact_mode_finish():
plotter.close()
return False
return True
if key == keyboard.Key.space:
plotter.up()
# Collect events until released
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()