模拟来自ADB终端的按键组合 [英] Simulating combination of key presses from ADB terminal

查看:573
本文介绍了模拟来自ADB终端的按键组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向Android版Chrome发送" CTRL + W "以关闭活动标签.我尝试了很多事情,但是从终端上实现它并没有成功. (如果我将USB键盘与OTG连接,则可以使用CTRL + W关闭选项卡)

I want to send "CTRL + W" to the Chrome for Android to close active tab. I tried lots of things but there is no success to achieve it from terminal. (If i connect a USB Keyboard with OTG, i can close the tab with CTRL+W)

首先,我不想为此编写应用程序,我只希望Shell命令从Tasker中使用它.

Firstly i do not want to write a application for this, i only want a shell command to use it from Tasker.

我在某处读到要实现此功能(CTRL + W按键),我必须像这样模拟按键:

I read somewhere that to achieve this (CTRL+W keypress), i have to simulate key presses like this:

向下CTRL
下W
上W
向上CTRL

Down CTRL
Down W
Up W
Up CTRL

要在终端上实现这一点,似乎我必须使用" sendevent ".

And to achieve this from terminal, it seems i have to use "sendevent".

我可以用"sendevent"模拟所有硬件按键,但是不能用它模拟普通按键.

I can simulate all hardware keypress with "sendevent" but can not simulate the normal keys with it.

例如,上下按电源键:

sendevent /dev/input/event1 1 116 1
sendevent /dev/input/event1 0 0 0
sendevent /dev/input/event1 1 116 0
sendevent /dev/input/event1 0 0 0

我使用此命令,但是我不能使用此命令发送普通密钥. (例如a,b,c等)

i use this commands, but i can not use this commands to send normal keys. (for example a,b,c etc)

event1是gpio键,所以我正在使用它.其他所有输入事件都是传感器,一个是充电驱动器. (max77693-muic)

The event1 is the gpio-keys, so i'm using it. And all the other input events are sensors and one is the charging driver. (max77693-muic)

"getevent -p"的输出表明:

The output of the "getevent -p" says that:

add device 1: /dev/input/event9
  name:     "compass_sensor"
  events:
    REL (0002): 0000  0001  0002  0003  0004  0005  0006  0007 
                0008  0009 
  input props:
    <none>
add device 2: /dev/input/event6
  name:     "barometer_sensor"
  events:
    REL (0002): 0000  0001  0002 
  input props:
    <none>
add device 3: /dev/input/event5
  name:     "light_sensor"
  events:
    REL (0002): 0000  0001  0002  0009 
  input props:
    <none>
add device 4: /dev/input/event4
  name:     "proximity_sensor"
  events:
    ABS (0003): 0019  : value 1, min 0, max 1, fuzz 0, flat 0, resolution 0
  input props:
    <none>
add device 5: /dev/input/event3
  name:     "gyro_sensor"
  events:
    REL (0002): 0003  0004  0005 
  input props:
    <none>
could not get driver version for /dev/input/mice, Not a typewriter
add device 6: /dev/input/event7
  name:     "Midas_WM1811 Midas Jack"
  events:
    KEY (0001): 0072  0073  00e2 
    SW  (0005): 0002  0004 
  input props:
    <none>
add device 7: /dev/input/event1
  name:     "gpio-keys"
  events:
    KEY (0001): 0072  0073  0074  00ac 
  input props:
    <none>
add device 8: /dev/input/event0
  name:     "max77693-muic"
  events:
    KEY (0001): 0072  0073  00a3  00a4  00a5 
  input props:
    <none>
add device 9: /dev/input/event8
  name:     "sec_touchkey"
  events:
    KEY (0001): 008b  009e 
    LED (0011): 0008 
  input props:
    <none>
add device 10: /dev/input/event2
  name:     "sec_touchscreen"
  events:
    ABS (0003): 002f  : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
                0030  : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                0031  : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                0032  : value 0, min 0, max 30, fuzz 0, flat 0, resolution 0
                0035  : value 0, min 0, max 719, fuzz 0, flat 0, resolution 0
                0036  : value 0, min 0, max 1279, fuzz 0, flat 0, resolution 0
                0039  : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0
                003c  : value 0, min -90, max 90, fuzz 0, flat 0, resolution 0
                003d  : value 0, min 0, max 1, fuzz 0, flat 0, resolution 0
  input props:
    INPUT_PROP_DIRECT

我的gpio-keys布局文件"/system/usr/keylayout/gpio-keys.kl"也是如此:

Also my gpio-keys layout file "/system/usr/keylayout/gpio-keys.kl" like this:

key 115   VOLUME_UP         WAKE
key 114   VOLUME_DOWN       WAKE
key 116   POWER             WAKE
key 172   HOME              WAKE

我可以使用以下命令发送所有正常的按键事件:

I can send all normal keyevents with:

"input keyevent KEYCODE_X" 

并发送多个:

"input keyevent KEYCODE_X KEYCODE_Y"

您应该认为它可以像这样工作:

You should think it can works like this:

"input keyevent KEYCODE_CTRL_LEFT KEYCODE W"

但是按键事件立即上下移动,我不能用它发送CTRL + W组合键.

but keyevent down and up immediatly and i can not use it to send CTRL+W combination.

我知道,答案应该是"sendevent".但是我找不到.

I know, the answer should be with "sendevent". But i can not find.

我还试图将一些伪造的密钥添加到密钥布局文件中,如下所示:

I also tried to adding some fake keys into the key layout file like this:

key 115   VOLUME_UP         WAKE
key 114   VOLUME_DOWN       WAKE
key 116   POWER             WAKE
key 172   HOME              WAKE
key 19    Q

我重新启动电话,然后尝试:

i restarted the phone, then tried:

sendevent /dev/input/event1 1 19 1
sendevent /dev/input/event1 0 0 0
sendevent /dev/input/event1 1 19 0
sendevent /dev/input/event1 0 0 0

但是它永远不会在任何文本框中写入"Q".

But it never writes "Q" into the any textbox.

请帮助,谢谢您的帮助.

Please help, thanks for your helps.

推荐答案

哦,是的!我不知道为什么,但是每当我感到被卡住时,我都会进入stackoverflow,一旦我开始写问题就以某种方式找到答案... xD 无论如何,我可以通过以下过程来做到这一点:

Oh YES!! I dont know why but whenever I feel stuck I come to stackoverflow and as soon as I start writing the question somehow I find the answer... xD Anyways, I was able to do it by following procedure:

  1. 转到/system/usr/keylayout/
  2. 在我的情况下,没有gpio键,反正打开 Generic.kl
  3. 它具有模拟任何东西所需的所有键码...例如CTRL_RIGHT键码为97,W键码为17
  4. 这就是您所需要的,现在打开tasker->新任务->添加等待5秒->运行shell: input keyevent 97 input keyevent 17
  1. Go to /system/usr/keylayout/
  2. In my case there was no gpio-keys, anyways open Generic.kl
  3. It has all the keycodes you would need to simulate anything... such as for CTRL_RIGHT keycode is 97 and for W keycode is 17
  4. Thats all you need, now open tasker --> New task --> Add wait 5 sec --> Run shell: input keyevent 97 input keyevent 17

现在运行命令并快速打开chrome,瞧! 5秒钟后,您的标签页就会消失!

Now run the command and quickly open chrome, voila! in 5 secs you will see your tab disappearing!

希望对以后的任务专家都有帮助;)

Hope that helps all the future tasker pros ;)

荣誉...

这篇关于模拟来自ADB终端的按键组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆