diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-09-08 22:14:04 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-09-08 22:14:04 -0700 |
commit | 70fbf7d8d5879c2349cb5c5d6ae2278dcf3d5a51 (patch) | |
tree | 7f03cc3e997e5cb64dd89bb6dfc10b92e152a69a /src/proxyClient.js | |
parent | 971e59fe7306042f90c85fe0dff04d666b1f01ab (diff) |
proxy input events
Diffstat (limited to 'src/proxyClient.js')
-rw-r--r-- | src/proxyClient.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/proxyClient.js b/src/proxyClient.js index bbf3e278..41f6a501 100644 --- a/src/proxyClient.js +++ b/src/proxyClient.js @@ -41,3 +41,31 @@ worker.onmessage = function(event) { } }; +function cloneEvent(event) { + var ret = {}; + for (var x in event) { + if (x == x.toUpperCase()) continue; + var prop = event[x]; + if (typeof prop === 'number' || typeof prop === 'string') ret[x] = prop; + } + return ret; +}; + +['keydown', 'keyup', 'keypress', 'blur', 'visibilitychange'].forEach(function(event) { + document.addEventListener(event, function(event) { + worker.postMessage({ target: 'document', event: cloneEvent(event) }); + }); +}); + +['unload'].forEach(function(event) { + window.addEventListener(event, function(event) { + worker.postMessage({ target: 'window', event: cloneEvent(event) }); + }); +}); + +['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mousewheel', 'mouseout'].forEach(function(event) { + Module.canvas.addEventListener(event, function(event) { + worker.postMessage({ target: 'canvas', event: cloneEvent(event) }); + }, true); +}); + |