mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 15:29:26 +00:00
Macro Record service added. RobotKeys.md added for future translations.
This commit is contained in:
parent
e03405dfb0
commit
d1058dfc17
2 changed files with 223 additions and 0 deletions
106
fe/src/services/MacroRecordService.js
Normal file
106
fe/src/services/MacroRecordService.js
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
const keyMap = {
|
||||
// Modifier keys
|
||||
Control: 'Ctrl',
|
||||
Shift: 'Shift',
|
||||
Alt: 'Alt',
|
||||
Meta: 'Win',
|
||||
CapsLock: 'Caps',
|
||||
// Special keys
|
||||
PageUp: 'PgUp',
|
||||
PageDown: 'PgDn',
|
||||
ScrollLock: 'Scr Lk',
|
||||
Insert: 'Ins',
|
||||
Delete: 'Del',
|
||||
Escape: 'Esc',
|
||||
Space: 'Space',
|
||||
// Symbol keys
|
||||
Backquote: '`',
|
||||
Backslash: '\\',
|
||||
BracketLeft: '[',
|
||||
BracketRight: ']',
|
||||
Comma: ',',
|
||||
Equal: '=',
|
||||
Minus: '-',
|
||||
Period: '.',
|
||||
Quote: "'",
|
||||
Semicolon: ';',
|
||||
Slash: '/',
|
||||
// Arrow keys
|
||||
ArrowUp: '▲',
|
||||
ArrowRight: '▶',
|
||||
ArrowDown: '▼',
|
||||
ArrowLeft: '◀',
|
||||
// Media keys
|
||||
MediaPlayPause: 'Play',
|
||||
MediaStop: 'Stop',
|
||||
MediaTrackNext: 'Next',
|
||||
MediaTrackPrevious: 'Prev',
|
||||
MediaVolumeDown: 'Down',
|
||||
MediaVolumeUp: 'Up',
|
||||
AudioVolumeMute: 'Mute',
|
||||
AudioVolumeDown: 'Down',
|
||||
AudioVolumeUp: 'Up',
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters a keyboard event and returns an object with two properties:
|
||||
* loc (optional) and str.
|
||||
* loc is the location of the key (either 'left', 'right', or 'num').
|
||||
* str is the string representation of the key (e.g. 'a', 'A', 'Enter', etc.).
|
||||
* If the key is a modifier key, it is represented by its name (e.g. 'Ctrl', 'Shift', etc.).
|
||||
* If the key is not a modifier key, it is represented by its character (e.g. 'a', 'A', etc.).
|
||||
* If the key is not a character key, it is represented by its symbol (e.g. ',', '.', etc.).
|
||||
* @param {KeyboardEvent} e - The keyboard event to filter.
|
||||
* @return {Object} An object with two properties: loc (optional) and str.
|
||||
*/
|
||||
export const filterKey = (e) => {
|
||||
const k = {} // Object k (key)
|
||||
|
||||
// If location is set, set loc (location)
|
||||
if (e.location === 1) k.loc = 'left'
|
||||
if (e.location === 2) k.loc = 'right'
|
||||
if (e.location === 3) k.loc = 'num'
|
||||
|
||||
if (e.key.includes('Media') || e.key.includes('Audio')) k.loc = mediaPrefix(e)
|
||||
|
||||
// If code is in keyMap, set str by code
|
||||
if (keyMap[e.code] || keyMap[e.key]) {
|
||||
k.str = keyMap[e.code] || keyMap[e.key]
|
||||
} else {
|
||||
// If code is not in keyMap, set str by e.key
|
||||
k.str = e.key.toLowerCase()
|
||||
}
|
||||
|
||||
// return k object
|
||||
return k
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string prefix for the given media key.
|
||||
* @param {KeyboardEvent} e - The keyboard event to get the prefix for.
|
||||
* @return {string} The prefix for the key (either 'Media' or 'Volume').
|
||||
*/
|
||||
const mediaPrefix = (e) => {
|
||||
switch (e.key) {
|
||||
case 'MediaPlayPause':
|
||||
case 'MediaStop':
|
||||
case 'MediaTrackNext':
|
||||
case 'MediaTrackPrevious':
|
||||
return 'Media'
|
||||
case 'MediaVolumeDown':
|
||||
case 'MediaVolumeUp':
|
||||
case 'AudioVolumeDown':
|
||||
case 'AudioVolumeUp':
|
||||
case 'AudioVolumeMute':
|
||||
return 'Volume'
|
||||
}
|
||||
}
|
||||
|
||||
export const isRepeat = (lastStep, e, direction) => {
|
||||
return (
|
||||
lastStep &&
|
||||
lastStep.type === 'key' &&
|
||||
lastStep.code === e.code &&
|
||||
lastStep.direction === direction
|
||||
)
|
||||
}
|
||||
117
fe/src/services/RobotKeys.md
Normal file
117
fe/src/services/RobotKeys.md
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
"A-Z a-z 0-9"
|
||||
|
||||
"backspace"
|
||||
"delete"
|
||||
"enter"
|
||||
"tab"
|
||||
"esc"
|
||||
"escape"
|
||||
"up" Up arrow key
|
||||
"down" Down arrow key
|
||||
"right" Right arrow key
|
||||
"left" Left arrow key
|
||||
"home"
|
||||
"end"
|
||||
"pageup"
|
||||
"pagedown"
|
||||
|
||||
"f1"
|
||||
"f2"
|
||||
"f3"
|
||||
"f4"
|
||||
"f5"
|
||||
"f6"
|
||||
"f7"
|
||||
"f8"
|
||||
"f9"
|
||||
"f10"
|
||||
"f11"
|
||||
"f12"
|
||||
"f13"
|
||||
"f14"
|
||||
"f15"
|
||||
"f16"
|
||||
"f17"
|
||||
"f18"
|
||||
"f19"
|
||||
"f20"
|
||||
"f21"
|
||||
"f22"
|
||||
"f23"
|
||||
"f24"
|
||||
|
||||
"cmd" is the "win" key for windows
|
||||
"lcmd" left command
|
||||
"rcmd" right command
|
||||
// "command"
|
||||
"alt"
|
||||
"lalt" left alt
|
||||
"ralt" right alt
|
||||
"ctrl"
|
||||
"lctrl" left ctrl
|
||||
"rctrl" right ctrl
|
||||
"control"
|
||||
"shift"
|
||||
"lshift" left shift
|
||||
"rshift" right shift
|
||||
// "right_shift"
|
||||
"capslock"
|
||||
"space"
|
||||
"print"
|
||||
"printscreen" // No Mac support
|
||||
"insert"
|
||||
"menu" Windows only
|
||||
|
||||
"audio_mute" Mute the volume
|
||||
"audio_vol_down" Lower the volume
|
||||
"audio_vol_up" Increase the volume
|
||||
"audio_play"
|
||||
"audio_stop"
|
||||
"audio_pause"
|
||||
"audio_prev" Previous Track
|
||||
"audio_next" Next Track
|
||||
"audio_rewind" Linux only
|
||||
"audio_forward" Linux only
|
||||
"audio_repeat" Linux only
|
||||
"audio_random" Linux only
|
||||
|
||||
|
||||
"num0"
|
||||
"num1"
|
||||
"num2"
|
||||
"num3"
|
||||
"num4"
|
||||
"num5"
|
||||
"num6"
|
||||
"num7"
|
||||
"num8"
|
||||
"num9"
|
||||
"num_lock"
|
||||
|
||||
"num."
|
||||
"num+"
|
||||
"num-"
|
||||
"num*"
|
||||
"num/"
|
||||
"num_clear"
|
||||
"num_enter"
|
||||
"num_equal"
|
||||
|
||||
// // "numpad_0" No Linux support
|
||||
// "numpad_0"
|
||||
// "numpad_1"
|
||||
// "numpad_2"
|
||||
// "numpad_3"
|
||||
// "numpad_4"
|
||||
// "numpad_5"
|
||||
// "numpad_6"
|
||||
// "numpad_7"
|
||||
// "numpad_8"
|
||||
// "numpad_9"
|
||||
// "numpad_lock"
|
||||
|
||||
"lights_mon_up" Turn up monitor brightness No Windows support
|
||||
"lights_mon_down" Turn down monitor brightness No Windows support
|
||||
"lights_kbd_toggle" Toggle keyboard backlight on/off No Windows support
|
||||
"lights_kbd_up" Turn up keyboard backlight brightness No Windows support
|
||||
"lights_kbd_down" Turn down keyboard backlight brightness No Windows support
|
||||
Loading…
Add table
Add a link
Reference in a new issue