How to detect Keycode.Return using an Android bluetooth keyboard?
I am working on an in game console for Android, working with bluetooth keyboards. I want to send console inputs by pressing the return key on the bluetooth keyboard. However I am running into trouble detecting the keypress.
I am using the following code to debug keypresses from the bluetooth keyboard:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class PrintKeyInputs : MonoBehaviour
{
public Text TextField;
void Update()
{
foreach(KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKeyDown(kcode))
TextField.text = "KeyCode down: " + kcode;
Debug.Log("KeyCode down: " + kcode);
}
}
}
Pressing the return key doesn't return anything on kcode
.
Any ideas how to get the return keypress?
Answer by rjth · Nov 28, 2016 at 04:32 PM
Okay so I'have figured it out myself. The bluetooth keyboard doesn't return Keycode.Return on pressing the return key. It sends Keycode.10. I am not sure if this is a bug, I didn't have the chance to test it with with other keyboards. However I made it work with this solution:
public class InputFieldActivator : MonoBehaviour
{
KeyCode BluetoothReturn = (KeyCode)10;
void Update()
{
if(Input.GetKeyDown(BluetoothReturn))
{
// Do something
}
}
}
Answer by YusufAfandi · May 06, 2017 at 08:32 PM
Oh God, you just save my live.
i just search it more about 3 hours. Damn
Thanks