0

I have been trying to deal with getting the last input in to a text field on an Android app from Javascript.

I was originally trying to use the KeyUp, KeyDown and KeyPress events to get the KeyCodes from keyboard input however with android soft keyboards you will get the KeyCode 229 for every key other than backspace, space and enter.

So now I am using the onInput event however this just seems to alert me to the fact that something has been input in to a text field and not what that input was.

document.getElementById("textarea").addEventListener("input", function (e) {
    ClaroSpeak.KeyHandler(e);
}, false);

Does the input event some how let me know what the last change or key was, e.g. 'space' 'a' 'F' ect...

Lawtonj94
  • 309
  • 1
  • 5
  • 16
  • Possible duplicate of [Capture keys typed on android virtual keyboard using javascript](https://stackoverflow.com/questions/30743490/capture-keys-typed-on-android-virtual-keyboard-using-javascript) – reyiyo Oct 10 '17 at 19:05

1 Answers1

0

What about setting a 'global' variable and storing the last element in it?

gabriel garcia
  • 368
  • 3
  • 17
  • what if the user puts a element in the middle or a sentence? And how do i get the element in the first place unless you mean parse the text. – Lawtonj94 Feb 24 '16 at 11:42
  • What do u mean? I'm sorry I'm having a hard day D: – gabriel garcia Feb 24 '16 at 11:57
  • so you said store the last element, but am trying to get the key that was pressed last, this might not be the last element as it could be a 'backspace' or the user could input something in the middle of a word or sentence e.g. Hello, becomes Hekllo, in which case the last element is still o but the last key is 'k' – Lawtonj94 Feb 24 '16 at 11:59
  • Do you want to implement autocompletion in that input? You can still get the key pressed with `e.keyCode` and then do what you need to do in each case. I would recommend you to use `onkeypress`event – gabriel garcia Feb 24 '16 at 12:04
  • 1
    No you can not, on a soft keyboard KeyCodes will always be 229 since the value to be input can be several values e.g. e or é. because of this Google recommend that you do not use the keyPress keyUp or KeyDown events. – Lawtonj94 Feb 24 '16 at 12:12
  • So if I use an `onkeypress` event on my page and I visit the page from an android device will i get `e.keyCode = 229`? Take a look at this: [link](https://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html#fixed-virtual-key-codes) – gabriel garcia Feb 24 '16 at 13:16