-
Notifications
You must be signed in to change notification settings - Fork 35
Guide to layout scripting
You can make keyboard layout with KeyMagic layout script language.
- Headers
- Variables
- Rules
- VirtualKeys
- String Index
- Using matched context in output
- NULL Output
- Match Any
- Not Of
- Switch
- Comments
- Escape in string
- Joining Lines
Description: Headers are used to define keyboard layout descriptions, layout settings and icon path. And they needed to be in comment block.
Syntax: @%name = %value
/**
@Name = "A Smart Unicode Keyboard Layout"
@Description = "This is keyboard description"
@TRACK_CAPSLOCK = "false"
@EAT_KEYS = "true"
@US_LAYOUT_BASED = "true"
@SMART_BACKSPACE = "true"
@TREAT_CTRL_ALT_AS_RALT = "true"
**/
-
Name: Name of keyboard layout.
*
Implemented from v1.4 -
Icon: Full path or relative path of icon file.
*
Implemented from v1.4 -
Description: Description of the keyboard.
*
Implemented from v1.4 - TRACK_CAPSLOCK: Setting false to this option will ignore caps locks key. (default: true)
- SMART_BACKSPACE: Backspace will acts as undo key that will restore to the most recent state before last user input. (default: false)
- EAT_KEYS: When this option is true, any undefined keys will not have any output. (default: false)
- US_LAYOUT_BASED: Key code values will be based on US Keyboard Layout. (default: false)
- TREAT_CTRL_ALT_AS_RALT: Pressing CTRL+ALT will be treat as RALT (ALT-Gr) (default: true)
Note: Options are case insensitive.
Dscription: Variables are used to store strings.
Syntax: $%name = %value
$vowels_cap = "AEIOU"
$vowels_small = 'aeiou'
$ka = U1000
You can also use declared variables in new variable declaration.
$vowels = $vowels_cap + $vowels_small
You can use both String and Unicode in a variable.
$AAA = "A" + U0040 + $vowles
Description: Rules are used to match the context what user type and how to customize the output.
Syntax: %pattern_to_be_match => %output_pattern
'a' => U1000
With the above rule, when user type 'a', the output will be U1000 (Myanmar က).
Description: Virtual keys are commonly used in LHS. Anyway, they could be used in the RHS too.
Syntax: < %vkcode [ & %vkcode ] >
%vkcode can be one of the VirtualCodes.
< VK_KEY_A > => U1000
The output will be U1000 (Myanmar က) when user type 'a'.
Note: All Virtual Key inside <> need to be pressed at the same time to successfully match the pattern.
< VK_CTRL & VK_SHIFT & VK_KEY_A > => U1000
Above pattern will be matched only when the user press CONTROL KEY, SHIFT KEY and A KEY.
Description: You can match one character from the string variable specifying index.
Syntax: $var[%n]
%n is the index of character.
$string = "ABCDE"
$string[1] => U1039
If you use *
instead of index, it will be considered as any of character from the string array.
$string[=> "You typed" + $1
When you used *
, index of matched letter in LHS can be used in RHS.
$small = 'zxcv'
$cap = 'ZXCV'
$small[*] => $cap[$1]
// z to Z, x to X
$small[*] + $small[*] => $1 + $cap[$2]
// zx to zX, cv to cV
$small[*] + $cap[*] => $1 + $small[$2] + $2
// zZ to zzZ
Description: You can use matched context of LHS in the RHS.
Syntax: %context [ + %context ] => %n [ + %n]
'will ' + 'this ' + 'swap' => $2 + $1 + $3
When the context is will this swap then the output will be this will swap
Description: Set the output to empty.
Syntax: %context => null
'Blacklis' + <VK_KEY_T> => NULL // Ex1
'I need this string to delete with single backspace' + <VK_BACK> => null // Ex2
Ex1: In this example, when the context is 'Blacklis' and typing 'T' will result in empty output. Ex2: This will delete whole string as soon as you type backspace.
Note: You can still use '' or "" to have null output. 'abc' => ''
Description: Use in the left side of the pattern. And used to match any character.
Syntax: [+ %context] => [%pattern]
'i' + * => 'I' + $2
Description: Used with string arrays (variables). Will match any character except from the string array.
Syntax: $var[^]
$vowels = 'aeiou'
$vowels[^] => $1 + ' is not a vowel'
Description: Switches are internal boolean(true/false) values. You could use switches as deadkey. After switch value is changed to TRUE, TRUE value only valid for next input.
Syntax: ('%switch_name')
'=' => ('myswitch') // When user type '=', switch named myswitch's value is TRUE
// following two rules will match only when value of myswitch is TRUE
'z' + ('myswitch') => 'zee' // myswitch's value is now FALSE and print 'zee'
'v' + ('myswitch') => 'vee' + ('myswitch') // myswitch's value is still TRUE and print 'vee'
//
: comment till the end of line.
/* */
: comment multiline.
$slash = '\\'
$d_quote = "\""
$aUnicode = "\u1000"
$vowels = 'aei' + \
'ou'
$vowels[*](^]) => \
'vowles'