done client-side mouse reporting
This commit is contained in:
+70
-7
@@ -770,6 +770,14 @@
|
|||||||
for(k in _mods) _mods[k] = event[modifierMap[k]];
|
for(k in _mods) _mods[k] = event[modifierMap[k]];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isModifierPressed(mod) {
|
||||||
|
if (mod=='control'||mod=='ctrl') return _mods[17];
|
||||||
|
if (mod=='shift') return _mods[16];
|
||||||
|
if (mod=='meta') return _mods[91];
|
||||||
|
if (mod=='alt') return _mods[18];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// handle keydown event
|
// handle keydown event
|
||||||
function dispatch(event) {
|
function dispatch(event) {
|
||||||
var key, handler, k, i, modifiersMatch, scope;
|
var key, handler, k, i, modifiersMatch, scope;
|
||||||
@@ -995,6 +1003,7 @@
|
|||||||
global.key.deleteScope = deleteScope;
|
global.key.deleteScope = deleteScope;
|
||||||
global.key.filter = filter;
|
global.key.filter = filter;
|
||||||
global.key.isPressed = isPressed;
|
global.key.isPressed = isPressed;
|
||||||
|
global.key.isModifier = isModifierPressed;
|
||||||
global.key.getPressedKeyCodes = getPressedKeyCodes;
|
global.key.getPressedKeyCodes = getPressedKeyCodes;
|
||||||
global.key.noConflict = noConflict;
|
global.key.noConflict = noConflict;
|
||||||
global.key.unbind = unbindKey;
|
global.key.unbind = unbindKey;
|
||||||
@@ -1681,8 +1690,21 @@ var Screen = (function () {
|
|||||||
(function() {
|
(function() {
|
||||||
var x = i % W;
|
var x = i % W;
|
||||||
var y = Math.floor(i / W);
|
var y = Math.floor(i / W);
|
||||||
e.addEventListener('click', function () {
|
e.addEventListener('mouseenter', function (evt) {
|
||||||
Input.onTap(y, x);
|
Input.onMouseMove(x, y);
|
||||||
|
});
|
||||||
|
e.addEventListener('mousedown', function (evt) {
|
||||||
|
Input.onMouseDown(x, y, evt.button+1);
|
||||||
|
});
|
||||||
|
e.addEventListener('mouseup', function (evt) {
|
||||||
|
Input.onMouseUp(x, y, evt.button+1);
|
||||||
|
});
|
||||||
|
e.addEventListener('contextmenu', function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
});
|
||||||
|
e.addEventListener('mousewheel', function (evt) {
|
||||||
|
Input.onMouseWheel(x, y, evt.deltaY>0?1:-1);
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@@ -2003,10 +2025,6 @@ var Input = (function() {
|
|||||||
Conn.send("STR:"+str);
|
Conn.send("STR:"+str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPosMsg(y, x) {
|
|
||||||
Conn.send("TAP:"+y+','+x);
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendBtnMsg(n) {
|
function sendBtnMsg(n) {
|
||||||
Conn.send("BTN:"+n);
|
Conn.send("BTN:"+n);
|
||||||
}
|
}
|
||||||
@@ -2129,6 +2147,10 @@ var Input = (function() {
|
|||||||
_bindFnKeys();
|
_bindFnKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mb1 = 0;
|
||||||
|
var mb2 = 0;
|
||||||
|
var mb3 = 0;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
_initKeys();
|
_initKeys();
|
||||||
|
|
||||||
@@ -2138,11 +2160,30 @@ var Input = (function() {
|
|||||||
sendBtnMsg(+this.dataset['n']);
|
sendBtnMsg(+this.dataset['n']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener('mousedown', function(evt) {
|
||||||
|
if (evt.button == 0) mb1 = 1;
|
||||||
|
if (evt.button == 1) mb2 = 1;
|
||||||
|
if (evt.button == 2) mb3 = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('mouseup', function(evt) {
|
||||||
|
if (evt.button == 0) mb1 = 0;
|
||||||
|
if (evt.button == 1) mb2 = 0;
|
||||||
|
if (evt.button == 2) mb3 = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function packModifiersForMouse() {
|
||||||
|
return (key.isModifier('ctrl')?1:0) |
|
||||||
|
(key.isModifier('shift')?2:0) |
|
||||||
|
(key.isModifier('alt')?4:0) |
|
||||||
|
(key.isModifier('meta')?8:0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init: init,
|
||||||
onTap: sendPosMsg,
|
// onTap: sendPosMsg,
|
||||||
sendString: sendStrMsg,
|
sendString: sendStrMsg,
|
||||||
setAlts: function(cu, np, fn) {
|
setAlts: function(cu, np, fn) {
|
||||||
if (opts.cu_alt != cu || opts.np_alt != np || opts.fn_alt != fn) {
|
if (opts.cu_alt != cu || opts.np_alt != np || opts.fn_alt != fn) {
|
||||||
@@ -2154,6 +2195,28 @@ var Input = (function() {
|
|||||||
_bindFnKeys();
|
_bindFnKeys();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onMouseMove: function(x, y) {
|
||||||
|
// TODO gather held buttons & key modifiers
|
||||||
|
var b = (mb1?1:0) | (mb2?2:0) | (mb3?4:0);
|
||||||
|
var m = packModifiersForMouse();
|
||||||
|
Conn.send("MM:"+y+','+x+','+b+','+m);
|
||||||
|
},
|
||||||
|
onMouseDown: function(x, y, which) {
|
||||||
|
if(which>3) return;
|
||||||
|
var m = packModifiersForMouse();
|
||||||
|
Conn.send("MP:"+y+','+x+','+which+','+m);
|
||||||
|
},
|
||||||
|
onMouseUp: function(x, y, which) {
|
||||||
|
if(which>3) return;
|
||||||
|
var m = packModifiersForMouse();
|
||||||
|
Conn.send("MR:"+y+','+x+','+which+','+m);
|
||||||
|
},
|
||||||
|
onMouseWheel: function(x, y, dir) {
|
||||||
|
// -1 ... btn 4 (away from user)
|
||||||
|
// +1 ... btn 5 (towards user)
|
||||||
|
var m = packModifiersForMouse();
|
||||||
|
Conn.send("MP:"+y+','+x+','+(dir<0?4:5)+','+m);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,14 @@
|
|||||||
for(k in _mods) _mods[k] = event[modifierMap[k]];
|
for(k in _mods) _mods[k] = event[modifierMap[k]];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isModifierPressed(mod) {
|
||||||
|
if (mod=='control'||mod=='ctrl') return _mods[17];
|
||||||
|
if (mod=='shift') return _mods[16];
|
||||||
|
if (mod=='meta') return _mods[91];
|
||||||
|
if (mod=='alt') return _mods[18];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// handle keydown event
|
// handle keydown event
|
||||||
function dispatch(event) {
|
function dispatch(event) {
|
||||||
var key, handler, k, i, modifiersMatch, scope;
|
var key, handler, k, i, modifiersMatch, scope;
|
||||||
@@ -292,6 +300,7 @@
|
|||||||
global.key.deleteScope = deleteScope;
|
global.key.deleteScope = deleteScope;
|
||||||
global.key.filter = filter;
|
global.key.filter = filter;
|
||||||
global.key.isPressed = isPressed;
|
global.key.isPressed = isPressed;
|
||||||
|
global.key.isModifier = isModifierPressed;
|
||||||
global.key.getPressedKeyCodes = getPressedKeyCodes;
|
global.key.getPressedKeyCodes = getPressedKeyCodes;
|
||||||
global.key.noConflict = noConflict;
|
global.key.noConflict = noConflict;
|
||||||
global.key.unbind = unbindKey;
|
global.key.unbind = unbindKey;
|
||||||
|
|||||||
+61
-7
@@ -124,8 +124,21 @@ var Screen = (function () {
|
|||||||
(function() {
|
(function() {
|
||||||
var x = i % W;
|
var x = i % W;
|
||||||
var y = Math.floor(i / W);
|
var y = Math.floor(i / W);
|
||||||
e.addEventListener('click', function () {
|
e.addEventListener('mouseenter', function (evt) {
|
||||||
Input.onTap(y, x);
|
Input.onMouseMove(x, y);
|
||||||
|
});
|
||||||
|
e.addEventListener('mousedown', function (evt) {
|
||||||
|
Input.onMouseDown(x, y, evt.button+1);
|
||||||
|
});
|
||||||
|
e.addEventListener('mouseup', function (evt) {
|
||||||
|
Input.onMouseUp(x, y, evt.button+1);
|
||||||
|
});
|
||||||
|
e.addEventListener('contextmenu', function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
});
|
||||||
|
e.addEventListener('mousewheel', function (evt) {
|
||||||
|
Input.onMouseWheel(x, y, evt.deltaY>0?1:-1);
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@@ -446,10 +459,6 @@ var Input = (function() {
|
|||||||
Conn.send("STR:"+str);
|
Conn.send("STR:"+str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPosMsg(y, x) {
|
|
||||||
Conn.send("TAP:"+y+','+x);
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendBtnMsg(n) {
|
function sendBtnMsg(n) {
|
||||||
Conn.send("BTN:"+n);
|
Conn.send("BTN:"+n);
|
||||||
}
|
}
|
||||||
@@ -572,6 +581,10 @@ var Input = (function() {
|
|||||||
_bindFnKeys();
|
_bindFnKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mb1 = 0;
|
||||||
|
var mb2 = 0;
|
||||||
|
var mb3 = 0;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
_initKeys();
|
_initKeys();
|
||||||
|
|
||||||
@@ -581,11 +594,30 @@ var Input = (function() {
|
|||||||
sendBtnMsg(+this.dataset['n']);
|
sendBtnMsg(+this.dataset['n']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener('mousedown', function(evt) {
|
||||||
|
if (evt.button == 0) mb1 = 1;
|
||||||
|
if (evt.button == 1) mb2 = 1;
|
||||||
|
if (evt.button == 2) mb3 = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('mouseup', function(evt) {
|
||||||
|
if (evt.button == 0) mb1 = 0;
|
||||||
|
if (evt.button == 1) mb2 = 0;
|
||||||
|
if (evt.button == 2) mb3 = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function packModifiersForMouse() {
|
||||||
|
return (key.isModifier('ctrl')?1:0) |
|
||||||
|
(key.isModifier('shift')?2:0) |
|
||||||
|
(key.isModifier('alt')?4:0) |
|
||||||
|
(key.isModifier('meta')?8:0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init: init,
|
||||||
onTap: sendPosMsg,
|
// onTap: sendPosMsg,
|
||||||
sendString: sendStrMsg,
|
sendString: sendStrMsg,
|
||||||
setAlts: function(cu, np, fn) {
|
setAlts: function(cu, np, fn) {
|
||||||
if (opts.cu_alt != cu || opts.np_alt != np || opts.fn_alt != fn) {
|
if (opts.cu_alt != cu || opts.np_alt != np || opts.fn_alt != fn) {
|
||||||
@@ -597,6 +629,28 @@ var Input = (function() {
|
|||||||
_bindFnKeys();
|
_bindFnKeys();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onMouseMove: function(x, y) {
|
||||||
|
// TODO gather held buttons & key modifiers
|
||||||
|
var b = (mb1?1:0) | (mb2?2:0) | (mb3?4:0);
|
||||||
|
var m = packModifiersForMouse();
|
||||||
|
Conn.send("MM:"+y+','+x+','+b+','+m);
|
||||||
|
},
|
||||||
|
onMouseDown: function(x, y, which) {
|
||||||
|
if(which>3) return;
|
||||||
|
var m = packModifiersForMouse();
|
||||||
|
Conn.send("MP:"+y+','+x+','+which+','+m);
|
||||||
|
},
|
||||||
|
onMouseUp: function(x, y, which) {
|
||||||
|
if(which>3) return;
|
||||||
|
var m = packModifiersForMouse();
|
||||||
|
Conn.send("MR:"+y+','+x+','+which+','+m);
|
||||||
|
},
|
||||||
|
onMouseWheel: function(x, y, dir) {
|
||||||
|
// -1 ... btn 4 (away from user)
|
||||||
|
// +1 ... btn 5 (towards user)
|
||||||
|
var m = packModifiersForMouse();
|
||||||
|
Conn.send("MP:"+y+','+x+','+(dir<0?4:5)+','+m);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user