简体   繁体   English

安卓USB调试模式下,USB调试时可以把电脑键盘作为手机输入设备吗?

[英]In Android USB debugging mode, can I make my computer keyboard as input device to my mobile handset while USB debugging?

I like USB debugging on Android as it is faster than Emulator.我喜欢 Android 上的 USB 调试,因为它比模拟器更快。 I know I can use my keyboard in emulator but while debugging I want to use my computer keyboard (plugged to computer) instead of devices keyboard for making my input more faster.我知道我可以在模拟器中使用我的键盘,但是在调试时我想使用我的计算机键盘(插入计算机)而不是设备键盘来使我的输入更快。 Is that possible?那可能吗?

Share KM is a free app that lets you use your PC's keyboard and mouse to control your Android. Share KM是一款免费应用程序,可让您使用 PC 的键盘和鼠标来控制您的 Android。 Connection can be made over USB, WiFi, or Bluetooth.可以通过 USB、WiFi 或蓝牙进行连接。

It works a lot like adding an additional monitor to your computer – move your mouse to the edge of your screen and the cursor moves to the Android.它的工作原理很像在您的计算机上添加一个额外的显示器——将鼠标移动到屏幕边缘,光标移动到 Android。

I found a possibility via "adb tools".我通过“adb 工具”找到了一种可能性。 Connect your phone to the computer via usb cable and start adb at the computer terminal (eg Ubuntu)将手机通过usb线连接电脑,在电脑终端(如Ubuntu)启动adb

adb shell input keyboard text Hello    

or要么

adb shell input [<source>] <command> [<arg>...]    

This will give you the possibility to send text/keystrokes via computer/laptop keyboard to your smartphone.这将使您可以通过计算机/笔记本电脑键盘将文本/按键发送到您的智能手机。

Note: your input will be sent through two shells (computer and android device), so you'd have to "double escape" even spaces.注意:您的输入将通过两个外壳(计算机和安卓设备)发送,因此您必须“双重转义”甚至空格。 To avoid that, you may eg type为避免这种情况,您可以键入

adb shell
input keyboard 'any text you like, including shell-sensitive characters'

the second line is input on your android device in adb shell第二行是在您的 android 设备上的 adb shell 中输入

Tested on Ubuntu 14.04 LTS and Samsung Galaxy S3 with CyanogenMod.使用 CyanogenMod 在 Ubuntu 14.04 LTS 和三星 Galaxy S3 上进行测试。 Confirmed on Ubuntu 18.04 LTS and Moto G2 with Lineage OS在带有 Lineage OS 的 Ubuntu 18.04 LTS 和 Moto G2 上得到确认

It sounds like you want to use your PC's keyboard via some software on the PC rather than use a separate USB keyboard connected to the Android device.听起来您想通过 PC 上的某些软件使用 PC 的键盘,而不是使用连接到 Android 设备的单独 USB 键盘。

This actually is possible, but the details are device specific.这实际上是可能的,但细节是特定于设备的。 You would need to send key events via adb, but you'd need to determine the implementation-specific translation of characters to event codes, and even the event channel number.您需要通过 adb 发送关键事件,但您需要确定特定于实现的字符到事件代码的转换,甚至是事件通道号。 There are likely open source projects out there for doing this, and you'd be better off starting with one of those than trying to develop it from scratch.可能有一些开源项目可以用来做这件事,你最好从其中一个项目开始,而不是尝试从头开始开发它。

As for using a separate USB keyboard, as mentioned in comments this is a possibility on some more recent devices (typically you need an adapter cable with the ID pin grounded) but introduces the issue of not being able to use USB for ADB as well as a keyboard at the same time.至于使用单独的 USB 键盘,正如评论中提到的,这在一些较新的设备上是可能的(通常您需要一根带 ID 引脚接地的适配器电缆),但引入了无法将 USB 用于 ADB 的问题以及同时一个键盘。 One possible workaround would be to put ADB into TCP/wireless mode, unplug the computer and plug in the keyboard.一种可能的解决方法是将 ADB 置于 TCP/无线模式,拔下计算机并插入键盘。 A simpler approach could be to use a bluetooth keyboard.一种更简单的方法是使用蓝牙键盘。

Note that either the USB or bluetooth keyboard, and likely also the key event method, will cause the on-screen keyboard to pop up.请注意,无论是 USB 键盘还是蓝牙键盘,可能还有按键事件方法,都会导致屏幕键盘弹出。 People trying to use devices with external keyboards find this annoying and tend to install zero-height on screen keyboards;尝试使用带有外部键盘的设备的人发现这很烦人,并且倾向于在屏幕键盘上安装零高度; however, if you are testing what an actual user will do, then having the keyboard pop up will give a more realistic impression of the end-user experience (though of course the amount of screen real estate left after the keyboard varies from device to device).但是,如果您正在测试实际用户会做什么,那么弹出键盘会给最终用户体验提供更真实的印象(当然,键盘后剩余的屏幕空间量因设备而异)。

Plug your keyboard directly into Android USB OTG port and it will work.将您的键盘直接插入 Android USB OTG 端口即可使用。 Most of recent Android devices do support USB host mode apart very few models that have this feature intentionally removed (Google).大多数最近的 Android 设备确实支持 USB 主机模式,只有少数型号有意删除了此功能(谷歌)。 There is also a good our guestion about this . 我们对此也有很好的评价

With my Google Galaxy Nexus and Lenovo tablet, even mouse works (mouse pointer appears).使用我的 Google Galaxy Nexus 和联想平板电脑,甚至鼠标也能工作(出现鼠标指针)。 You probably can use USB switch that allows to share the keyboard between two computers.您可能可以使用允许在两台计算机之间共享键盘的 USB 开关。 Mind also that you need USB OTG and not USB device converter (there are some USB converters that fit into micro USB OTG port nicely but are for USB devices only).还要注意,您需要 USB OTG 而不是 USB 设备转换器(有一些 USB 转换器非常适合微型 USB OTG 端口,但仅适用于 USB 设备)。

Of course, ADB cannot use the USB port if it is already taken by the keyboard.当然,如果 USB 端口已经被键盘占用,ADB 不能使用。 Hence you need to use wireless for ADB.因此,您需要为 ADB 使用无线。

This proposal does not match fully your initial idea but seems matching the goal you are aiming to achieve (debug Android app directly on device using your keyboard).这个提议并不完全符合你最初的想法,但似乎符合你的目标(使用键盘直接在设备上调试 Android 应用程序)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM