FromEvent and map*()
map()
takes any valid full from event definition.
map({ key_code: 'a', modifiers: { mandatory: ['left_command'] } })
FromEvent type
export type FromEvent = (
| { key_code: string | number }
| { consumer_key_code: string | number }
| { pointing_button: string | number }
| { any: 'key_code' | 'consumer_key_code' | 'pointing_button' }
| { simultaneous: Array</*...*/>, simultaneous_options?: {/*...*/} }
) & {
modifiers?: { mandatory?: [/*...*/], optional?: [/*...*/] }
}
There are some useful methods to help create FromEvent
easier:
map(key)β
The most common FromEvent
is with key_code
. map(key)
also supports alias
for some key_code
and modifiers, like β
, β
, etc.
The list of supported key_code
can be found here.
map('a') // map(key_code)
map(',', 'left_command') // map(key_alias, mandatoryModifiers)
map(1, 'β', 'βͺ') // map(number_key_value, modifier_alias, modifier_alias)
map('β', { right: 'ββ₯' }) // map (key_alias, { left/right: modifier_alias})
map('left_command', { optional: 'β§' }) // map(key_code, { optional: modifiers })
map('keypad_asterisk', 'optionalAny') // map(key_code, 'optionalAny')
Generated JSON
// map('a')
{ "key_code": "a" }
// map(',', 'left_command')
{ "key_code": "comma", "modifiers": { "mandatory": [ "left_command"] } }
// map(1, 'β', 'βͺ')
{ "key_code": "1", "modifiers": { "mandatory": [ "command"], "optional": [ "caps_lock"] } }
// map('β', { right: 'ββ₯' })
{ "key_code": "left_arrow", "modifiers": { "mandatory": [ "right_command", "right_option"] } }
// map('left_command', { optional: 'β§' })
{ "key_code": "left_command", "modifiers": { "optional": [ "shift"] } }
// map('keypad_asterisk', 'optionalAny')
{ "key_code": "keypad_asterisk", "modifiers": { "optional": [ "any"] } }
Key aliasβ
The list of supported key alias can be found here,
Key alias
β command
β₯ option
β control
β§ shift
βͺ caps_lock
β up_arrow
β down_arrow
β left_arrow
β right_arrow
β page_up
β page_down
β home
β end
β return_or_enter
β escape
β« delete_or_backspace
β¦ delete_forward
β₯ tab
β£ spacebar
- hyphen
= equal_sign
[ open_bracket
] close_bracket
\ backslash
; semicolon
' quote
` grave_accent_and_tilde
, comma
. period
/ slash
It is recommended to put the alias on a layer/simlayer to use them.
Example of key alias on a layer
layer(['z', '/'], 'emoji-mode').manipulators([
// 1 2 3 4 5
withMapper(['β', 'β₯', 'β', 'β§', 'βͺ'])((k, i) =>
map((i + 1) as NumberKeyValue).toPaste(k),
),
// Paste the symbols instead of triggering the key
withMapper(['β', 'β', 'β', 'β', 'β£', 'β', 'β₯', 'β', 'β«', 'β¦', 'βͺ'])((k) =>
map(k).toPaste(k),
),
map(',').toPaste('βΉ'), // left_{modifier}
map('.').toPaste('βΊ'), // right_{modifier}
])
map('βΉβ')
,βΉβ
isleft_command
, can also be<β
,lβ
,leftβ
map(1, '??')
,??
isoptionalAny
, can also be?any
,{ optional: 'any' }
map(1, '?βΊββ₯')
,?βΊββ₯
is{ optional: ['right_command', 'right_option'] }
mapConsumerKey()β
mapConsumerKey()
is similar to map(key)
but with consumer_key_code
instead
of key_code
.
The list of supported consumer_key_code
can be found here.
mapConsumerKey('menu', 'β', 'any')
Generated JSON
{
"consumer_key_code": "menu",
"modifiers": { "mandatory": ["command"], "optional": ["any"] }
}
mapPointingButton()β
mapPointingButton()
is similar to map(key)
but with pointing_button
instead
of key_code
.
The list of supported pointing_button
can be found here.
mapPointingButton('button1', 'β')
Generated JSON
{
"pointing_button": "button1",
"modifiers": { "mandatory": ["command"] }
}
mapSimultaneous()β
mapSimultaneous()
creates from.simultaneous
with (optional) options and threshold parameter.
mapSimultaneous(
['a', { pointing_button: 'button1' }], // keys
{ key_down_order: 'strict' }, // options?
100, // threshold?, default 50
)
Generated JSON
{
"type": "basic",
"from": {
"simultaneous": [
{"key_code": "a"},
{"pointing_button": "button1"}
],
"simultaneous_options": {
"key_down_order": "strict"
}
},
"parameters": {
"basic.simultaneous_threshold_milliseconds": 100
}
}
Modifiersβ
To set from.modifiers
use mapSimultaneous().modifiers(/* ... */)
.
Thresholdβ
The threshold parameter can also be set at writeToProfile()
for the profile.
writeToProfile(
'--dry-run', // profile name
[], // rules
{ 'basic.simultaneous_threshold_milliseconds': 100 }, // parameters
)