Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Keycode 10 for 'Enter' on Android for external keyboards

Discussion in 'Android' started by leifcr, Jul 19, 2016.

  1. leifcr

    leifcr

    Joined:
    Jul 18, 2016
    Posts:
    4
    External bluetooth keyboards return keycode 10 for return/enter instead of keycode 13.

    To reproduce/test add this code to a script on any GameObject:
    Code (CSharp):
    1. void OnGUI() {
    2.         Event e = Event.current;
    3.         if (e.isKey) {
    4.             Debug.Log ("KeyCode: String:" + e.keyCode.ToString() + " Type: " + e.type);
    5.         }
    6.     }
    Log output:

    07-19 14:38:33.021 26208 26223 I Unity : KeyCode: String:10 Type: KeyDown
    07-19 14:38:33.021 26208 26223 I Unity : UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    07-19 14:38:33.021 26208 26223 I Unity : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    ..........
    07-19 14:39:19.706 26208 26223 I Unity :
    07-19 14:39:19.789 26208 26223 I Unity : KeyCode: String:10 Type: KeyUp
    ........

    Since KeyCode 10 is not in KeyCode Enum, it cannot be used in Input.GetKey, Input.GetKeyDown or Input.GetKeyUp.

    Either the keycode list needs LineFeed as a keycode, or it has to be translated to 13 (Return).
     
    rjth likes this.
  2. Alex-Lian

    Alex-Lian

    Guest

    Is this a regression on 5.4 beta? Could we have a bug report please?
     
  3. leifcr

    leifcr

    Joined:
    Jul 18, 2016
    Posts:
    4
    Not sure if it is a regression on Unity 5.4 beta.

    Development platform: Ubuntu 16.04, Unity 5.4 beta.
    Test setup:
    Xperia Z5 + Logitech Bluetooth keyboard
    Galaxy Tab S2 + Logitech Bluetooth keyboard
    Xperia Z5 + Unnamed bluetooth keyboard
    Galaxy Tab S2 + Unnamed bluetooth keyboard

    Bug reports are disabled in the linux editor, that's why I posted on the 5.4 beta.
     
  4. Alex-Lian

    Alex-Lian

    Guest

    This isn't a general support forum though, it probably best is served on the android forums so I'll move it.

    Though, forum posts are not easy ways for us to track bugs through our system. We really do need a bug report if you could.
     
  5. leifcr

    leifcr

    Joined:
    Jul 18, 2016
    Posts:
    4
    Will do as soon as the linux build includes options for submitting bug reports.
     
  6. rjth

    rjth

    Joined:
    Dec 6, 2014
    Posts:
    8
    I had the same issue with the Logitech K380 keyboard on Android. I've managed to make it work with the script below:

    Code (CSharp):
    1. public class InputFieldActivator : MonoBehaviour
    2. {
    3.      KeyCode BluetoothReturn = (KeyCode)10;
    4.      void Update()
    5.      {
    6.          if(Input.GetKeyDown(BluetoothReturn))
    7.          {
    8.              // Do something
    9.          }
    10.      }
    11. }
     
    -chris likes this.
  7. babji3

    babji3

    Joined:
    May 28, 2015
    Posts:
    179
    Hi, what about other keys, like Alphabets?
    Help