-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Releasing a binding when another activates #156
Labels
Request
Feature request or idea related issues.
Comments
Just to follow up, i've essentially done this to resolve the issue in user land: import Keyboard from 'keyboardjs'
export class Input {
constructor(editor, controls) {
this.editor = editor
this.controls = controls
Keyboard.bind('shift', this.onCrouch, this.onCrouchRelease)
Keyboard.bind('shift + mod + z', this.onRedo)
// ...etc
}
onCrouch = event => {
event.preventRepeat()
if (event.metaKey) return
this.controls.axis.y = -1
}
onCrouchRelease = () => {
this.controls.axis.y = 0
}
onRedo = () => {
this.onCrouchRelease() // cancel crouch
this.editor.redo()
}
// ...etc
} Although it works, I think it would make the api cohesive if you could configure things like cancelling and preventRepeat as binding options, eg: import Keyboard from 'keyboardjs'
export class Input {
constructor(editor, controls) {
this.editor = editor
this.controls = controls
Keyboard.bind('shift', this.onCrouch, this.onCrouchRelease, {
preventRepeat: true,
noMeta: true,
})
Keyboard.bind('shift + mod + z', this.onRedo, null, {
cancels: ['shift'],
})
// ...etc
}
onCrouch = () => {
this.controls.axis.y = -1
}
onCrouchRelease = () => {
this.controls.axis.y = 0
}
onRedo = () => {
this.editor.redo()
}
// ...etc
} Anyways, just my two cents and some food for thought. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm building an 3D editor in the browser and attempting to use the following bindings:
w
a
s
d
to move the camera forward/back/strafe-left/strafe-rightshift
to move the camera downspace
to move the camera upmod + z
to undo changesshift + mod + z
to redo changesThe problem i'm facing is that moving the camera down (
shift
) and the redo function (shift + mod + z
) conflict with each other:Typically with undo/redo, when redoing something you would hold down
mod + shift
and then tapz
multiple times to redo a bunch of changes in the editor. The problem is that theshift
keydown bind (for moving the camera down) triggers immediately and his keyup event doesn't happen until you release all the keys. This results in the camera moving downward while you're redoing a bunch of changes.I think something like
KeyboardJS.releaseBind('shift')
would be useful, as we could put it in themod + shift + z
binding to immediately fire the keyup event for theshift
binding, effectively cancelling it.I can't seem to find any workarounds in the mean time, do you have any thoughts on this?
By the way, KeyboardJS is the most robust library i've found so far for browser based editors and games. The others (mousetrap, hotkeys etc) are all missing essential features for this use-case, for example releasing keys on window blur, cmd keyup events etc. Kudos to you for building such a useful package.
The text was updated successfully, but these errors were encountered: