Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

With the following code I can list the inputDevices connected to Android device.

public void onClick(View v) {
    if(v==mConnect){
        Toast.makeText(MainActivity.this, "TESTE", Toast.LENGTH_LONG).show();
        Log.d("INPUTDEVICES", "111111111111111111111");
        int[] teste;
        teste = new int[10];

        for(int i=0;i<5;i++){
        teste[i]=-1;
        }

        teste = InputDevice.getDeviceIds();
        for(int i=0;i<5;i++){
            Log.d("TESTE", Integer.toString(teste[i]));
            Log.d("TESTEE",InputDevice.getDevice(teste[i]).getName());
        }


    }
}

D/INPUTDEVICES( 6572): 111111111111111111111
D/TESTE   ( 6572): 1
D/TESTEE  ( 6572): Phone_key
D/TESTE   ( 6572): 3
D/TESTEE  ( 6572): ssd253x-ts
D/TESTE   ( 6572): 4
D/TESTEE  ( 6572): sun4i-keyboard
D/TESTE   ( 6572): 5
D/TESTEE  ( 6572): axp20-supplyer
D/TESTE   ( 6572): 8
D/TESTEE  ( 6572): Logitech USB Keyboard

Now I want to wait for text from a specific input device, in this case the input device 8 - Logitech USB Keyboard. Can you help me with that?

Thanks :)

EDIT

I want something like that:

@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
    Toast.makeText(UITestsActivity.this,
               "YOU CLICKED ENTER KEY",
                Toast.LENGTH_LONG).show();
        return true;
    }
    return super.dispatchKeyEvent(e);
};

but that works for all keyboard keys like 'a','b','c',...

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You can use the method getDeviceId() from the KeyEvent class to filter for your desired keyboard:

http://developer.android.com/reference/android/view/KeyEvent.html#getDeviceId%28%29

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.