I want to capture the keydown-event for a specific key (<) for all elements in a website. On Windows and iOS this is not a problem and everything is working fine. On Android (OnePlus 6, Android 10, Chrome 81, Gboard-Keyboard) however I couldnt manage to get the proper keyCode for the pressed key, therefore resulting in a essential function of my site not working. The keyCode always shows up as unidentified, 0 or 226.
What i am trying to accomplish:
- Focus any kind of element on the page
- Press <-key
- Focus a certain input as soon as the <-key was pressed
The code that is working on Windows and iOS:
$(document).keydown(function(e) {
e = e || window.event;
if (e.key === "<") {
$("#text2").focus();
} else {
// this is just for testing purposes
alert(e.key);
}
});
Here is a jsfiddle example: http://jsfiddle.net/rv6tc5mj/15/
What I´ve tried so far:
- switching from keydown to keyup, keypress - keyup doesnt change anything, keypress doesnt trigger on Android
- using another keyboard - no success
- using e.keyCode, e.which, e.charCode - no success
As it seems, this issue is known but these workarounds dont work in my case since i need to catch the keydown-event everywhere, not just in a single input.
Do you have any ideas or workarounds? Any help would be highly appreciated! Thanks in advance.