jaywcjlove / hotkeys-js

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
https://jaywcjlove.github.io/hotkeys-js
MIT License
6.65k stars 410 forks source link

by pass browser shortcut on keydown/keyup? #446

Open mysolo opened 1 year ago

mysolo commented 1 year ago

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 1 year ago

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 1 year ago

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.

oleksandr-danylchenko commented 2 months ago

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 🤷🏻‍♂️🤷🏻‍♂️🤷🏻‍♂️