Skip to content

Commit

Permalink
Add missing forceful ESC key exitPointerLock support
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaer Kazmer committed Mar 16, 2018
1 parent eef5c7b commit ee63d4d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,18 @@ nativeWindow.setEventHandler((type, data) => {
_dispatchCanvasEvent(canvas, new window.Event('resize'));
break;
}
case 'keydown':
case 'keydown': {
if (data.keyCode === 27 && window.top.document.pointerLockElement) {
window.top.document.exitPointerLock();
}

const e = new window.KeyboardEvent(type, data);
_dispatchCanvasEvent(canvas, e, true);
if (!e.handled) {
window.document.documentElement.dispatchEvent(e, false);
}
break;
}
case 'keyup':
case 'keypress': {
const e = new window.KeyboardEvent(type, data);
Expand Down Expand Up @@ -275,7 +286,7 @@ nativeWindow.setEventHandler((type, data) => {

nativeWindow.setCursorPosition(context.getWindowHandle(), window.innerWidth / 2, window.innerHeight / 2);
}

const e = new window.MouseEvent(type, data);
_dispatchCanvasEvent(canvas, e, true);
if (!e.handled) {
Expand Down

0 comments on commit ee63d4d

Please sign in to comment.