commit b95e4b73cf3a0157ecf56af77c170d9400023b50 Author: Jan-Lukas Pagel Date: Mon May 15 22:15:57 2017 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e97605 --- /dev/null +++ b/.gitignore @@ -0,0 +1,113 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +### Eclipse template + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet +### NetBeans template +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +/PasswordTyper.iml +/lib/ +/.idea/ diff --git a/src/Keyboard.java b/src/Keyboard.java new file mode 100644 index 0000000..6d9e1eb --- /dev/null +++ b/src/Keyboard.java @@ -0,0 +1,149 @@ +import java.awt.*; + +import static java.awt.event.KeyEvent.*; + +public class Keyboard { + + private Robot robot; + + + public Keyboard() throws AWTException { + this.robot = new Robot(); + } + + public Keyboard(Robot robot) { + this.robot = robot; + } + + public void type(CharSequence characters) { + int length = characters.length(); + for (int i = 0; i < length; i++) { + char character = characters.charAt(i); + type(character); + } + } + + public void type(char character) { + switch (character) { + case 'a': doType(VK_A); break; + case 'b': doType(VK_B); break; + case 'c': doType(VK_C); break; + case 'd': doType(VK_D); break; + case 'e': doType(VK_E); break; + case 'f': doType(VK_F); break; + case 'g': doType(VK_G); break; + case 'h': doType(VK_H); break; + case 'i': doType(VK_I); break; + case 'j': doType(VK_J); break; + case 'k': doType(VK_K); break; + case 'l': doType(VK_L); break; + case 'm': doType(VK_M); break; + case 'n': doType(VK_N); break; + case 'o': doType(VK_O); break; + case 'p': doType(VK_P); break; + case 'q': doType(VK_Q); break; + case 'r': doType(VK_R); break; + case 's': doType(VK_S); break; + case 't': doType(VK_T); break; + case 'u': doType(VK_U); break; + case 'v': doType(VK_V); break; + case 'w': doType(VK_W); break; + case 'x': doType(VK_X); break; + case 'y': doType(VK_Y); break; + case 'z': doType(VK_Z); break; + case 'A': doType(VK_SHIFT, VK_A); break; + case 'B': doType(VK_SHIFT, VK_B); break; + case 'C': doType(VK_SHIFT, VK_C); break; + case 'D': doType(VK_SHIFT, VK_D); break; + case 'E': doType(VK_SHIFT, VK_E); break; + case 'F': doType(VK_SHIFT, VK_F); break; + case 'G': doType(VK_SHIFT, VK_G); break; + case 'H': doType(VK_SHIFT, VK_H); break; + case 'I': doType(VK_SHIFT, VK_I); break; + case 'J': doType(VK_SHIFT, VK_J); break; + case 'K': doType(VK_SHIFT, VK_K); break; + case 'L': doType(VK_SHIFT, VK_L); break; + case 'M': doType(VK_SHIFT, VK_M); break; + case 'N': doType(VK_SHIFT, VK_N); break; + case 'O': doType(VK_SHIFT, VK_O); break; + case 'P': doType(VK_SHIFT, VK_P); break; + case 'Q': doType(VK_SHIFT, VK_Q); break; + case 'R': doType(VK_SHIFT, VK_R); break; + case 'S': doType(VK_SHIFT, VK_S); break; + case 'T': doType(VK_SHIFT, VK_T); break; + case 'U': doType(VK_SHIFT, VK_U); break; + case 'V': doType(VK_SHIFT, VK_V); break; + case 'W': doType(VK_SHIFT, VK_W); break; + case 'X': doType(VK_SHIFT, VK_X); break; + case 'Y': doType(VK_SHIFT, VK_Y); break; + case 'Z': doType(VK_SHIFT, VK_Z); break; + case '`': doType(VK_BACK_QUOTE); break; + case '0': doType(VK_0); break; + case '1': doType(VK_1); break; + case '2': doType(VK_2); break; + case '3': doType(VK_3); break; + case '4': doType(VK_4); break; + case '5': doType(VK_5); break; + case '6': doType(VK_6); break; + case '7': doType(VK_7); break; + case '8': doType(VK_8); break; + case '9': doType(VK_9); break; + case '-': doType(VK_MINUS); break; + case '=': doType(VK_EQUALS); break; + case '~': doType(VK_SHIFT, VK_BACK_QUOTE); break; + case '!': doType(VK_EXCLAMATION_MARK); break; + case '@': doType(VK_AT); break; + case '#': doType(VK_NUMBER_SIGN); break; + case '$': doType(VK_DOLLAR); break; + case '%': doType(VK_SHIFT, VK_5); break; + case '^': doType(VK_CIRCUMFLEX); break; + case '&': doType(VK_AMPERSAND); break; + case '*': doType(VK_ASTERISK); break; + case '(': doType(VK_LEFT_PARENTHESIS); break; + case ')': doType(VK_RIGHT_PARENTHESIS); break; + case '_': doType(VK_UNDERSCORE); break; + case '+': doType(VK_PLUS); break; + case '\t': doType(VK_TAB); break; + case '\n': doType(VK_ENTER); break; + case '[': doType(VK_OPEN_BRACKET); break; + case ']': doType(VK_CLOSE_BRACKET); break; + case '\\': doType(VK_BACK_SLASH); break; + case '{': doType(VK_SHIFT, VK_OPEN_BRACKET); break; + case '}': doType(VK_SHIFT, VK_CLOSE_BRACKET); break; + case '|': doType(VK_SHIFT, VK_BACK_SLASH); break; + case ';': doType(VK_SEMICOLON); break; + case ':': doType(VK_COLON); break; + case '\'': doType(VK_QUOTE); break; + case '"': doType(VK_QUOTEDBL); break; + case ',': doType(VK_COMMA); break; + case '<': doType(VK_SHIFT, VK_COMMA); break; + case '.': doType(VK_PERIOD); break; + case '>': doType(VK_SHIFT, VK_PERIOD); break; + case '/': doType(VK_SLASH); break; + case '?': doType(VK_SHIFT, VK_SLASH); break; + case ' ': doType(VK_SPACE); break; + default: + throw new IllegalArgumentException("Cannot type character " + character); + } + } + + private void doType(int... keyCodes) { + doType(keyCodes, 0, keyCodes.length); + } + + private void doType(int[] keyCodes, int offset, int length) { + if (length == 0) { + return; + } + + robot.keyPress(keyCodes[offset]); + doType(keyCodes, offset + 1, length - 1); + robot.keyRelease(keyCodes[offset]); + } + + public void typeEnter() { + robot.keyPress(VK_ENTER); + robot.keyRelease(VK_ENTER); + } + +} \ No newline at end of file diff --git a/src/PasswordTyper.java b/src/PasswordTyper.java new file mode 100644 index 0000000..7d8e274 --- /dev/null +++ b/src/PasswordTyper.java @@ -0,0 +1,65 @@ +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +/** + * Created by Jan on 15.05.2017. + * Tysox.de Developer + */ +public class PasswordTyper extends JFrame { + + private JPanel contentPane; + private JTextField text; + private Keyboard keyboard; + + public static void main(String... args) { + EventQueue.invokeLater(() -> { + try { + PasswordTyper frame = new PasswordTyper(); + frame.setVisible(true); + frame.setTitle("PasswortTyper"); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } + + public PasswordTyper() { + try { + keyboard = new Keyboard(); + } catch (AWTException e) { + e.printStackTrace(); + } + setResizable(true); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + setBounds(100, 100, 450, 300); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + contentPane.setLayout(new BorderLayout(0, 0)); + setContentPane(contentPane); + + text = new JTextField(); + contentPane.add(text, BorderLayout.NORTH); + text.setColumns(10); + + JButton startButton = new JButton("Type"); + startButton.addActionListener(e -> { + new Thread(new TypeThread()).start(); + }); + contentPane.add(startButton, BorderLayout.WEST); + } + + private class TypeThread extends Thread { + @Override + public void run() { + try { + sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + keyboard.type(text.getText()); + keyboard.typeEnter(); + } + } + +}