P
P
plartem2017-01-12 18:41:24
JavaScript
plartem, 2017-01-12 18:41:24

JS How to track keystroke combinations (example - Alt+Ctrl+1)?

What is the solution for tracking keystrokes like Alt+Ctrl+1 - Alt+Ctrl+999 and the like?
Now I'm considering a variant of an array that is filled with data until alt and control are released, are there any other ways / methods?
I also looked at the documentation on commands in the chrome api ( https://developer.chrome.com/extensions/commands ), but there
1) you cannot use alt and control at the same time
2) there is no way to set one handler for numbers 1-999, etc. .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dmz9, 2017-01-13
@dmz9

You can do this with jiquery.
you hang up keydown on the document, then you listen to event.
there, among other things, there is
event.ctrlKey
event.altKey
event.shiftKey (seemingly)
well, the clamped event.key itself (an asterisk, for example)
put the code into a function, I don’t remember if the pressed button is considered a repetition of the event, but if not, just run the function after an interval

$(document).on('keydown',function (event) {
            if (event.ctrlKey&&event.key=='*') {
              // кодэ
            }
        })

M
M-ka, 2017-01-12
@M-ka

The problem is that the codes of the keys pressed come sequentially... and the allegedly pressed simultaneous combination will in fact be a sequence of such .... therefore, it remains only to track the sequences in different combinations, taking into account the time interval.... we can, for example, create a repository of the necessary codes and fix the time of pressing each and check for availability of interest and temporary deviations .... well, or google other solutions, but what will be the others? Yes, I think the same just with different implementation options))))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question