Skip to content

Commit

Permalink
fix: remove deprecated keyCode in controls (#59)
Browse files Browse the repository at this point in the history
Brings three-stdlib up to date with three: mrdoob/three.js#21409
  • Loading branch information
haywirez authored May 11, 2021
1 parent 57382f3 commit cf15c71
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/controls/OrbitControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class OrbitControls extends EventDispatcher {
autoRotate = false
autoRotateSpeed = 2.0 // 30 seconds per orbit when fps is 60
// The four arrow keys
keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 }
keys = { LEFT: 'ArrowLeft', UP: 'ArrowUp', RIGHT: 'ArrowRight', BOTTOM: 'ArrowDown' }
// Mouse buttons
mouseButtons = {
LEFT: MOUSE.ROTATE,
Expand Down Expand Up @@ -498,7 +498,7 @@ class OrbitControls extends EventDispatcher {
function handleKeyDown(event: KeyboardEvent) {
let needsUpdate = false

switch (event.keyCode) {
switch (event.code) {
case scope.keys.UP:
pan(0, scope.keyPanSpeed)
needsUpdate = true
Expand Down
8 changes: 4 additions & 4 deletions src/controls/TrackballControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TrackballControls extends EventDispatcher {
public minDistance = 0
public maxDistance = Infinity

public keys: [number, number, number] = [65 /*A*/, 83 /*S*/, 68 /*D*/]
public keys: [string, string, string] = ['KeyA' /*A*/, 'KeyS' /*S*/, 'KeyD' /*D*/]

public mouseButtons = {
LEFT: MOUSE.ROTATE,
Expand Down Expand Up @@ -344,11 +344,11 @@ class TrackballControls extends EventDispatcher {

if (this._keyState !== this.STATE.NONE) {
return
} else if (event.keyCode === this.keys[this.STATE.ROTATE] && !this.noRotate) {
} else if (event.code === this.keys[this.STATE.ROTATE] && !this.noRotate) {
this._keyState = this.STATE.ROTATE
} else if (event.keyCode === this.keys[this.STATE.ZOOM] && !this.noZoom) {
} else if (event.code === this.keys[this.STATE.ZOOM] && !this.noZoom) {
this._keyState = this.STATE.ZOOM
} else if (event.keyCode === this.keys[this.STATE.PAN] && !this.noPan) {
} else if (event.code === this.keys[this.STATE.PAN] && !this.noPan) {
this._keyState = this.STATE.PAN
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/controls/experimental/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CameraControls extends EventDispatcher {
enableKeys = true

/** The four arrow keys */
keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 }
keys = { LEFT: 'ArrowLeft', UP: 'ArrowUp', RIGHT: 'ArrowRight', BOTTOM: 'ArrowDown' }

mouseButtons: {
LEFT: MOUSE
Expand Down Expand Up @@ -545,8 +545,7 @@ class CameraControls extends EventDispatcher {
private handleKeyDown = (event: KeyboardEvent): void => {
let needsUpdate = false

// TODO: keyCode deprecated?
switch (event.keyCode) {
switch (event.code) {
case this.keys.UP:
this.pan(0, this.keyPanSpeed)
needsUpdate = true
Expand Down

1 comment on commit cf15c71

@vercel
Copy link

@vercel vercel bot commented on cf15c71 May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.