简体   繁体   English

Android:模拟物理按键的键盘输入

[英]Android: simulate a physical button press of keyboard input

This might be a bit of an ambiguous question but I'll do my best at describing what I want to do. 这可能是一个模棱两可的问题,但是我会尽力描述我想做什么。 I need to make a service that will trigger a physical button press or input code to the currently active application. 我需要提供一项将触发物理按钮按下或向当前活动的应用程序输入代码的服务。 I'm trying to make a mapper for the Xperia Play touch pads so they can be used with apps and games that don't support them but mapping each axis corner to a physical keyboard key or input. 我正在尝试为Xperia Play触摸板制作一个映射器,以便它们可以与不支持它们但将每个轴角映射到物理键盘按键或输入的应用程序和游戏一起使用。

I can imagine such a feature would be a security risk to include in the standard Android SDK, although I may be wrong in which case there might be some kind of Intent or Receiver to handle those events. 我可以想象将这种功能包含在标准Android SDK中会带来安全隐患,尽管我可能错了,在这种情况下,可能会有某种Intent或Receiver来处理这些事件。

If there isn't, does anyone know how I could go about doing what I want to do? 如果没有,有谁知道我该怎么做?

Try sendkey command in you adb shell. 尝试在adb shell中使用sendkey命令。

You cannot do it in application yet. 您还不能在应用程序中执行此操作。

You cannot do this in a normal App, but you have two other options depending on your needs: 您无法在普通的应用程序中执行此操作,但是您可以根据需要选择其他两个选项:

  • Android SDKs MonkeyRunner lets you automate input Android SDKs MonkeyRunner可让您自动输入
  • Using root to directly manipulate the keyboard events in android; 使用root直接在android中操纵键盘事件; I know that there are tools for linux with Xorg, but I'm not sure if they will work on android: xvkbd or xdotool 我知道有一些Xorg的Linux工具,但是我不确定它们是否可以在android上使用: xvkbdxdotool

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

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