I'm currently working on implementing character movement within a scene using Vue.js.
For this purpose, I have set up key bindings for both left and right buttons:
created () {
window.addEventListener('keyup', this.keyup)
window.addEventListener('keydown', this.keydown)
}
Below are the methods associated with these key events:
keydown (e) {
if (e.keyCode === 37) this.onWalkLeftPressed()
if (e.keyCode === 39) this.onWalkRightPressed()
},
keyup (e) {
if (e.keyCode === 37) this.onWalkLeftReleased()
if (e.keyCode === 39) this.onWalkRightReleased()
}
My goal is to enable instant character movement upon pressing and holding down a key, with no delay between actions. However, what I am experiencing is that once a key is pressed, there is an initial event fired followed by a slight delay of approximately 500ms before consecutive events are triggered until the key is released.
Is this behavior inherent to browsers, and do you have any suggestions on how I can override it to ensure seamless event firing without any interruptions?
You can view the current setup here: