essential-actions

Clone or download

Merge pull request #17 from prubiella/hotkey-doc

#14 - Documentation, table mapping between keyboard and hotkey namings

Modified Files

# Hotkey Action plugin
This plugin allows map and execute keyboard shortcuts
## KeyBoard Mapping Reference to Hotkeyaction
The following table shows the relation between our keyboard and what we have to type on the plugin field to fire the hotkeys we want:
Hotkey mapping plugin | Keyboard Key |
--------------------- | ------------ |
A | A |
B | B |
C | C |
D | D |
E | E |
F | F |
G | G |
H | H |
I | I |
J | J |
K | K |
L | L |
M | M |
N | N |
O | O |
P | P |
Q | Q |
R | R |
S | S |
T | T |
U | U |
V | V |
W | W |
X | X |
Y | Y |
Z | Z |
` | ` |
0 | 0 |
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 5 |
6 | 6 |
7 | 7 |
8 | 8 |
9 | 9 |
\- | - |
= | = |
~ | ~ |
! | ! |
@ | @ |
\# | # |
$ | $ |
^ | ^ |
& | & |
\* | * |
( | ( |
) | ) |
\_ | _ |
\+ | + |
TAB | TAB |
\[ | \[ |
] | ] |
\\ | \\ |
{ | { |
} | } |
\| | \| |
\; | ; |
\: | : |
\ | \ |
, | , |
\< | < |
\. | . |
\> | > |
/ | / |
" " | " " |
WINDOWS | WIN |
SUPER | SUPER |
COMMAND | COMMAND |
WIN | WIN |
META | META |
SHIFT | SHIFT |
ALT | ALT |
F1 | F1 |
F2 | F2 |
F3 | F3 |
F4 | F4 |
F5 | F5 |
F6 | F6 |
F7 | F7 |
F8 | F8 |
F9 | F9 |
F10 | F10 |
F11 | F11 |
F12 | F12 |
F13 | F13 |
F14 | F14 |
F15 | F15 |
F16 | F16 |
F17 | F17 |
F18 | F18 |
F19 | F19 |
F20 | F20 |
F21 | F21 |
F22 | F22 |
F23 | F23 |
F24 | F24 |
NUMPAD 0 | NUMPAD 0 |
NUMPAD 1 | NUMPAD 1 |
NUMPAD 2 | NUMPAD 2 |
NUMPAD 3 | NUMPAD 3 |
NUMPAD 4 | NUMPAD 4 |
NUMPAD 5 | NUMPAD 5 |
NUMPAD 6 | NUMPAD 6 |
NUMPAD 7 | NUMPAD 7 |
NUMPAD 8 | NUMPAD 8 |
NUMPAD 9 | NUMPAD 9 |
NUMBER SIGN | NUMBER SIGN |
HOME | HOME |
INSERT | INSERT |
PAGE UP | PAGE UP |
PAGE DOWN | PAGE DOWN |
END | END |
ENTER | ENTER |
DELETE | DELETE |
SCROLL LOCK | SCROLL LOCK |
PRINT SCREEN | PRINT SCREEN |
PAUSE | PAUSE |
NUM LOCK | NUM LOCK |
CONTROL | CONTROL |
CAPS LOCK | CAPS LOCK |
NUM UP | NUM UP |
ARROW UP | UP |
NUM LEFT | NUM LEFT |
ARROW LEFT | LEFT |
ALT GRAPH | ALT GRAPH |
NUM RIGHT | NUM RIGHT |
ARROW RIGHT | RIGHT |
NUM DOWN | NUM DOWN |
ARROW DOWN | DOWN |
## Usage
To create a new hotkey, just drag the hotkey feature to the desired button and in the field `Key combination (separate using comma)` just type your combination.
Example: in ubuntu 20.04 for opening terminal just type `CONTROL,ALT,T`
## Known issues:
- `WINDOWS` or `SUPER` or `META` key in Linux distros does not work.
package com.stream_pi.hotkeyaction;
package com.stream_pi.hotkeyaction;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.normalaction.NormalAction;
import com.stream_pi.action_api.normalaction.NormalAction;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCode;
import javafx.scene.robot.Robot;
import javafx.scene.robot.Robot;
import java.util.ArrayList;
import java.util.ArrayList;
import static javafx.scene.input.KeyCode.*;
import static javafx.scene.input.KeyCode.*;
public class HotkeyAction extends NormalAction {
public class HotkeyAction extends NormalAction {
public HotkeyAction()
public HotkeyAction()
{
{
setName("Hotkey");
setName("Hotkey");
setCategory("Essentials");
setCategory("Essentials");
setAuthor("rnayabed");
setAuthor("rnayabed");
setServerButtonGraphic("far-keyboard");
setServerButtonGraphic("far-keyboard");
setHelpLink("https://github.com/Stream-Pi/EssentialActions");
setHelpLink("https://github.com/prubiella/essentialactions/tree/master/hotkeyaction/README.md");
setVersion(new Version(1,0,0));
setVersion(new Version(1,0,0));
}
}
@Override
@Override
public void initProperties() throws Exception {
public void initProperties() throws Exception {
Property keyCombination = new Property("key_comb", Type.STRING);
Property keyCombination = new Property("key_comb", Type.STRING);
keyCombination.setDisplayName("Key combination (Separate using comma)");
keyCombination.setDisplayName("Key combination (Separate using comma)");
addClientProperties(keyCombination);
addClientProperties(keyCombination);
}
}
private Robot robot;
private Robot robot;
@Override
@Override
public void initAction() throws Exception {
public void initAction() throws Exception {
Platform.runLater(()->robot = new Robot());
Platform.runLater(()->robot = new Robot());
}
}
@Override
@Override
public void onActionClicked() throws Exception
public void onActionClicked() throws Exception
{
{
Property keyCombination = getClientProperties().getSingleProperty("key_comb");
Property keyCombination = getClientProperties().getSingleProperty("key_comb");
if(keyCombination.getStringValue().isBlank())
if(keyCombination.getStringValue().isBlank())
{
{
throw new MinorException("No key specified");
throw new MinorException("No key specified");
}
}
press(keyCombination.getStringValue()
press(keyCombination.getStringValue()
.toUpperCase()
.toUpperCase()
.replace("?","SHIFT,/")
.replace("?","SHIFT,/")
.split(",")
.split(",")
);
);
}
}
public void press(String[] characters) throws InterruptedException {
public void press(String[] characters) throws InterruptedException {
ArrayList<KeyCode> pressedChars = new ArrayList<>();
ArrayList<KeyCode> pressedChars = new ArrayList<>();
try{
try{
for (String s : characters) {
for (String s : characters) {
KeyCode vkValue = getKeyCodeValue(s.trim());
KeyCode vkValue = getKeyCodeValue(s.trim());
press(vkValue);
press(vkValue);
Thread.sleep(50);
Thread.sleep(50);
pressedChars.add(vkValue);
pressedChars.add(vkValue);
}
}
}
}
finally
finally
{
{
releaseCharacters(pressedChars);
releaseCharacters(pressedChars);
}
}
}
}
private void releaseCharacters(ArrayList<KeyCode> chars) throws InterruptedException
private void releaseCharacters(ArrayList<KeyCode> chars) throws InterruptedException
{
{
for(KeyCode c : chars)
for(KeyCode c : chars)
{
{
release(c);
release(c);
Thread.sleep(50);
Thread.sleep(50);
}
}
}
}
public KeyCode getKeyCodeValue(String character) throws IllegalArgumentException
public KeyCode getKeyCodeValue(String character) throws IllegalArgumentException
{
{
switch (character) {
switch (character) {
case "A": return A;
case "A": return A;
case "B": return B;
case "B": return B;
case "C": return C;
case "C": return C;
case "D": return D;
case "D": return D;
case "E": return E;
case "E": return E;
case "F": return F;
case "F": return F;
case "G": return G;
case "G": return G;
case "H": return H;
case "H": return H;
case "I": return I;
case "I": return I;
case "J": return J;
case "J": return J;
case "K": return K;
case "K": return K;
case "L": return L;
case "L": return L;
case "M": return M;
case "M": return M;
case "N": return N;
case "N": return N;
case "O": return O;
case "O": return O;
case "P": return P;
case "P": return P;
case "Q": return Q;
case "Q": return Q;
case "R": return R;
case "R": return R;
case "S": return S;
case "S": return S;
case "T": return T;
case "T": return T;
case "U": return U;
case "U": return U;
case "V": return V;
case "V": return V;
case "W": return W;
case "W": return W;
case "X": return X;
case "X": return X;
case "Y": return Y;
case "Y": return Y;
case "Z": return Z;
case "Z": return Z;
case "`": return BACK_QUOTE;
case "`": return BACK_QUOTE;
case "0": return DIGIT0;
case "0": return DIGIT0;
case "1": return DIGIT1;
case "1": return DIGIT1;
case "2": return DIGIT2;
case "2": return DIGIT2;
case "3": return DIGIT3;
case "3": return DIGIT3;
case "4": return DIGIT4;
case "4": return DIGIT4;
case "5": return DIGIT5;
case "5": return DIGIT5;
case "6": return DIGIT6;
case "6": return DIGIT6;
case "7": return DIGIT7;
case "7": return DIGIT7;
case "8": return DIGIT8;
case "8": return DIGIT8;
case "9": return DIGIT9;
case "9": return DIGIT9;
case "-": return MINUS;
case "-": return MINUS;
case "=": return EQUALS;
case "=": return EQUALS;
case "~": return BACK_QUOTE;
case "~": return BACK_QUOTE;
case "!": return EXCLAMATION_MARK;
case "!": return EXCLAMATION_MARK;
case "@": return AT;
case "@": return AT;
case "#": return NUMBER_SIGN;
case "#": return NUMBER_SIGN;
case "$": return DOLLAR;
case "$": return DOLLAR;
case "^": return CIRCUMFLEX;
case "^": return CIRCUMFLEX;
case "&": return AMPERSAND;
case "&": return AMPERSAND;
case "*": return ASTERISK;
case "*": return ASTERISK;
case "(": return LEFT_PARENTHESIS;
case "(": return LEFT_PARENTHESIS;
case ")": return RIGHT_PARENTHESIS;
case ")": return RIGHT_PARENTHESIS;
case "_": return UNDERSCORE;
case "_": return UNDERSCORE;
case "+": return PLUS;
case "+": return PLUS;
case "TAB": return TAB;
case "TAB": return TAB;
case "[": return OPEN_BRACKET;
case "[": return OPEN_BRACKET;
case "]": return CLOSE_BRACKET;
case "]": return CLOSE_BRACKET;
case "\\": return BACK_SLASH;
case "{": return OPEN_BRACKET;
case "{": return OPEN_BRACKET;
case "}": return CLOSE_BRACKET;
case "}": return CLOSE_BRACKET;
case "|": return BACK_SLASH;
case "|": return PIPE;
case ";": return SEMICOLON;
case ";": return SEMICOLON;
case ":": return COLON;
case ":": return COLON;
case "\"": return BACK_SLASH;
case "\\": return BACK_SLASH;
case "\"": return QUOTE;
case ",": return COMMA;
case ",": return COMMA;
case "<": return LESS;
case "<": return LESS;
case ".": return PERIOD;
case ".": return PERIOD;
case ">": return GREATER;
case ">": return GREATER;
case "/": return SLASH;
case "/": return SLASH;
case " ": return SPACE;
case " ": return SPACE;
case "WIN":
case "WIN":
case "WINDOWS":
case "WINDOWS":
case "SUPER":
case "SUPER":
case "COMMAND":
case "COMMAND":
return WINDOWS;
return WINDOWS;
case "META":
case "META":
return META;
return META;
case "SHIFT":
case "SHIFT":
return SHIFT;
return SHIFT;
case "ALT": return ALT;
case "ALT": return ALT;
case "F1": return F1;
case "F1": return F1;
case "F2": return F2;
case "F2": return F2;
case "F3": return F3;
case "F3": return F3;
case "F4": return F4;
case "F4": return F4;
case "F5": return F5;
case "F5": return F5;
case "F6": return F6;
case "F6": return F6;
case "F7": return F7;
case "F7": return F7;
case "F8": return F8;
case "F8": return F8;
case "F9": return F9;
case "F9": return F9;
case "F10": return F10;
case "F10": return F10;
case "F11": return F11;
case "F11": return F11;
case "F12": return F12;
case "F12": return F12;
case "F13": return F13;
case "F13": return F13;
case "F14": return F14;
case "F14": return F14;
case "F15": return F15;
case "F15": return F15;
case "F16": return F16;
case "F16": return F16;
case "F17": return F17;
case "F17": return F17;
case "F18": return F18;
case "F18": return F18;
case "F19": return F19;
case "F19": return F19;
case "F20": return F20;
case "F20": return F20;
case "F21": return F21;
case "F21": return F21;
case "F22": return F22;
case "F22": return F22;
case "F23": return F23;
case "F23": return F23;
case "F24": return F24;
case "F24": return F24;
case "NUMPAD 0": return NUMPAD0;
case "NUMPAD 0": return NUMPAD0;
case "NUMPAD 1": return NUMPAD1;
case "NUMPAD 1": return NUMPAD1;
case "NUMPAD 2": return NUMPAD2;
case "NUMPAD 2": return NUMPAD2;
case "NUMPAD 3": return NUMPAD3;
case "NUMPAD 3": return NUMPAD3;
case "NUMPAD 4": return NUMPAD4;
case "NUMPAD 4": return NUMPAD4;
case "NUMPAD 5": return NUMPAD5;
case "NUMPAD 5": return NUMPAD5;
case "NUMPAD 6": return NUMPAD6;
case "NUMPAD 6": return NUMPAD6;
case "NUMPAD 7": return NUMPAD7;
case "NUMPAD 7": return NUMPAD7;
case "NUMPAD 8": return NUMPAD8;
case "NUMPAD 8": return NUMPAD8;
case "NUMPAD 9": return NUMPAD9;
case "NUMPAD 9": return NUMPAD9;
case "NUMBER SIGN": return NUMBER_SIGN;
case "NUMBER SIGN": return NUMBER_SIGN;
case "HOME": return HOME;
case "HOME": return HOME;
case "INSERT": return INSERT;
case "INSERT": return INSERT;
case "PAGE UP": return PAGE_UP;
case "PAGE UP": return PAGE_UP;
case "PAGE DOWN": return PAGE_DOWN;
case "PAGE DOWN": return PAGE_DOWN;
case "END": return END;
case "END": return END;
case "ENTER": return ENTER;
case "ENTER": return ENTER;
case "DELETE": return DELETE;
case "DELETE": return DELETE;
case "SCROLL LOCK": return SCROLL_LOCK;
case "SCROLL LOCK": return SCROLL_LOCK;
case "PRINT SCREEN": return PRINTSCREEN;
case "PRINT SCREEN": return PRINTSCREEN;
case "PAUSE": return PAUSE;
case "PAUSE": return PAUSE;
case "NUM LOCK": return NUM_LOCK;
case "NUM LOCK": return NUM_LOCK;
case "CONTROL": return CONTROL;
case "CONTROL": return CONTROL;
case "CAPS LOCK": return CAPS;
case "CAPS LOCK": return CAPS;
case "NUM UP": return KP_UP;
case "NUM UP": return KP_UP;
case "UP": return UP;
case "UP": return UP;
case "NUM LEFT": return KP_LEFT;
case "NUM LEFT": return KP_LEFT;
case "LEFT": return LEFT;
case "LEFT": return LEFT;
case "ALT GRAPH": return ALT_GRAPH;
case "ALT GRAPH": return ALT_GRAPH;
case "NUM RIGHT": return KP_RIGHT;
case "NUM RIGHT": return KP_RIGHT;
case "RIGHT": return RIGHT;
case "RIGHT": return RIGHT;
case "NUM DOWN": return KP_DOWN;
case "NUM DOWN": return KP_DOWN;
case "DOWN": return DOWN;
case "DOWN": return DOWN;
default:
default:
throw new IllegalArgumentException("Cannot press character " + character);
throw new IllegalArgumentException("Cannot press character " + character);
}
}
}
}
private void press(KeyCode keyCode)
private void press(KeyCode keyCode)
{
{
Platform.runLater(()->robot.keyPress(keyCode));
Platform.runLater(()->robot.keyPress(keyCode));
}
}
private void release(KeyCode keyCode)
private void release(KeyCode keyCode)
{
{
Platform.runLater(()->robot.keyRelease(keyCode));
Platform.runLater(()->robot.keyRelease(keyCode));
}
}
@Override
@Override
public void onShutDown() throws Exception {
public void onShutDown() throws Exception {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
}
}
}
}