123456789101112131415161718192021222324252627282930 |
- # This is a sample Python script.
- from pynput import mouse,keyboard
- # Press Shift+F10 to execute it or replace it with your code.
- # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
- import win32con
- def on_press(key):
- try:
- print(f'Key {key.char} pressed')
- except AttributeError:
- print(f'Special key {key} pressed')
- def on_release(key):
- if key == keyboard.Key.esc:
- # Stop listener
- return False
- def on_click(x, y, button, pressed):
- if pressed:
- print(f'Mouse clicked at ({x}, {y}) with {button}')
- # 鼠标监听
- mouse_listener = mouse.Listener(on_click=on_click)
- mouse_listener.start()
- # 键盘监听
- # 保持监听
- mouse_listener.join()
|