Skip to content

Commit efdde6d

Browse files
authored
fix(KeyboardControls): support non-qwerty keyboards (#573) (#574)
* fix(KeyboardControls): support non-QWERTY keyboards * docs(KeyboardControls): add mention of QWERTY/non-QWERTY layouts * docs(KeyboardControls): fix wording/formatting
1 parent f0fb337 commit efdde6d

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# KeyboardControls
22

3-
KeyboardControls is a special type of controller that allows you to move through the scene using your keyboard, is based on the Unreal Engine Controls.
4-
53
<DocsDemo>
64
<KeyboardControlsDemo />
75
</DocsDemo>
86

7+
`<KeyboardControls />` is a simple keyboard controller for the camera. The camera's movements are bound to:
8+
9+
* WASD on QWERTY keyboards or equivalent keys on non-QWERTY keyboards
10+
* Arrow keys
11+
912
::: info
10-
:memo: KeyboardControls uses `PointerLockControls` under the hood, meaning you can use [all the props from `<PointerLockControls />`](pointer-lock-controls#props) as well as it events.
13+
`<KeyboardControls />` uses `<PointerLockControls />` under the hood. You can use [`<PointerLockControls />` props and events](pointer-lock-controls#props).
1114
:::
1215

1316
## Usage
1417

15-
You can use the ASDW or the arrows keys to move and your mouse to explore your scene.
16-
1718
```vue{3,10}
1819
<script setup lang="ts">
1920
import { TresCanvas } from '@tresjs/core'
@@ -31,18 +32,18 @@ import { KeyboardControls, Box } from '@tresjs/cientos'
3132
```
3233

3334
::: warning
34-
Is really important that the Perspective camera is set first in the canvas. Otherwise might break.
35+
You must add a `<TresPerspectiveCamera />` to your scene before adding `<KeyboardControls />`.
3536
:::
3637

3738
## Props
3839

39-
| Prop | Description | Default |
40-
| :---------------------- | :----------------------------------- | ------- |
41-
| **moveSpeed** | Speed movement. | 0.2 |
42-
| **makeDefault** | If `true`, the controls will be set as the default controls for the scene. | `true` |
43-
| **camera** | The camera to control. | `undefined` |
44-
| **domElement** | The dom element to listen to. | `undefined` |
45-
| **selector** | Accept an id element as string, if it is set, the new element will be used as the trigger | `undefined` |
40+
| Prop | Description | Default |
41+
| :-------------- | :----------------------------------- | ------- |
42+
| **moveSpeed** | Speed movement. | 0.2 |
43+
| **makeDefault** | If `true`, the controls will be set as the default controls for the scene. | `true` |
44+
| **camera** | The camera to control. | `undefined` |
45+
| **domElement** | The DOM element to listen to. | `undefined` |
46+
| **selector** | Accept an id element as string. If set, the new element will be used as the trigger | `undefined` |
4647

4748
## Events
4849

@@ -52,5 +53,5 @@ Is really important that the Perspective camera is set first in the canvas. Othe
5253

5354
| Event | Description |
5455
| :--------- | :--------------------------------------------------------------- |
55-
| **isLock** | Return `true` if "lock", `false` if "unlock" events are trigger. |
56+
| **isLock** | Return `true` if "lock", `false` if "unlock" events are triggered. |
5657
| **change** | Dispatched when the control changes. |

src/core/controls/KeyboardControls.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ watch(props, () => {
7070
const sidewardMove = ref(0)
7171
const forwardMove = ref(0)
7272
73-
const { w, s, a, d, Up, Down, Left, Right } = useMagicKeys()
73+
const { KeyW, KeyA, KeyS, KeyD, Up, Down, Left, Right } = useMagicKeys()
7474
7575
watchEffect(() => {
76-
if (a.value || Left.value) { sidewardMove.value = -moveSpeed.value }
77-
else if (d.value || Right.value) { sidewardMove.value = moveSpeed.value }
76+
if (KeyA.value || Left.value) { sidewardMove.value = -moveSpeed.value }
77+
else if (KeyD.value || Right.value) { sidewardMove.value = moveSpeed.value }
7878
else { sidewardMove.value = 0 }
79-
if (w.value || Up.value) { forwardMove.value = moveSpeed.value }
80-
else if (s.value || Down.value) { forwardMove.value = -moveSpeed.value }
79+
if (KeyW.value || Up.value) { forwardMove.value = moveSpeed.value }
80+
else if (KeyS.value || Down.value) { forwardMove.value = -moveSpeed.value }
8181
else { forwardMove.value = 0 }
8282
})
8383

0 commit comments

Comments
 (0)