spiegel-keyman/common/web/keyboard-processor/src/text/keyEvent.ts

57 lines
No EOL
2 KiB
TypeScript

/// <reference path="outputTarget.ts" />
namespace com.keyman.text {
// Represents a probability distribution over a keyboard's keys.
// Defined here to avoid compilation issues.
export type KeyDistribution = {keyId: string, p: number}[];
/**
* This class is defined within its own file so that it can be loaded by code outside of KMW without
* having to actually load the entirety of KMW.
*/
export class KeyEvent {
Lcode: number;
Lstates: number;
LmodifierChange?: boolean;
Lmodifiers: number;
LisVirtualKey: boolean;
vkCode: number;
kName: string;
kLayer?: string; // The key's layer property
kbdLayer?: string; // The virtual keyboard's active layer
kNextLayer?: string;
/**
* Marks the active keyboard at the time that this KeyEvent was generated by the user.
*
* Note: this is NOT equivalent to the active keyboard at the time that the event handler begins
* processing! It should be set via closure (or similar) on the event handler that can 100%
* guarantee that the keyboard instance known to the handler has not changed during JS execution
* since the user's interaction that raised the event.
*/
srcKeyboard?: keyboards.Keyboard;
// Holds relevant event properties leading to construction of this KeyEvent.
source?: any; // Technically, KeyEvent|MouseEvent|Touch - but those are DOM types that must be kept out of headless mode.
// Holds a generated fat-finger distribution (when appropriate)
keyDistribution?: KeyDistribution;
/**
* The device model for web-core to follow when processing the keystroke.
*/
device: utils.DeviceSpec;
/**
* `true` if this event was produced by sources other than a DOM-based KeyboardEvent.
*/
isSynthetic: boolean = true;
public static constructNullKeyEvent(device: utils.DeviceSpec): KeyEvent {
const keyEvent = new KeyEvent();
keyEvent.Lcode = 0;
keyEvent.kName = '';
keyEvent.device = device;
return keyEvent;
}
};
}