Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER} + * @param keyCode The keycode to send. + */ public void clickKey(int keyCode) { pressTime = System.currentTimeMillis(); @@ -75,6 +110,12 @@ public class Keyboard implements KeyListener { } } + /** + * Creates and sends a given PRESS KeyEvent using the given keyCode. Note, this does not send a Release Event + * typically associated with a key click. + *
Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER} + * @param keyCode + */ public void pressKey(int keyCode) { pressTime = System.currentTimeMillis(); @@ -82,6 +123,12 @@ public class Keyboard implements KeyListener { sendKeyEvent(ke); } + /** + * Creates and sends a given RELEASE KeyEvent using the given keyCode. Note, this does not send a Press Event + * typically associated with a key click. + *
Use constants where possible, from {@link KeyEvent}, such as {@code KeyEvent.VK_ENTER}
+ * @param keyCode
+ */
public void releaseKey(int keyCode) {
pressTime = System.currentTimeMillis();
@@ -89,6 +136,15 @@ public class Keyboard implements KeyListener {
sendKeyEvent(ke);
}
+ /**
+ * Creates KeyEvents to perform a Click of the given Char. This includes a Press, Typed and Release event
+ * in addition to an initial shiftDown and ending shiftUp if the character is a Special Char such as {@code !"£$%^&*(}
+ *
+ * {@see specialChars}
+ * @param target Component this event is linked to.
+ * @param c Char to send.
+ * @return KeyEvents for each action.
+ */
private KeyEvent[] createKeyClick(Component target, char c) {
pressTime += 2 * getRandom();
@@ -129,27 +185,23 @@ public class Keyboard implements KeyListener {
}
}
+ /**
+ * Creates KeyEvents for Press and Release of the given keyCode.
+ * @param target
+ * @param keyCode
+ * @return An array containing Press and Release KeyEvents.
+ */
private KeyEvent[] createKeyClick(Component target, int keyCode) {
- int modifier = 0;
- switch (keyCode) {
- case KeyEvent.VK_SHIFT:
- modifier = KeyEvent.SHIFT_MASK;
- break;
- case KeyEvent.VK_ALT:
- modifier = KeyEvent.ALT_MASK;
- break;
- case KeyEvent.VK_CONTROL:
- modifier = KeyEvent.CTRL_MASK;
- break;
- }
- KeyEvent pressed = new KeyEvent(target, KeyEvent.KEY_PRESSED,
- pressTime, modifier, keyCode, KeyEvent.CHAR_UNDEFINED);
- KeyEvent released = new KeyEvent(target, KeyEvent.KEY_RELEASED,
- pressTime + getRandom(), 0, keyCode, KeyEvent.CHAR_UNDEFINED);
- return new KeyEvent[]{ pressed, released };
+ return new KeyEvent[]{ createKeyPress(target, keyCode), createKeyRelease(target, keyCode) };
}
+ /**
+ * Creates a Press type KeyEvent
+ * @param target
+ * @param keyCode
+ * @return
+ */
private KeyEvent createKeyPress(Component target, int keyCode) {
int modifier = 0;
switch (keyCode) {
@@ -169,26 +221,23 @@ public class Keyboard implements KeyListener {
return pressed;
}
+ /**
+ * Creates a Release type KeyEvent
+ * @param target
+ * @param keyCode
+ * @return
+ */
private KeyEvent createKeyRelease(Component target, int keyCode) {
- @SuppressWarnings("unused")
- int modifier = 0;
- switch (keyCode) {
- case KeyEvent.VK_SHIFT:
- modifier = KeyEvent.SHIFT_MASK;
- break;
- case KeyEvent.VK_ALT:
- modifier = KeyEvent.ALT_MASK;
- break;
- case KeyEvent.VK_CONTROL:
- modifier = KeyEvent.CTRL_MASK;
- break;
- }
KeyEvent released = new KeyEvent(target, KeyEvent.KEY_RELEASED,
pressTime + getRandom(), 0, keyCode, KeyEvent.CHAR_UNDEFINED);
return released;
}
+ /**
+ * Actually triggers sending of a given KeyEvent in the instance of KeyListeners' {@code component} field.
+ * @param e
+ */
public void sendKeyEvent(KeyEvent e) {
for (KeyListener kl : component.getKeyListeners()) {
if (kl instanceof Keyboard) {
@@ -210,16 +259,28 @@ public class Keyboard implements KeyListener {
}
}
+ /**
+ * Allows the {@code KeyListener.keyPressed} event to be overridden.
+ * @param e
+ */
@Override
public void keyPressed(KeyEvent e) {
}
+ /**
+ * Allows the {@code KeyListener.keyReleased} event to be overridden.
+ * @param e
+ */
@Override
public void keyReleased(KeyEvent e) {
}
+ /**
+ * Allows the {@code KeyListener.keyTyped} event to be overridden.
+ * @param e
+ */
@Override
public void keyTyped(KeyEvent e) {
diff --git a/src/main/java/org/parabot/environment/scripts/Frameworks.java b/src/main/java/org/parabot/environment/scripts/Frameworks.java
deleted file mode 100644
index af5d40f..0000000
--- a/src/main/java/org/parabot/environment/scripts/Frameworks.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package org.parabot.environment.scripts;
-
-import org.parabot.environment.scripts.framework.AbstractFramework;
-import org.parabot.environment.scripts.framework.LoopTask;
-import org.parabot.environment.scripts.framework.Strategy;
-
-import java.util.Collection;
-
-/**
- * Holds various script frameworks
- *
- * @author Everel
- */
-public class Frameworks {
-
- public static Looper getLooper(LoopTask loopTask) {
- return new Looper(loopTask);
- }
-
- public static StrategyWorker getStrategyWorker(Collection