I'm in the process of developing an application and I'm looking to prevent the space bar from scrolling my page
My framework of choice is VUE, and I am trying to trigger a method using an event handler
However, when I attempt to call the 'keymonitor' method, I encounter an error:
An unexpected block statement surrounds the arrow body; please move the returned value immediately after the
=>
Is there a proper way to invoke the 'keymonitor' method?
window.addEventListener('keydown', e => {
return this.keymonitor(e)
})
keymonitor(event) {
if (this.sendkey === 1) {
if (event.key.length === 1) {
this.keyDown = {
cmd: 'keyboard',
key: event.key,
}
} else if (
event.key === 'Enter' ||
event.key === 'Tab' ||
event.key === 'PageUp' ||
event.key === 'PageDown' ||
event.key === 'End' ||
event.key === 'Home' ||
event.key === 'ArrowLeft' ||
event.key === 'ArrowUp' ||
event.key === 'ArrowRight' ||
event.key === 'ArrowDown' ||
event.key === 'Backspace' ||
event.key === 'Delete' ||
event.key === 'Escape'
) {
this.keyDown = {
cmd: 'keyboardSpecial',
key: event.key,
}
// event.preventDefault();
}
console.log('eventkey: ')
console.log(this.keyDown)
this.sendMessage(this.keyDown)
}
if (event.which === 32) {
console.log('SPACE')
}
return false
},