pynput
library: for controlling and listening to mouse and keyboard.Controller
objects for mouse and keyboard automation.from pynput.mouse import Listener as MouseListener, Controller as MouseController
from pynput.keyboard import Key, Listener as KeyboardListener, Controller as KeyboardController
Listener
: used to listen for input events.Controller
: used to simulate (control) input devices.as
: gives custom names for easier reference (avoid confusion when using both mouse and keyboard listeners).Examples in the comments demonstrate basic file operations:
Mode | Purpose | Example |
---|---|---|
"r" |
Read-only | open("log.txt", "r") |
"w" |
Write (overwrites file) | open("log.txt", "w") |
"a" |
Append (adds to end) | open("log.txt", "a") |
with
:with open("log.txt", "a") as f:
f.write("Hello World\\n")