Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Key code from KeyboardEvent in android is unidentified?

I will get a Char from keydown event.

In all browsers I can use event.key and it works fine, but in android the result is something else:

event.key: unidentified
event.code: ''
event.which: `229` (for [a-z0-9] is always this number)
window.event.keyCode: `229`

Here is an old stackoverflow post, but it doesn't work any more.

codepen demo for test in android (IOS and PC work fine)

How can i get key code or key string from KeyboardEvent

like image 849
miladfm Avatar asked Apr 11 '26 17:04

miladfm


1 Answers

i was going trough the same problem in android. i found out that using the input event solved the problem. this event contains the whole string which is actualy typed so if you just one the last character typed just take the last character of the string "event.data"

        document.addEventListener('input',function(event){
        console.log(event)
        let word = event.data === null ? '' : event.data
        input.search(word)

    })
like image 61
TamoMbobda Avatar answered Apr 13 '26 07:04

TamoMbobda