Automate your typing practice on MonkeyType!
ChromeDriver | Selenium |
---|---|
Keyboard | Argparse |
---|---|
You can also install required dependencies using pip install -r requirements.txt
, and of course, make sure you have Python (version 3.6 or higher).
Make sure the Chrome Driver path is set to the right executable.
In the script, it is set to sh chrome_driver_path = "C:\\ProgramData\\chocolatey\\lib\\chromedriver\\tools\\chromedriver.exe"
but you may want to change it depending on where you have installed it.
At the bottom, the WPM is meant to be changed before running the script: typing_wpm = 150 This number is not completely accurate but it will get you around the number. Set it to whatever you want.
- Command line arguments have been added to change the WPM directly, however you are free to change it in the script as well.
The script is toggled through the
SHIFT
key.
Does not always pass bot detection and remember to use it at your own risk!
-
Importing Required Libraries:
- Import necessary Python libraries and modules, including
argparse
,time
,selenium
,keyboard
, and exceptions.
- Import necessary Python libraries and modules, including
-
Setting Up WebDriver and Command-Line Arguments:
- Set up the Chrome WebDriver to control the browser.
- Parse command-line arguments using
argparse
. Accepts the optional--wpm
argument with a default value of 100.
-
Opening the MonkeyType Website:
- Navigate to the "https://monkeytype.com/" website.
-
Handling Cookie Popup:
- The
handle_cookie_popup()
function waits for the cookie popup to appear and disappear usingWebDriverWait
andEC
fromselenium
. Print error message on exception.
- The
-
Setting Up Mode and Clicking:
- Wait for the "div[mode='words']" element to become clickable and click on it to select "words" mode.
-
Calculating Typing Delay:
- The
calculate_typing_delay()
function calculates the delay between typing each word based on target WPM and word length.
- The
-
Automating Typing:
- The
automate_typing()
function controls typing. - Check "SHIFT" key press to toggle typing and wait until released.
- If typing enabled, find active word and type it using
ActionChains
. Wait based on calculated delay and press "SPACE" key. - Catch exceptions like
NoSuchElementException
andWebDriverException
.
- The
-
Running the Automation:
- Set
typing_wpm
(e.g., 150) for desired WPM. - Call
automate_typing()
withargs
object as argument to start typing automation.
- Set
-
Comments and Formatting:
- Code is well-commented and properly formatted for readability.
Comments removed using http://www.removecomments.com/ and image created using https://carbon.vercel.app/