here are the main alternatives:
pynput - Lower-level, better for listeners
from pynput.keyboard import Key, Controller
keyboard = Controller()
keyboard.type('hello')
keyboard.press(Key.ctrl)
keyboard.press('s')
keyboard.release('s')
keyboard.release(Key.ctrl)
Good for: keyboard/mouse listeners, hotkey detection, background monitoring.
keyboard - Simpler API, supports hotkeys
import keyboard
keyboard.write('hello')
keyboard.press_and_release('ctrl+s')
keyboard.add_hotkey('ctrl+shift+q', lambda: print('triggered'))
Good for: hotkey registration, simpler syntax, recording/playback.
mouse - Companion to keyboard library
import mouse
mouse.click('left')
mouse.move(100, 200)
pywinauto - Best for Windows GUI automation
from pywinauto import Application
app = Application().start('notepad.exe')
app.UntitledNotepad.Edit.type_keys('hello')
app.UntitledNotepad.menu_select('File->Save As')
Good for: interacting with Windows controls directly (buttons, menus, dialogs) without coordinates. Much more robust.
autoit (via pyautoit) - Windows classic
import autoit
autoit.run('notepad.exe')
autoit.win_wait_active('Untitled - Notepad')
autoit.send('hello')
recommendation:
| Use case | Best choice |
|---|
| Windows app automation | pywinauto |
| Cross-platform, simple | pyautogui |
| Hotkey listeners | keyboard / pynput |
| Robust Windows scripting | pywinauto or autoit |
For your Notepad example, pywinauto would be more reliable since it targets controls directly rather than screen coordinates.