Keyboard event only when focus is in the canvas

This commit is contained in:
Thomas FORGIONE 2015-04-27 15:04:33 +02:00
parent 0386263d58
commit 18665ecd03
2 changed files with 3 additions and 3 deletions

View File

@ -35,4 +35,4 @@ button.
</div>
<div id="container" style="padding: 0px; margin: 0px;"></div>
<div id="container" style="padding: 0px; margin: 0px;" tabindex="1"></div>

View File

@ -46,8 +46,8 @@ var PointerCamera = function() {
var onMouseMove = function(event) {self.onMouseMove(event); };
var onMouseUp = function(event) {self.onMouseUp(event); };
document.addEventListener('keydown', onKeyDown, false);
document.addEventListener('keyup', onKeyUp, false);
listenerTarget.addEventListener('keydown', onKeyDown, false);
listenerTarget.addEventListener('keyup', onKeyUp, false);
listenerTarget.addEventListener('mousedown', function(event) { if (event.which == 1) onMouseDown(event);}, false);
listenerTarget.addEventListener('mousemove', function(event) { if (event.which == 1) onMouseMove(event);}, false);
listenerTarget.addEventListener('mouseup', onMouseUp, false);