Chapter 7
Automating Mouse and Keyboard
IN THIS CHAPTER
Automating mouse and keyboard
Typing text from a Python script
Creating your own shortcut keys
Taking screenshots automatically
In this chapter, you investigate techniques for automating the mouse and keyboard. These techniques allow you to simulate human input for tasks like graphical user interface (GUI) testing, data entry, or repetitive workflows where you need to type the same thing over and over.
PyAutoGUI (short for Python Automation for Graphical User Interfaces) is the main library we’ll use for these scripts. It’s not part of the standard library. You’ll need to pip install it yourself. I suggest you create a folder for the script (or all scripts that use PyAutoGUI); then create a virtual environment and activate that virtual environment (see Chapter 2). Then make sure you enter this command at the VS Code Terminal:
pip install pyautogui
If you want to try out all the scripts in this chapter, you can create each one in that same sample folder to share the PyAutoGUI module.
Granting Permissions on a Mac
By default, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access