Is it possible to program Android to act as physical USB keyboard?

前端 未结 13 869
暖寄归人
暖寄归人 2020-12-04 07:00

What I really want to know is whether it is a hardware problem, or a software problem. Could I plug my android phone into a computer via USB and have it act as a hardware ke

相关标签:
13条回答
  • 2020-12-04 07:15

    I've modified kernel on Nexus 7 to act like standard HID keyboard and mouse, without losing MTP/ADB/other USB functionality.

    You can use usb-gadget-test commandline utility to send keystrokes and mouse movements to your PC. I want to create a remote admin app later, which will send key events and receive video from camera.

    Kernel patch, binaries and instructions: https://github.com/pelya/android-keyboard-gadget

    Edit: I've published a proper app to Google Play, if your Nexus 7 is rooted you can flash kernel right from the app, and send keypresses with it.

    0 讨论(0)
  • 2020-12-04 07:17

    Looks like someone finally did it, it is a tiny bit ugly - but here it is:

    http://forum.xda-developers.com/showthread.php?t=1871281

    It involves some kernel recompiling, and a bit of editing, and you loose partial functionality (the MDC?) .. but it's done.

    Personally though, now that I see the "true cost", I would probably put together a little adapter on a Teency or something - assuming that Android can talk to serial devices via USB. But that's based on the fact that I have a samsung, and would require a special cable to make a USB connection anyway - no extra pain to have a little device on the end, if I have to carry the damn cable around anyway.

    0 讨论(0)
  • 2020-12-04 07:17

    You have to establish some kind of connection to do that android-out-of-the-box, like via tcp/ip and adb, so no not w/o installing at least adb and a listener on the computer.

    But if you have an activity that sends the hardware keyboard like data via usb then why not? Won't be easy i guess. At this point the usuas forum answer comes right away: "Why don't you change your plans and ...." :)

    0 讨论(0)
  • 2020-12-04 07:18

    Don't give up. Linux can do it with the right hardware, via "USB Gadgets." And giving the following facts:

    1. My old Nokia N95 could use it's USB to be a "Mass Storage Device", a "Media Player", "a GSM modem", or to print photos.
    2. I can plug an iPhone into an iPad via a the Apple USB-Camera passive adapter, and they transfer pictures.
    3. iPhone can obvious present as a number of things, e.g. when they go into DFU.

    Why is all this relevant?

    Because if I was writing a linux phone I know what it would do, and how it would do it. And the answer would involve USB Gadgets.

    Reading one of the links that was posted here,

    It's the Linux kernel, the code is in drivers/usb/gadget/ in the kernel.org tree if you are interested. Android does have a few specific gadget patches that are not in mainline, but it's not all that much. You can see all of this by just checking out their kernel git tree, no need to bother their developers.

    I would guess that you would have a shot at it - but it would involve recompiling the android kernel/operating system - or at least having a build environment in which you /could/ rebuild the kernel if you wanted.

    BTW, I have an Atmel NGW100mkII, which support USB gadgets, but doesn't ship with the HID module. And I'll be having to do the above and more.

    0 讨论(0)
  • 2020-12-04 07:21

    Seems someone have done it by patching the kernel. I just came across a paper titled "Exploiting Smart-Phone USB Connectivity For Fun And Profit" by Angelos Stavrou, Zhaohui Wang, Computer Science Department George Mason University, Fairfax, VA. (available freely by googling the above title). Here the two researchers are investigating the possibility of a compromised android device controlling the attached PC by having the android device presenting itself as an HID device (keyboard). As a proof of concept, it seems that they have successfully patched a kernel doing exactly what you want. They didn't provide detailed steps but anyway I just quote what they said they've done:

    .....we developed a special USB gadget driver in addition to existing USB composite interface on the Android Linux kernel using the USB Gadget API for Linux[4]. The UGAL framework helped us implement a simple USB Human Interface Driver (HID) functionality (i.e. device driver) and the glue code between the various kernel APIs. Using the code provided in: “drivers/usb/gadget/composite.c”, we created our own gadget driver as an additional composite USB interface. This driver simulates a USB keyboard device. We can also simulate a USB mouse device sending pre-programmed input command to the desktop system. Therefore, it is straightforward to pose as a normal USB mouse or keyboard device and send predefined command stealthily to simulate malicious interactive user activities. To verify this functionality, in our controlled experiments, we send keycode sequences to perform non-fatal operations and show how such a manipulated device can cause damages In particular, we simulated a Dell USB keyboard (vendorID=413C, productID=2105) sending ”CTRL+ESC” key combination and ”U” and ”Enter” key sequence to reboot the machine. Notice that this only requires USB connection and can gain the ”current user” privilege on the desktop system. With the additional local or remote exploit sent as payload, the malware can escalate the privilege and gain full access of the desktop system.

    0 讨论(0)
  • 2020-12-04 07:21

    I have some experience here as a user. The most obvious solution is via tcp/ip via a client/server model. Many of the tools out there like airkeyboard (http://www.freenew.net/iPhone/air-keyboard-111/171415.htm) utilize this method for creating a keyboard/mouse replacement using a smartphone os. Note that there are some security issues that become apparent in the implementation. For instance, you must be logged in to utilize the server componenents.

    Other cross platform tools (ie windows/mac controlling another windows/mac instance) utilize a similar approach. See synergy: http://synergy-foss.org/

    0 讨论(0)
提交回复
热议问题