web-common-resource/terminal/smartxKs/input.js

8 lines
6.0 KiB
JavaScript
Raw Permalink Normal View History

2024-08-20 12:11:35 +00:00
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
*/
var Keyboard,Mouse;!function(){"use strict";Keyboard=function(e){this._keyDownList=[],Util.set_defaults(this,e,{target:document,focused:!0}),this._handler=new KeyEventDecoder(kbdUtil.ModifierSync(),VerifyCharModifier(TrackKeyState(EscapeModifiers(this._handleRfbEvent.bind(this))))),this._eventHandlers={keyup:this._handleKeyUp.bind(this),keydown:this._handleKeyDown.bind(this),keypress:this._handleKeyPress.bind(this),blur:this._allKeysUp.bind(this)}},Keyboard.prototype={_handleRfbEvent:function(e){this._onKeyPress&&(Util.Debug("onKeyPress "+("keydown"==e.type?"down":"up")+", keysym: "+e.keysym.keysym+"("+e.keysym.keyname+")"),this._onKeyPress(e.keysym.keysym,"keydown"==e.type))},_handleKeyDown:function(e){return!this._focused||(!this._handler.keydown(e)||(Util.stopEvent(e),!1))},_handleKeyPress:function(e){return!this._focused||(!this._handler.keypress(e)||(Util.stopEvent(e),!1))},_handleKeyUp:function(e){return!this._focused||(!this._handler.keyup(e)||(Util.stopEvent(e),!1))},_allKeysUp:function(){Util.Debug(">> Keyboard.allKeysUp"),this._handler.releaseAll(),Util.Debug("<< Keyboard.allKeysUp")},grab:function(){var e=this._target;Util.addEvent(e,"keydown",this._eventHandlers.keydown),Util.addEvent(e,"keyup",this._eventHandlers.keyup),Util.addEvent(e,"keypress",this._eventHandlers.keypress),Util.addEvent(window,"blur",this._eventHandlers.blur)},ungrab:function(){var e=this._target;Util.removeEvent(e,"keydown",this._eventHandlers.keydown),Util.removeEvent(e,"keyup",this._eventHandlers.keyup),Util.removeEvent(e,"keypress",this._eventHandlers.keypress),Util.removeEvent(window,"blur",this._eventHandlers.blur),this._allKeysUp()},sync:function(e){this._handler.syncModifiers(e)}},Util.make_properties(Keyboard,[["target","wo","dom"],["focused","rw","bool"],["onKeyPress","rw","func"]]),Mouse=function(e){this._mouseCaptured=!1,this._doubleClickTimer=null,this._lastTouchPos=null,Util.set_defaults(this,e,{target:document,focused:!0,scale:1,touchButton:1}),this._eventHandlers={mousedown:this._handleMouseDown.bind(this),mouseup:this._handleMouseUp.bind(this),mousemove:this._handleMouseMove.bind(this),mousewheel:this._handleMouseWheel.bind(this),mousedisable:this._handleMouseDisable.bind(this)}},Mouse.prototype={_captureMouse:function(){this._target.setCapture&&this._target.setCapture(),this._mouseCaptured=!0},_releaseMouse:function(){this._target.releaseCapture&&this._target.releaseCapture(),this._mouseCaptured=!1},_resetDoubleClickTimer:function(){this._doubleClickTimer=null},_handleMouseButton:function(e,t){if(!this._focused)return!0;this._notify&&this._notify(e);var s,n=e||window.event,o=Util.getEventPosition(e,this._target,this._scale);if(e.touches||e.changedTouches){if(1==t){if(null===this._doubleClickTimer)this._lastTouchPos=o;else{clearTimeout(this._doubleClickTimer);var i=this._lastTouchPos.x-o.x,u=this._lastTouchPos.y-o.y;Math.sqrt(i*i+u*u)<20*(window.devicePixelRatio||1)&&(o=this._lastTouchPos)}this._doubleClickTimer=setTimeout(this._resetDoubleClickTimer.bind(this),500)}s=this._touchButton}else s=n.which?1<<n.button:(1&n.button)+2*(2&n.button)+(4&n.button)/2;return this._onMouseButton&&(Util.Debug("onMouseButton "+(t?"down":"up")+", x: "+o.x+", y: "+o.y+", bmask: "+s),this._onMouseButton(o.x,o.y,t,s)),Util.stopEvent(e),!1},_handleMouseDown:function(e){this._captureMouse(),this._handleMouseButton(e,1)},_handleMouseUp:function(e){this._mouseCaptured&&(this._handleMouseButton(e,0),this._releaseMouse())},_handleMouseWheel:function(e){if(!this._focused)return!0;this._notify&&this._notify(e);var t,s=e||window.event,n=Util.getEventPosition(e,this._target,this._scale),o=s.detail?-1*s.detail:s.wheelDelta/40;return t=o>0?8:16,this._onMouseButton&&(this._onMouseButton(n.x,n.y,1,t),this._onMouseButton(n.x,n.y,0,t)),Util.stopEvent(e),!1},_handleMouseMove:function(e){if(!this._focused)return!0;this._notify&&this._notify(e);var t=(e||window.event,Util.getEventPosition(e,this._target,this._scale));return this._onMouseMove&&this._onMouseMove(t.x,t.y),Util.stopEvent(e),!1},_handleMouseDisable:function(e){return!this._focused||((e||window.even