Skip to content

Commit

Permalink
Check exitVR property of keyboard-shortcuts to enable Escape shortcut (
Browse files Browse the repository at this point in the history
…#5512)

Co-authored-by: Noeri Huisman <[email protected]>
  • Loading branch information
mrxz and mrxz authored Nov 9, 2024
1 parent 7b8a308 commit d112009
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 2 additions & 1 deletion docs/components/keyboard-shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ keyboard-shortcuts component applies only to the [`<a-scene>` element][scene].
## Example

```html
<a-scene keyboard-shortcuts="enterVR: false"></a-scene>
<a-scene keyboard-shortcuts="enterVR: false; exitVR: false;"></a-scene>
```

## Properties

| Property | Description | Default Value |
|-------------|-------------------------------------------------------|---------------|
| enterVR | Enables the shortcut to press 'F' to enter VR. | true |
| exitVR | Enables the shortcut to press 'Escape' to exit VR. | true |
9 changes: 2 additions & 7 deletions src/components/scene/keyboard-shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ module.exports.Component = registerComponent('keyboard-shortcuts', {
this.onKeyup = this.onKeyup.bind(this);
},

update: function (oldData) {
var data = this.data;
this.enterVREnabled = data.enterVR;
},

play: function () {
window.addEventListener('keyup', this.onKeyup, false);
},
Expand All @@ -29,10 +24,10 @@ module.exports.Component = registerComponent('keyboard-shortcuts', {
onKeyup: function (evt) {
var scene = this.el;
if (!shouldCaptureKeyEvent(evt)) { return; }
if (this.enterVREnabled && evt.keyCode === 70) { // f.
if (this.data.enterVR && evt.keyCode === 70) { // f.
scene.enterVR();
}
if (this.enterVREnabled && evt.keyCode === 27) { // escape.
if (this.data.exitVR && evt.keyCode === 27) { // escape.
scene.exitVR();
}
}
Expand Down

0 comments on commit d112009

Please sign in to comment.