question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OrbitControls keydown events not firing

See original GitHub issue

Describe the bug

the keydown event is attached to the dom node as should be, but when you use the arrow keys no event is fired. I can see in the PR #17819 that you added the following code:

if ( scope.domElement.tabIndex === -1 ) {
  scope.domElement.tabIndex = 0;
}

but in the latest release r123, this code is no longer there. If I re-add the code above the keydown events work as expected. After some digging I can see in #20617 this issue is known, but i’ve already written this bug so at least it’s visible to others.

If I understand right, is it that the canvas isn’t focussed so the keydown events don’t fire? I’m happy to work on a PR to fix this.

To Reproduce

Steps to reproduce the behavior:

  1. Go to - https://threejs.org/examples/?q=controls#misc_controls_orbit
  2. try use the arrow keys

Expected behavior

The keydown events should fire moving the camera.

Platform:

  • Device: [Desktop, Mobile] desktop
  • OS: [Windows, MacOS, Linux, Android, iOS] macOS
  • Browser: [Chrome, Firefox, Safari, Edge] chrome/firefox
  • Three.js version: r123

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
WestLangleycommented, Mar 3, 2022

@TiagoCavalcante OrbitControls listens for arrow keys, not WASD.

Do this:

controls.listenToKeyEvents( window );

controls.keys = { LEFT: 'KeyA', UP: 'KeyW', RIGHT: 'KeyD', BOTTOM: 'KeyS' };
1reaction
mrdoobcommented, Jan 8, 2021

I just try to look at this issue from the perspective of an average three.js user. I fear the additional call of listen*() methods could be considered as inconvenient. Especially if one says it “worked before without issues”

Yeah, but I think it’s not too bad and teaches the user about pointer events.

Also, code editors also gave me issues when doing this:

var controls = new THREE.OrbitControls( camera );

They would complain that controls is not used and had to do this:

new THREE.OrbitControls( camera );

Which was always weird 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

keydown doesn't work in threejs canvas, OrbitControls on
The element , i.e., input and button is focussed on clicking but input doesn't register any key stroke. When I checking in the...
Read more >
Orbitcontrols default keyboard events stopped working ...
OrbitControls keydown events not firing ... Describe the bug the keydown event is attached to the dom node as should be, but when...
Read more >
Three.js OffscreenCanvas
The OrbitControls attach event handlers to window to get keyboard events. Not sure that's the right place to attach them but that's beyond...
Read more >
Add Controls in ThreeJs | OrbitControls in ThreeJs - YouTube
Controlling objects in ThreeJs is a pretty important topic so by doing that we can create a pretty good interactive 3D view, ...
Read more >
Orbit controls for threejs from the project itself
It would not be that hard to implement some camera controls for a three.js ... of a camera with the mouse, keyboard, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found