This code seems to be the only one to output which keycode has been pressed on Android devices:
var input_field = document.getElementById('photo-id');
input_field.addEventListener('textInput', function(e) {
var char = e.data;
var keyCode = char.charCodeAt(0);
return true;
});
I need the result value of keyCode
outside of this function. I tried return keyCode;
instead of return true;
but this doesn't work.
How can I achieve this?
EDIT: Detailed explanation.
I'm using TagIt (http://aehlke.github.io/tag-it) and I'm trying to modify the code inside a function this.tagInput.keydown(function(event) {
which checks if a comma or space has been pressed to seperate words into tags. I don't know how excatly to pass it to this function or where to put the addEventListener
? Like I mentioned I just need to make this addition to recognize Android device keycodes.
EDIT2: Code stripped down.
this.tagInput.keydown(function(event) { // function of the library that checks every keydown event
// my addition to check for Android keycode input:
try {
var last_key_code_pressed;
this.addEventListener('textInput', function(e) {
var char = e.data;
var kc = char.charCodeAt(0);
last_key_code_pressed = kc;
console.log(kc); // works to output keycode here but not outside
return true;
});
console.warn(last_key_code_pressed);
} catch(e) {
console.warn("error:" + e);
}
// need to get the keycode of the addEventListener HERE
/* here are if-else-conditions to check if comma,
enter or space is pressed (code of the mentioned library) */