mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-12 10:37:43 +00:00
feat(web): Add longpress globe action
This commit is contained in:
parent
651932f1bb
commit
9fcf488094
1 changed files with 51 additions and 11 deletions
|
|
@ -13,27 +13,67 @@
|
|||
/*****************************************/
|
||||
|
||||
namespace com.keyman.osk {
|
||||
VisualKeyboard.prototype.optionKey = function(this: VisualKeyboard, e: KeyElement, keyName: string, keyDown: boolean) {
|
||||
|
||||
// Used to distinguish shortpress from longpress on globe key
|
||||
export class GlobeKeyState {
|
||||
longpressGlobeKey: boolean = false;
|
||||
globeKeyTimer: number;
|
||||
|
||||
setGlobeKeyTimer(): void {
|
||||
this.longpressGlobeKey = false;
|
||||
|
||||
this.globeKeyTimer = window.setTimeout(function() {
|
||||
this.longpressGlobeKey=true;
|
||||
}.bind(this), 500)
|
||||
}
|
||||
}
|
||||
|
||||
export class GlobeKeyHandler {
|
||||
static globeKeyState = new GlobeKeyState();
|
||||
}
|
||||
|
||||
VisualKeyboard.prototype.optionKey = function(this: VisualKeyboard, e: KeyElement, keyName: string, keyDown: boolean) {
|
||||
let keyman = com.keyman.singleton;
|
||||
let device = com.keyman.singleton.util.device;
|
||||
|
||||
if(keyName.indexOf('K_LOPT') >= 0) {
|
||||
if(keyDown) {
|
||||
this.menuEvent = e;
|
||||
if(typeof keyman['showKeyboardList'] == 'function') {
|
||||
keyman['showKeyboardList']();
|
||||
if (device.OS == 'Android') {
|
||||
// Start the timer to distinguish between short and longpress of globe key
|
||||
if (!GlobeKeyHandler.globeKeyState.globeKeyTimer || GlobeKeyHandler.globeKeyState.globeKeyTimer == 0) {
|
||||
GlobeKeyHandler.globeKeyState.setGlobeKeyTimer();
|
||||
}
|
||||
} else {
|
||||
this.menuEvent = e;
|
||||
if(typeof keyman['showKeyboardList'] == 'function') {
|
||||
keyman['showKeyboardList'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(this.menuEvent) {
|
||||
this.highlightKey(this.menuEvent, false);
|
||||
}
|
||||
if(typeof(window['menuKeyUp']) == 'function') {
|
||||
window['menuKeyUp']();
|
||||
// Globe Key Up
|
||||
if (device.OS == 'Android') {
|
||||
this.menuEvent = e;
|
||||
if(typeof keyman['doGlobeKey'] == 'function') {
|
||||
// pass whether longpress on globe as parameter
|
||||
keyman['doGlobeKey'](GlobeKeyHandler.globeKeyState.longpressGlobeKey);
|
||||
}
|
||||
|
||||
// Clear longpress timer
|
||||
GlobeKeyHandler.globeKeyState.longpressGlobeKey = false;
|
||||
GlobeKeyHandler.globeKeyState.globeKeyTimer = 0;
|
||||
} else {
|
||||
if(this.menuEvent) {
|
||||
this.highlightKey(this.menuEvent, false);
|
||||
}
|
||||
if(typeof(window['menuKeyUp']) == 'function') {
|
||||
window['menuKeyUp']();
|
||||
}
|
||||
}
|
||||
this.menuEvent = null;
|
||||
}
|
||||
}
|
||||
} else if(keyName.indexOf('K_ROPT') >= 0) {
|
||||
if(keyDown) {
|
||||
this.highlightKey(e,false);
|
||||
this.highlightKey(e,false);
|
||||
if(typeof keyman['hideKeyboard'] == 'function') {
|
||||
keyman['hideKeyboard']();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue