Skip to content

Instantly share code, notes, and snippets.

@kjmehta01
Last active December 20, 2020 02:20
Show Gist options
  • Save kjmehta01/de0c3e5dbdb25224fe667fdfd83582b3 to your computer and use it in GitHub Desktop.
Save kjmehta01/de0c3e5dbdb25224fe667fdfd83582b3 to your computer and use it in GitHub Desktop.
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.FileReader;
public class FastTyping
{
public static void main(String[] args) throws Exception
{
//Gets rid of html and just leaves words \/\/\/
BufferedReader in = new BufferedReader(new FileReader("raw.txt"));
String text = in.readLine();
text = text.replaceAll("</span>", "");
text = text.replaceAll("<div id=\"row1\" style=\"top: 1px;\">", "");
text = text.replaceAll("<span wordnr=\"0\" class=\"highlight\">", "");
text = text.replaceAll("</div>", "");
for(int x = 0; x < 500; x++){
text = text.replaceAll("<span wordnr=\""+ x +"\" class=\"\">", "");
}
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Robot bot = new Robot();
bot.setAutoDelay(10);
int keyCode;
//initial wait(in milliseconds)
try {
Thread.sleep(5000);
}
catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
int duration = 10;
for(int x = 0; x < text.length(); x++){
//Splits string and types one character at a time
keyCode = KeyEvent.getExtendedKeyCodeForChar(text.charAt(x));
long start = System.currentTimeMillis();
while(System.currentTimeMillis() - start < duration) {
//uppercase letter? presses shift and then key, otherwise just key
if(Character.isUpperCase(text.charAt(x))){
bot.keyPress(16);
}
bot.keyPress(keyCode);
}
//lets go of keys
if(Character.isUpperCase(text.charAt(x))){
bot.keyRelease(16);
}
bot.keyRelease(keyCode);
}
}
}
@abdulmalik44
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment