From: Debayan Sutradhar Date: Mon, 31 May 2021 19:54:30 +0530 Subject: [hotkeyaction] - Clean up, refactored to use new Action API --- [hotkeyaction] - Clean up, refactored to use new Action API --- --- 'a/hotkeyaction/.gitignore' +++ b/hotkeyaction/.gitignore @@ -1,5 +1,5 @@ .idea/ -HotkeyAction.iml +*.iml target/ --- 'a/hotkeyaction/pom.xml' +++ b/hotkeyaction/pom.xml @@ -6,7 +6,7 @@ com.stream-pi hotkeyaction - 2.0.0 + 2.0.1 @@ -39,15 +39,9 @@ 1.0.0-SNAPSHOT 1.0.0-SNAPSHOT - - 16 - UTF-8 11 11 - - 11.5.0 - 11.5.0 @@ -62,17 +56,5 @@ action-api ${ActionAPIVersion} - - - org.kordamp.ikonli - ikonli-fontawesome5-pack - ${IkonliFA5PackVersion} - - - - org.kordamp.ikonli - ikonli-javafx - ${IkonliVersion} - \ No newline at end of file --- 'a/hotkeyaction/src/main/java/com/stream_pi/hotkeyaction/HotkeyAction.java' +++ b/hotkeyaction/src/main/java/com/stream_pi/hotkeyaction/HotkeyAction.java @@ -23,11 +23,12 @@ public class HotkeyAction extends Normal setAuthor("rnayabed"); setServerButtonGraphic("far-keyboard"); setHelpLink("https://github.com/stream-pi/essentialactions/blob/master/hotkeyaction/README.md"); - setVersion(new Version(2,0,0)); + setVersion(new Version(2,0,1)); } @Override - public void initProperties() throws Exception { + public void initProperties() + { Property keyCombination = new Property("key_comb", Type.STRING); keyCombination.setDisplayName("Key combination (Separate using comma)"); @@ -38,12 +39,13 @@ public class HotkeyAction extends Normal private Robot robot; @Override - public void initAction() throws Exception { + public void initAction() + { Platform.runLater(()->robot = new Robot()); } @Override - public void onActionClicked() throws Exception + public void onActionClicked() throws MinorException { Property keyCombination = getClientProperties().getSingleProperty("key_comb"); @@ -52,15 +54,24 @@ public class HotkeyAction extends Normal throw new MinorException("No key specified"); } - press(keyCombination.getStringValue() - .toUpperCase() - .replace("?","SHIFT,/") - .replace("|","SHIFT,\\") - .split(",") - ); + try + { + press(keyCombination.getStringValue() + .toUpperCase() + .replace("?","SHIFT,/") + .replace("|","SHIFT,\\") + .split(",") + ); + } + catch (InterruptedException e) + { + e.printStackTrace(); + throw new MinorException("Interrupted while press called. \n"+e.getMessage()); + } } - public void press(String[] characters) throws InterruptedException { + public void press(String[] characters) throws InterruptedException + { ArrayList pressedChars = new ArrayList<>(); @@ -116,7 +127,9 @@ public class HotkeyAction extends Normal case "X": return X; case "Y": return Y; case "Z": return Z; - case "`": return BACK_QUOTE; + case "`": + case "~": + return BACK_QUOTE; case "0": return DIGIT0; case "1": return DIGIT1; case "2": return DIGIT2; @@ -128,8 +141,7 @@ public class HotkeyAction extends Normal case "8": return DIGIT8; case "9": return DIGIT9; case "-": return MINUS; - case "=": return EQUALS; - case "~": return BACK_QUOTE; + case "=": return EQUALS; case "!": return EXCLAMATION_MARK; case "@": return AT; case "#": return NUMBER_SIGN; @@ -142,10 +154,8 @@ public class HotkeyAction extends Normal case "_": return UNDERSCORE; case "+": return PLUS; case "TAB": return TAB; - case "[": return OPEN_BRACKET; - case "]": return CLOSE_BRACKET; - case "{": return OPEN_BRACKET; - case "}": return CLOSE_BRACKET; + case "[": case "{" : return OPEN_BRACKET; + case "]": case "}" : return CLOSE_BRACKET; case ";": return SEMICOLON; case ":": return COLON; case "\\": return BACK_SLASH; @@ -305,11 +315,5 @@ public class HotkeyAction extends Normal { Platform.runLater(()->robot.keyRelease(keyCode)); } - - @Override - public void onShutDown() throws Exception { - // TODO Auto-generated method stub - - } }