Improved PPT
This commit is contained in:
parent
e9ba4125b0
commit
87a54c951f
@ -58,20 +58,32 @@ namespace _ppt {
|
||||
key_listener.remove(listener);
|
||||
}
|
||||
|
||||
interface CurrentState {
|
||||
event: ppt.KeyEvent;
|
||||
code: string;
|
||||
let key_hooks: ppt.KeyHook[] = [];
|
||||
|
||||
interface CurrentState {
|
||||
keys: {[code: string]:ppt.KeyEvent};
|
||||
special: { [key:number]:boolean };
|
||||
}
|
||||
|
||||
let current_state: CurrentState = {
|
||||
special: []
|
||||
} as any;
|
||||
|
||||
let key_hooks: ppt.KeyHook[] = [];
|
||||
let key_hooks_active: ppt.KeyHook[] = [];
|
||||
|
||||
function listener_blur() {
|
||||
current_state.special[ppt.SpecialKey.ALT] = false;
|
||||
current_state.special[ppt.SpecialKey.CTRL] = false;
|
||||
current_state.special[ppt.SpecialKey.SHIFT] = false;
|
||||
current_state.special[ppt.SpecialKey.WINDOWS] = false;
|
||||
|
||||
for(const code of Object.keys(current_state.keys))
|
||||
delete current_state[code];
|
||||
|
||||
for(const hook of key_hooks_active)
|
||||
hook.callback_release();
|
||||
key_hooks_active = [];
|
||||
}
|
||||
|
||||
function listener_hook(event: ppt.KeyEvent) {
|
||||
if(event.type == ppt.EventType.KEY_TYPED)
|
||||
return;
|
||||
@ -84,15 +96,12 @@ namespace _ppt {
|
||||
current_state.special[ppt.SpecialKey.SHIFT] = event.key_shift;
|
||||
current_state.special[ppt.SpecialKey.WINDOWS] = event.key_windows;
|
||||
|
||||
current_state.code = undefined;
|
||||
current_state.event = undefined;
|
||||
|
||||
current_state[event.key_code] = undefined;
|
||||
if(event.type == ppt.EventType.KEY_PRESS) {
|
||||
current_state.event = event;
|
||||
current_state.code = event.key_code;
|
||||
current_state[event.key_code] = event;
|
||||
|
||||
for(const hook of key_hooks) {
|
||||
if(hook.key_code && hook.key_code != event.key_code) continue;
|
||||
if(hook.key_code !== event.key_code) continue;
|
||||
if(hook.key_alt != event.key_alt) continue;
|
||||
if(hook.key_ctrl != event.key_ctrl) continue;
|
||||
if(hook.key_shift != event.key_shift) continue;
|
||||
@ -101,20 +110,27 @@ namespace _ppt {
|
||||
new_hooks.push(hook);
|
||||
if(!old_hooks.remove(hook) && hook.callback_press) {
|
||||
hook.callback_press();
|
||||
//console.debug("Trigger key press for %o!", hook);
|
||||
log.trace(LogCategory.GENERAL, tr("Trigger key press for %o!"), hook);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//We have a new situation
|
||||
for(const hook of old_hooks)
|
||||
if(hook.callback_release) {
|
||||
hook.callback_release();
|
||||
//console.debug("Trigger key release for %o!", hook);
|
||||
for(const hook of old_hooks) {
|
||||
//Do not test for meta key states because they could differ in a key release event
|
||||
if(hook.key_code === event.key_code) {
|
||||
if(hook.callback_release) {
|
||||
hook.callback_release();
|
||||
log.trace(LogCategory.GENERAL, tr("Trigger key release for %o!"), hook);
|
||||
}
|
||||
} else {
|
||||
new_hooks.push(hook);
|
||||
}
|
||||
}
|
||||
key_hooks_active = new_hooks;
|
||||
}
|
||||
|
||||
|
||||
export function register_key_hook(hook: ppt.KeyHook) {
|
||||
key_hooks.push(hook);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user