2

I'm trying to get an event going when pressing specific keys.

The keys I'm trying to listen to are bltzr and on my browser I can only press bltz but not the last r.

I'm trying this on Windows, I have tried on OSX and I still can't listen to all the keys pressed. However the error is different (can't tell you more about it because it wasn't my device)

This is the code I'm using to listen if keys are pressed :

var log = $('#log')[0], pressedKeys = []; $(document.body).keydown(function (evt) { var li = pressedKeys[evt.keyCode]; if (!li) { li = log.appendChild(document.createElement('li')); pressedKeys[evt.keyCode] = li; } $(li).text('Down: ' + evt.keyCode); $(li).removeClass('key-up'); }); $(document.body).keyup(function (evt) { var li = pressedKeys[evt.keyCode]; if (!li) { li = log.appendChild(document.createElement('li')); } $(li).text('Up: ' + evt.keyCode); $(li).addClass('key-up'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul id="log"> <li>List of keys:</li> </ul>

Why can I not see these specific keys down at the same time ?

Is there a way to listen to all of them at the same time ?

1
  • For getting dom with id there is no need for this var log = $('#log')[0],. Only $('#log') will be enough Commented Mar 10, 2017 at 17:43

1 Answer 1

1

You'll need to find a different method. On most (cheap) keyboards there is a maximum number keys that can be pressed & held simultaneously. This maximum depends on the keyboard hardware, protocols and connector type.

You can get information about the specifics by learning about n-key rollover (NKRO) versus matrix (usually a 2-key rollover) keyboards. The best keyboard will have NKRO support with a PS/2 connector (USB is limited) - related answer.

There also appears to be a limitation on touches depending on the device - basic (1-11) & large devices (50).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.