jaywcjlove/hotkeys-js

by pass browser shortcut on keydown/keyup?

mysolo opened this issue · 3 comments

mysolo commented

good morning,

We use hotkey.js as follows:

hotkey.unbind()
hotkeys(shortcut.key, shortcut.options , event)

with options: { keydown: false, keyup: true }

in order to receive only events on a keyup and avoid repetition events when keys remain pressed. This works well on shortcuts not used by the browser.
However, on command + Z, command + X, command + C, etc., for example, the browser takes over.
If you don't use keydown/keyup, it works, but we receive continuous events if the keys remain pressed.
Is there a way of receiving a single event for each key pressed, or of unbinding the browser keys when the same shortcut is used?

Ainias commented

As far as I understand the documentation, you can check for the event.type inside your callback. If it is keydown, return false to prevent the browser default. If it is keyup, do your normal callback

rouilj commented

Check event.repeat. If it is true your getting an auto-repeating key and you can ignore the event. If it's false handle the event.

check for the event.type inside your callback
If it is keyup, do your normal callback

Unfortunately, on the keyup event isn't even reported into the hotkeys when it's system-related 🤷🏻‍♂️🤷🏻‍♂️🤷🏻‍♂️