Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(developer): ldml scan codes support 🙀 #9615

Merged
merged 28 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5ddc8c8
chore(resources): ldml update keyboard -> keyboard3 🙀
srl295 Sep 22, 2023
6a54ebd
feat(developer): ldml scancodes 🙀
srl295 Sep 22, 2023
3a677da
feat(common): ldml scancodes 🙀
srl295 Sep 22, 2023
44f061f
feat(common): ldml scancodes 🙀
srl295 Sep 22, 2023
f56e4ff
feat(common): ldml scancodes 🙀
srl295 Sep 22, 2023
2726604
feat(common): ldml import infrastructure 🙀
srl295 Sep 25, 2023
87c18fd
feat(developer): scancode hint to warning 🙀
srl295 Sep 25, 2023
71aee7a
feat(common): scancode fixes for ks and iso 🙀
srl295 Sep 25, 2023
8774651
Merge branch 'master' into feat/developer/9403-scancodes-epic-ldml
srl295 Sep 25, 2023
2c588ed
feat(common): scancode fixes for ks and jis 🙀
srl295 Sep 25, 2023
1236ded
chore(resources): ldml update 🙀
srl295 Sep 28, 2023
bdef1c4
fix(common): update keyman for removal of vkeys 🙀
srl295 Sep 28, 2023
5fa99f5
fix(common): update keyman for removal of vkeys 🙀
srl295 Sep 28, 2023
518cc36
feat(common): scancode - skip test to validate prior changes🙀
srl295 Sep 28, 2023
623d679
Merge branch 'master' into feat/developer/9403-scancodes-epic-ldml
srl295 Sep 28, 2023
b2a8881
Merge branch 'master' into feat/developer/9403-scancodes-epic-ldml
srl295 Sep 28, 2023
6e2d858
feat(developer): ldml dynamic scancodes 🙀
srl295 Sep 28, 2023
968da50
feat(developer): ldml dynamic scancodes 🙀
srl295 Sep 28, 2023
b9f9d9c
feat(common): scancode - generate scancode.ts 🙀
srl295 Sep 30, 2023
4b9d7cb
feat(common): scancode - confirming that the calculated scancodes are…
srl295 Sep 30, 2023
64eaf39
chore(core): use sourcemaps when calling kmc for tests
srl295 Sep 30, 2023
ffe00c0
feat(common): scancode - move vkey map generation into KeysCompiler 🙀
srl295 Sep 30, 2023
f5ceac8
Merge branch 'master' into feat/developer/9403-scancodes-epic-ldml
srl295 Oct 1, 2023
17eba2d
feat(developer): scancode and forms 🙀
srl295 Oct 1, 2023
1b85166
Actualizar virtual-key-constants.ts
srl295 Oct 2, 2023
0cae964
Merge branch 'master' into feat/developer/9403-scancodes-epic-ldml
srl295 Oct 2, 2023
8200f84
feat(developer): scancode and forms 🙀
srl295 Oct 2, 2023
2b2661b
feat(developer): scancode and forms 🙀
srl295 Oct 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 81 additions & 116 deletions common/web/types/src/consts/virtual-key-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export const USVirtualKeyCodes = {
*/
K_oE2:226,
K_OE2:226,
k_oC1:193, // ISO B11, ABNT-2 key to left of right shift, not on US keyboard
k_OC1:193,
K_oC1:193, // ISO B11, ABNT-2 key to left of right shift, not on US keyboard
K_OC1:193,
'K_?C1':193,
'k_?C1':193,
K_oDF:0xDF,
Expand All @@ -144,125 +144,90 @@ export const USVirtualKeyCodes = {

const k = USVirtualKeyCodes;

export type KeyMap = number[][];
/** Map a CLDR scancode to a US VKey ala USVirtualKeyCodes */
export const CLDRScanToUSVirtualKeyCodes = {
0x02: k.K_1,
0x03: k.K_2,
0x04: k.K_3,
0x05: k.K_4,
0x06: k.K_5,
0x07: k.K_6,
0x08: k.K_7,
0x09: k.K_8,
0x0A: k.K_9,
0x0B: k.K_0,
0x0C: k.K_HYPHEN,
0x0D: k.K_EQUAL,

export const USVirtualKeyMap: KeyMap = [
// ` 1 2 3 4 5 6 7 8 9 0 - = [bksp]
[ k.K_BKQUOTE, k.K_1, k.K_2, k.K_3, k.K_4, k.K_5, k.K_6, k.K_7, k.K_8, k.K_9, k.K_0, k.K_HYPHEN, k.K_EQUAL ],
// [tab] Q W E R T Y U I O P [ ] \
[ k.K_Q, k.K_W, k.K_E, k.K_R, k.K_T, k.K_Y, k.K_U, k.K_I, k.K_O, k.K_P, k.K_LBRKT, k.K_RBRKT, k.K_BKSLASH ],
// [caps] A S D F G H J K L ; ' [enter]
[ k.K_A, k.K_S, k.K_D, k.K_F, k.K_G, k.K_H, k.K_J, k.K_K, k.K_L, k.K_COLON, k.K_QUOTE ],
// [shift] Z X C V B N M , . / [shift] *=oE2
[ k.K_Z, k.K_X, k.K_C, k.K_V, k.K_B, k.K_N, k.K_M, k.K_COMMA, k.K_PERIOD, k.K_SLASH ],
// space
[ k.K_SPACE ],
];
0x10: k.K_Q,
0x11: k.K_W,
0x12: k.K_E,
0x13: k.K_R,
0x14: k.K_T,
0x15: k.K_Y,
0x16: k.K_U,
0x17: k.K_I,
0x18: k.K_O,
0x19: k.K_P,
0x1A: k.K_LBRKT,
0x1B: k.K_RBRKT,

export const ISOVirtualKeyMap: KeyMap = [
// ` 1 2 3 4 5 6 7 8 9 0 - = [bksp]
[ k.K_BKQUOTE, k.K_1, k.K_2, k.K_3, k.K_4, k.K_5, k.K_6, k.K_7, k.K_8, k.K_9, k.K_0, k.K_HYPHEN, k.K_EQUAL ],
// [tab] Q W E R T Y U I O P [ ]
[ k.K_Q, k.K_W, k.K_E, k.K_R, k.K_T, k.K_Y, k.K_U, k.K_I, k.K_O, k.K_P, k.K_LBRKT, k.K_RBRKT ],
// [caps] A S D F G H J K L ; ' \ [enter]
[ k.K_A, k.K_S, k.K_D, k.K_F, k.K_G, k.K_H, k.K_J, k.K_K, k.K_L, k.K_COLON, k.K_QUOTE, k.K_BKSLASH ],
// [shift] * Z X C V B N M , . / [shift] *=oE2
[ k.K_oE2, k.K_Z, k.K_X, k.K_C, k.K_V, k.K_B, k.K_N, k.K_M, k.K_COMMA, k.K_PERIOD, k.K_SLASH ],
// space
[ k.K_SPACE ],
];
0x1E: k.K_A,
0x1F: k.K_S,
0x20: k.K_D,
0x21: k.K_F,
0x22: k.K_G,
0x23: k.K_H,
0x24: k.K_J,
0x25: k.K_K,
0x26: k.K_L,
0x27: k.K_COLON,
0x28: k.K_QUOTE,
0x29: k.K_BKQUOTE,

export const JISVirtualKeyMap: KeyMap = [
// [Hankaku/Zenkaku] 1 2 3 4 5 6 7 8 9 0 - ^ ¥ [bksp]
[ k.K_1, k.K_2, k.K_3, k.K_4, k.K_5, k.K_6, k.K_7, k.K_8, k.K_9, k.K_0, k.K_HYPHEN, k.K_EQUAL, k.K_BKSLASH /* YEN */ ],
// [tab] Q W E R T Y U I O P @«`» [ [enter]
[ k.K_Q, k.K_W, k.K_E, k.K_R, k.K_T, k.K_Y, k.K_U, k.K_I, k.K_O, k.K_P, k.K_BKQUOTE, k.K_LBRKT ],
// [caps] A S D F G H J K L ; : ] [enter]
[ k.K_A, k.K_S, k.K_D, k.K_F, k.K_G, k.K_H, k.K_J, k.K_K, k.K_L, k.K_COLON, k.K_QUOTE, k.K_RBRKT ],
// [shift] Z X C V B N M , . / _ [shift]
[ k.K_Z, k.K_X, k.K_C, k.K_V, k.K_B, k.K_N, k.K_M, k.K_COMMA, k.K_PERIOD, k.K_SLASH, k.K_oE2 /* ろ */ ],
// space
[ k.K_SPACE ],
];
0x2B: k.K_BKSLASH,
0x2C: k.K_Z,
0x2D: k.K_X,
0x2E: k.K_C,
0x2F: k.K_V,
0x30: k.K_B,
0x31: k.K_N,
0x32: k.K_M,
0x33: k.K_COMMA,
0x34: k.K_PERIOD,
0x35: k.K_SLASH,

export const ABNT2VirtualKeyMap: KeyMap = [
// ' 1 2 3 4 5 6 7 8 9 0 - = [bksp]
[ k.K_BKQUOTE, k.K_1, k.K_2, k.K_3, k.K_4, k.K_5, k.K_6, k.K_7, k.K_8, k.K_9, k.K_0, k.K_HYPHEN, k.K_EQUAL ],
// [tab] Q W E R T Y U I O P ´ [
[ k.K_Q, k.K_W, k.K_E, k.K_R, k.K_T, k.K_Y, k.K_U, k.K_I, k.K_O, k.K_P, k.K_LBRKT, k.K_RBRKT ],
// [caps] A S D F G H J K L ç ~ ] [enter]
[ k.K_A, k.K_S, k.K_D, k.K_F, k.K_G, k.K_H, k.K_J, k.K_K, k.K_L, k.K_COLON, k.K_QUOTE, k.K_BKSLASH ],
// [shift] \ Z X C V B N M , . ; / [shift]
[ k.K_oE2, k.K_Z, k.K_X, k.K_C, k.K_V, k.K_B, k.K_N, k.K_M, k.K_COMMA, k.K_PERIOD, k.K_SLASH, k.k_oC1 /* ABNT2 */ ],
// space
[ k.K_SPACE ],
];
0x39: k.K_SPACE,

/**
* Map from a hardware constant to a keymap
* For the 'key' see constants.layr_list_hardware_map
*/
export const HardwareToKeymap: Map<string, KeyMap> = new Map(
[
["us", USVirtualKeyMap],
["iso", ISOVirtualKeyMap],
["jis", JISVirtualKeyMap],
["abnt2", ABNT2VirtualKeyMap],
]
);
0x56: k.K_oE2, // << Same as 0x7D; found on iso, abnt2
0x73: k.K_oC1,
0x7D: k.K_oE2, // << Same as 0x56; found on jis

};

export type KeyMap = number[][];

/**
* Maps LDML VKey Names from CLDR VKey Enum in TR35 to Keyman virtual key codes
* Convert a scan code numerical KeyMap to VKeys
* @param scans keymap to convert
* @param badScans output: set of not-found scancodes
* @returns
*/
export const LdmlVkeyNames: Record<string, number> = {
'SPACE': k.K_SPACE, // 0x20, // A03
'0': k.K_0, // 0x30, // E10
'1': k.K_1, // 0x31, // E01
'2': k.K_2, // 0x32, // E02
'3': k.K_3, // 0x33, // E03
'4': k.K_4, // 0x34, // E04
'5': k.K_5, // 0x35, // E05
'6': k.K_6, // 0x36, // E06
'7': k.K_7, // 0x37, // E07
'8': k.K_8, // 0x38, // E08
'9': k.K_9, // 0x39, // E09
'A': k.K_A, // 0x41, // C01
'B': k.K_B, // 0x42, // B05
'C': k.K_C, // 0x43, // B03
'D': k.K_D, // 0x44, // C03
'E': k.K_E, // 0x45, // D03
'F': k.K_F, // 0x46, // C04
'G': k.K_G, // 0x47, // C05
'H': k.K_H, // 0x48, // C06
'I': k.K_I, // 0x49, // D08
'J': k.K_J, // 0x4A, // C07
'K': k.K_K, // 0x4B, // C08
'L': k.K_L, // 0x4C, // C09
'M': k.K_M, // 0x4D, // B07
'N': k.K_N, // 0x4E, // B06
'O': k.K_O, // 0x4F, // D09
'P': k.K_P, // 0x50, // D10
'Q': k.K_Q, // 0x51, // D01
'R': k.K_R, // 0x52, // D04
'S': k.K_S, // 0x53, // C02
'T': k.K_T, // 0x54, // D05
'U': k.K_U, // 0x55, // D07
'V': k.K_V, // 0x56, // B05
'W': k.K_W, // 0x57, // D02
'X': k.K_X, // 0x58, // B02
'Y': k.K_Y, // 0x59, // D06
'Z': k.K_Z, // 0x5A, // B01
'SEMICOLON': k.K_COLON, // 0xBA, // C10
'EQUAL': k.K_EQUAL, // 0xBB, // E12
'COMMA': k.K_COMMA, // 0xBC, // B08
'HYPHEN': k.K_HYPHEN, // 0xBD, // E11
'PERIOD': k.K_PERIOD, // 0xBE, // B09
'SLASH': k.K_SLASH, // 0xBF, // B10
'GRAVE': k.K_BKQUOTE, // 0xC0, // E00
'LBRACKET': k.K_LBRKT, // 0xDB, // D11
'BACKSLASH': k.K_BKSLASH, // 0xDC, // D13
'RBRACKET': k.K_RBRKT, // 0xDD, // D12
'QUOTE': k.K_QUOTE, // 0xDE, // C11
'LESS-THAN': k.K_oE2, // 0xE2, // B00 102nd key on European layouts, right of left shift.
'ABNT2': k.k_oC1, // 0xC1, // B11 Extra key, left of right-shift, ABNT2
};
export function CLDRScanToKeyMap(scans: KeyMap, badScans?: Set<number>): KeyMap {
return scans.map((row) => row.map((scan) => CLDRScanToVkey(scan, badScans)));
}

/** Convert one scan code to vkey, or undefined */
export function CLDRScanToVkey(scan: number, badScans?: Set<number>): number {
/** typescript fun to index the scan table */
function hasScanCode(key: PropertyKey): key is keyof typeof CLDRScanToUSVirtualKeyCodes {
return key in CLDRScanToUSVirtualKeyCodes;
}
if (hasScanCode(scan)) {
return CLDRScanToUSVirtualKeyCodes[scan];
} else {
badScans?.add(scan);
return undefined;
}
}

5 changes: 3 additions & 2 deletions common/web/types/src/kmx/kmx-plus-builder/build-layr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BUILDER_SECTION } from "./builder-section.js";
* List of layers, the <layers> element
*/
interface BUILDER_LAYR_LIST {
hardware: number; // hardware indicator
hardware: BUILDER_STR_REF; // hardware or 'touch'
layer: number; // index of first layer in the list, in the
count: number; // number of layer entries in the list
minDeviceWidth: number; // width in millimeters
Expand Down Expand Up @@ -82,7 +82,7 @@ export function build_layr(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l

layr.lists = kmxplus.layr.lists.map((list) => {
const blist: BUILDER_LAYR_LIST = {
hardware: list.hardware,
hardware: build_strs_index(sect_strs, list.hardware),
layer: null, // to be set below
_layers: list.layers,
count: list.layers.length,
Expand All @@ -92,6 +92,7 @@ export function build_layr(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_l
});
// now sort the lists
layr.lists.sort((a, b) => {
// sort by string #
if (a.hardware < b.hardware) {
return -1;
} else if (a.hardware > b.hardware) {
Expand Down
43 changes: 0 additions & 43 deletions common/web/types/src/kmx/kmx-plus-builder/build-vkey.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { BUILDER_STRS, build_strs } from './build-strs.js';
import { BUILDER_TRAN, build_tran } from './build-tran.js';
import { BUILDER_USET, build_uset } from './build-uset.js';
import { BUILDER_VARS, build_vars } from './build-vars.js';
import { BUILDER_VKEY, build_vkey } from './build-vkey.js';

type BUILDER_BKSP = BUILDER_TRAN;
// type BUILDER_FINL = BUILDER_TRAN;
Expand All @@ -36,7 +35,6 @@ type SectionBuilders = {
tran?: BUILDER_TRAN;
uset?: BUILDER_USET;
vars?: BUILDER_VARS;
vkey?: BUILDER_VKEY;
};

export default class KMXPlusBuilder {
Expand Down Expand Up @@ -73,7 +71,6 @@ export default class KMXPlusBuilder {
this.emitSection(file, this.file.COMP_PLUS_TRAN, this.sect.tran);
this.emitSection(file, this.file.COMP_PLUS_USET, this.sect.uset);
this.emitSection(file, this.file.COMP_PLUS_VARS, this.sect.vars);
this.emitSection(file, this.file.COMP_PLUS_VKEY, this.sect.vkey);

return file;
}
Expand All @@ -100,7 +97,6 @@ export default class KMXPlusBuilder {
this.sect.tran = build_tran(this.file.kmxplus.tran, this.sect.strs, this.sect.elem);
this.sect.uset = build_uset(this.file.kmxplus, this.sect.strs);
this.sect.vars = build_vars(this.file.kmxplus, this.sect.strs, this.sect.elem, this.sect.list);
this.sect.vkey = build_vkey(this.file.kmxplus);

// Finalize the sect (index) section

Expand Down Expand Up @@ -138,7 +134,6 @@ export default class KMXPlusBuilder {
offset = this.finalize_sect_item(this.sect.tran, offset);
offset = this.finalize_sect_item(this.sect.uset, offset);
offset = this.finalize_sect_item(this.sect.vars, offset);
offset = this.finalize_sect_item(this.sect.vkey, offset);

this.sect.sect.total = offset;
}
Expand Down
16 changes: 2 additions & 14 deletions common/web/types/src/kmx/kmx-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,6 @@ export class Bksp extends Tran {
}
};

// 'vkey'

export class VkeyItem {
vkey: number;
target: number;
}

export class Vkey extends Section {
vkeys: VkeyItem[] = [];
};

// 'disp'
export class DispItem {
to: StrsItem;
Expand All @@ -433,7 +422,7 @@ export class Disp extends Section {
* In-memory `<layers>`
*/
export class LayrList {
hardware: number;
hardware: StrsItem;
layers: LayrEntry[] = [];
minDeviceWidth: number; // millimeters
};
Expand Down Expand Up @@ -569,7 +558,6 @@ export interface KMXPlusData {
tran?: Tran;
uset?: Uset; // uset is ignored in-memory
vars?: Vars;
vkey?: Vkey;
};

export class KMXPlusFile extends KMXFile {
Expand Down Expand Up @@ -720,7 +708,7 @@ export class KMXPlusFile extends KMXFile {
});

this.COMP_PLUS_LAYR_LIST = new r.Struct({
hardware: r.uint32le, //enum
hardware: STR_REF, // str: hardware name
layer: r.uint32le, // index into layers
count: r.uint32le,
minDeviceWidth: r.uint32le, // integer: millimeters
Expand Down
3 changes: 2 additions & 1 deletion common/web/types/src/kvk/kvk-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface BUILDER_KVK_KEY {
export const BUILDER_KVK_KEY_Size = 9; // size of fixed elements of BUILDER_KVK_KEY

export const enum BUILDER_KVK_HEADER_FLAGS {
kvkhNone = 0x00, // no flags
kvkh102 = 0x01,
kvkhDisplayUnderlying = 0x02,
kvkhUseUnderlying = 0x04,
Expand Down Expand Up @@ -122,4 +123,4 @@ export default class KVKFile {
});

}
};
};
Loading