330
return KeyCode.DependsOnKbLayout;
331
}
333
>
private _encodeScanCodeCombo(scanCodeCombo: ScanCodeCombo): number {
334
>
return this._encode(scanCodeCombo.ctrlKey, scanCodeCombo.shiftKey, scanCodeCombo.altKey, scanCodeCombo.scanCode);
335
>
}
336
>
337
>
private _encodeKeyCodeCombo(keyCodeCombo: KeyCodeCombo): number {
338
>
return this._encode(keyCodeCombo.ctrlKey, keyCodeCombo.shiftKey, keyCodeCombo.altKey, keyCodeCombo.keyCode);
339
>
}
340
>
341
>
private _encode(ctrlKey: boolean, shiftKey: boolean, altKey: boolean, principal: number): number {
342
>
return (
343
>
((ctrlKey ? 1 : 0) << 0)
344
>
| ((shiftKey ? 1 : 0) << 1)
345
>
| ((altKey ? 1 : 0) << 2)
346
>
| principal << 3
347
>
) >>> 0;
348
>
}
349
>
}
350
>
351
>
export class MacLinuxKeyboardMapper implements IKeyboardMapper {
352
>
353
>
/**
354
>
* used only for debug purposes.
355
>
*/
356
>
private readonly _codeInfo: IMacLinuxKeyMapping[];
357
>
/**
358
>
* Maps ScanCode combos <-> KeyCode combos.
359
>
*/
360
>
private readonly _scanCodeKeyCodeMapper: ScanCodeKeyCodeMapper;
361
>
/**
362
>
* UI label for a ScanCode.
363
>
*/
364
>
private readonly _scanCodeToLabel: Array<string | null> = [];
365
>
/**
366
>
* Dispatching string for a ScanCode.
367
>
*/
368
>
private readonly _scanCodeToDispatch: Array<string | null> = [];
369
>
370
>
constructor(
371
>
private readonly _isUSStandard: boolean,
372
>
rawMappings: IMacLinuxKeyboardMapping,
373
>
private readonly _mapAltGrToCtrlAlt: boolean,
374
>
private readonly _OS: OperatingSystem,
375
>
) {
376
>
this._codeInfo = [];
377
>
this._scanCodeKeyCodeMapper = new ScanCodeKeyCodeMapper();
378
>
this._scanCodeToLabel = [];
379
>
this._scanCodeToDispatch = [];
380
>
381
>
const _registerIfUnknown = (
382
>
hwCtrlKey: 0 | 1, hwShiftKey: 0 | 1, hwAltKey: 0 | 1, scanCode: ScanCode,
383
>
kbCtrlKey: 0 | 1, kbShiftKey: 0 | 1, kbAltKey: 0 | 1, keyCode: KeyCode,
384
>
): void => {
385
>
this._scanCodeKeyCodeMapper.registerIfUnknown(
386
>
new ScanCodeCombo(hwCtrlKey ? true : false, hwShiftKey ? true : false, hwAltKey ? true : false, scanCode),
387
>
new KeyCodeCombo(kbCtrlKey ? true : false, kbShiftKey ? true : false, kbAltKey ? true : false, keyCode)
388
>
);
389
>
};
390
>
391
>
const _registerAllCombos = (_ctrlKey: 0 | 1, _shiftKey: 0 | 1, _altKey: 0 | 1, scanCode: ScanCode, keyCode: KeyCode): void => {
392
>
for (let ctrlKey = _ctrlKey; ctrlKey <= 1; ctrlKey++) {
393
>
for (let shiftKey = _shiftKey; shiftKey <= 1; shiftKey++) {
394
>
for (let altKey = _altKey; altKey <= 1; altKey++) {
395
>
_registerIfUnknown(
396
>
ctrlKey, shiftKey, altKey, scanCode,
397
>
ctrlKey, shiftKey, altKey, keyCode
398
>
);
399
>
}
400
>
}
401
>
}
402
>
};
403
>
404
>
// Initialize `_scanCodeToLabel`
405
>
for (let scanCode = ScanCode.None; scanCode < ScanCode.MAX_VALUE; scanCode++) {
406
>
this._scanCodeToLabel[scanCode] = null;
407
>
}
408
>
409
>
// Initialize `_scanCodeToDispatch`
410
>
for (let scanCode = ScanCode.None; scanCode < ScanCode.MAX_VALUE; scanCode++) {
411
>
this._scanCodeToDispatch[scanCode] = null;
412
>
}
413
>
414
>
// Handle immutable mappings
415
>
for (let scanCode = ScanCode.None; scanCode < ScanCode.MAX_VALUE; scanCode++) {
416
>
const keyCode = IMMUTABLE_CODE_TO_KEY_CODE[scanCode];
417
>
if (keyCode !== KeyCode.DependsOnKbLayout) {
418
>
_registerAllCombos(0, 0, 0, scanCode, keyCode);
419
>
this._scanCodeToLabel[scanCode] = KeyCodeUtils.toString(keyCode);
420
>
421
>
if (keyCode === KeyCode.Unknown || isModifierKey(keyCode)) {
422
>
this._scanCodeToDispatch[scanCode] = null; // cannot dispatch on this ScanCode
423
>
} else {
424
>
this._scanCodeToDispatch[scanCode] = `[${ScanCodeUtils.toString(scanCode)}]`;
425
>
}
426
>
}
427
>
}
428
>
429
>
// Try to identify keyboard layouts where characters A-Z are missing
430
>
// and forcibly map them to their corresponding scan codes if that is the case
431
>
const missingLatinLettersOverride: { [scanCode: string]: IMacLinuxKeyMapping } = {};
432
>
433
>
{
434
>
const producesLatinLetter: boolean[] = [];
435
>
for (const strScanCode in rawMappings) {
436
if (rawMappings.hasOwnProperty(strScanCode)) {
437
const scanCode = ScanCodeUtils.toEnum(strScanCode);