-
-
Save abdulmalik44/55d819972549f0586471b158bf8d5948 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment