essential-actions

Clone or download

#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 | Key Value
--------------------- | ------------ | ---------
A | A | A
B | B | B
C | C | C
D | D | D
E | E | E
F | F | F
G | G | G
H | H | H
I | I | I
J | J | J
K | K | K
L | L | L
M | M | M
N | N | N
O | O | O
P | P | P
Q | Q | Q
R | R | R
S | S | S
T | T | T
U | U | U
V | V | V
W | W | W
X | X | X
Y | Y | Y
Z | Z | Z
` | ` | BACK_QUOTE
0 | 0 | DIGIT0
1 | 1 | DIGIT1
2 | 2 | DIGIT2
3 | 3 | DIGIT3
4 | 4 | DIGIT4
5 | 5 | DIGIT5
6 | 6 | DIGIT6
7 | 7 | DIGIT7
8 | 8 | DIGIT8
9 | 9 | DIGIT9
\- | - | MINUS
= | = | EQUALS
~ | ~ | BACK_QUOTE
! | ! | EXCLAMATION_MARK
@ | @ | AT
\# | # | NUMBER_SIGN
$ | $ | DOLLAR
^ | ^ | CIRCUMFLEX
& | & | AMPERSAND
\* | * | ASTERISK
( | ( | LEFT_PARENTHESIS
) | ) | RIGHT_PARENTHESIS
\_ | _ | UNDERSCORE
\+ | + | PLUS
TAB | TAB | TAB
[ | [ | OPEN_BRACKET
] | ] | CLOSE_BRACKET
\\ | \\ | BACK_SLASH
{ | { | OPEN_BRACKET
} | } | CLOSE_BRACKET
\| | \| | PIPE
\; | ; | SEMICOLON
\: | : | COLON
\ | \ | BACK_SLASH
, | , | COMMA
\< | < | LESS
\. | . | PERIOD
\> | > | GREATER
/ | / | SLASH
" " | " " | SPACE
WIN\|WINDOWS\|SUPER\|COMMAND | WINDOWS | WINDOWS
META | `dont know` | `dont know`
SHIFT | SHIFT | SHIFT
ALT | ALT | ALT
F1 | F1 | F1
F2 | F2 | F2
F3 | F3 | F3
F4 | F4 | F4
F5 | F5 | F5
F6 | F6 | F6
F7 | F7 | F7
F8 | F8 | F8
F9 | F9 | F9
F10 | F10 | F10
F11 | F11 | F11
F12 | F12 | F12
F13 | F13 | F13
F14 | F14 | F14
F15 | F15 | F15
F16 | F16 | F16
F17 | F17 | F17
F18 | F18 | F18
F19 | F19 | F19
F20 | F20 | F20
F21 | F21 | F21
F22 | F22 | F22
F23 | F23 | F23
F24 | F24 | F24
NUMPAD 0 | NUMPAD 0 | NUMPAD0
NUMPAD 1 | NUMPAD 1 | NUMPAD1
NUMPAD 2 | NUMPAD 2 | NUMPAD2
NUMPAD 3 | NUMPAD 3 | NUMPAD3
NUMPAD 4 | NUMPAD 4 | NUMPAD4
NUMPAD 5 | NUMPAD 5 | NUMPAD5
NUMPAD 6 | NUMPAD 6 | NUMPAD6
NUMPAD 7 | NUMPAD 7 | NUMPAD7
NUMPAD 8 | NUMPAD 8 | NUMPAD8
NUMPAD 9 | NUMPAD 9 | NUMPAD9
NUMBER SIGN | NUMBER SIGN | NUMBER_SIGN
HOME | HOME | HOME
INSERT | INSERT | INSERT
PAGE UP | PAGE UP | PAGE_UP
PAGE DOWN | PAGE DOWN | PAGE_DOWN
END | END | END
ENTER | ENTER | ENTER
DELETE | DELETE | DELETE
SCROLL LOCK | SCROLL LOCK | SCROLL_LOCK
PRINT SCREEN | PRINT SCREEN | PRINTSCREEN
PAUSE | PAUSE | PAUSE
NUM LOCK | NUM LOCK | NUM_LOCK
CONTROL | CONTROL | CONTROL
CAPS LOCK | CAPS LOCK | CAPS
NUM UP | NUM UP | KP_UP
UP | UP | UP
NUM LEFT | NUM LEFT | KP_LEFT
LEFT | LEFT | LEFT
ALT GRAPH | ALT GRAPH | ALT_GRAPH
NUM RIGHT | NUM RIGHT | KP_RIGHT
RIGHT | RIGHT | RIGHT
NUM DOWN | NUM DOWN | KP_DOWN
DOWN | 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 bugs:
- Windows key in Linux distros is not working for any keymap.
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/Stream-Pi/EssentialActions/hotkeyaction");
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
}
}
}
}