D
D
Dubolom Unicellular2020-05-05 11:33:58
JavaScript
Dubolom Unicellular, 2020-05-05 11:33:58

How to find special keys in RegExp?

I searched everything, I can’t figure out how to track the pressing of special keys on the keyboard (Shift, Alt, Ctrl, etc.):

$(document).on("keydown", () => {
  let specialKeys = e.key.search(?); // ???? Какое выражение подставить ????
});

Is there an expression that covers all SPECIAL keys, and Shift and Alt... ?
img7.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hzzzzl, 2020-05-05
@hzzzzl

https://developer.mozilla.org/ru/docs/Web/API/Keyb...
the event will have properties like event.ctrlKey true/false, no need to parse the key itself

$(document).on("keydown", (e) => {
  console.log('holding shift:', e.shiftKey)
});

A
Alexander, 2020-05-05
@Seasle

alt , ctrl , shift , tab:

$(document).on('keydown', event => {
    if (event.key === 'Tab') { ... }
});

Here's another one to help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question