Can't see mouse and keyboard device with usbManager android

試著忘記壹切 提交于 2019-12-06 06:37:34

You can detect mouse/keyboard via InputManager:

if(Build.VERSION.SDK_INT > 15) {
    InputManager inptmgr = (InputManager)getSystemService(INPUT_SERVICE);
    int[] inputs = inptmgr.getInputDeviceIds();
    for(int i = 0;i<inputs.length;i++) {
        String devicename = inptmgr.getInputDevice(inputs[i]).getName();
        if(devicename.toLowerCase().contains("mouse")) {

        } else if(devicename.toLowerCase().contains("keyboard")) {

        }
    }
}

As for any other data you may want to collect, you can browse all the other methods under getInputDevice() such as getVendorId(), getProductId(), getMotionRange(), getKeyCharacterMap(), and others.

Hope this helps!

If you can already use the HID device for input, it' working as a input device(keyboard or mouse) and you don't need to access it as a USB device. You can simply catch the input from the device via listeners such as OnKeyListener.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!