You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
63 lines
1.4 KiB
from pynput import mouse
|
|
|
|
def on_move(x, y):
|
|
print('Pointer moved to {0}'.format(
|
|
(x, y)))
|
|
|
|
def on_click(x, y, button, pressed):
|
|
print('{0} at {1}'.format(
|
|
'Pressed' if pressed else 'Released',
|
|
(x, y)))
|
|
print(button)
|
|
if not pressed:
|
|
# Stop listener
|
|
return True
|
|
|
|
def on_scroll(x, y, dx, dy):
|
|
print('Scrolled {0} at {1}'.format(
|
|
'down' if dy < 0 else 'up',
|
|
(x, y)))
|
|
|
|
# Collect events until released
|
|
#with mouse.Listener(
|
|
# on_move=on_move,
|
|
# on_click=on_click,
|
|
# on_scroll=on_scroll) as listener:
|
|
# listener.join()
|
|
|
|
# ...or, in a non-blocking fashion:
|
|
#listener = mouse.Listener(
|
|
# on_move=on_move,
|
|
# on_click=on_click,
|
|
# on_scroll=on_scroll)
|
|
#listener.start()
|
|
|
|
|
|
from pynput import keyboard
|
|
|
|
def on_press(key):
|
|
try:
|
|
print('alphanumeric key {0} pressed'.format(
|
|
key.char))
|
|
except AttributeError:
|
|
print('special key {0} pressed'.format(
|
|
key))
|
|
|
|
def on_release(key):
|
|
print('{0} released'.format(
|
|
key))
|
|
if key == keyboard.Key.esc:
|
|
# Stop listener
|
|
return True
|
|
|
|
# Collect events until released
|
|
with keyboard.Listener(
|
|
on_press=on_press,
|
|
on_release=on_release) as listener:
|
|
listener.join()
|
|
|
|
# ...or, in a non-blocking fashion:
|
|
listener = keyboard.Listener(
|
|
on_press=on_press,
|
|
on_release=on_release)
|
|
listener.start() |