ブログ

ユーザースイッチの入力をコマンドから行う方法

at_shiita.ishigaki
2021年11月26日 9時12分

ユーザースイッチの入力を記録し、それを再生することで、ユーザースイッチの入力をコマンドから行います。
ユーザースイッチの入力を記録するには、evemu-recordコマンドを使用します。
※ここでは例として、out.logにユーザースイッチの入力を記録しています。

[armadillo ~]# evemu-record /dev/input/event0 out.log
(ユーザースイッチを押下)
(Ctrl+Cを入力)
[armadillo ~]# cat out.log
# EVEMU 1.3
# Kernel: 4.14-at38
# Input device name: "gpio-keys"
# Input device ID: bus 0x19 vendor 0x01 product 0x01 version 0x100
# Supported events:
#   Event type 0 (EV_SYN)
#     Event code 0 (SYN_REPORT)
#     Event code 1 (SYN_CONFIG)
#     Event code 2 (SYN_MT_REPORT)
#     Event code 3 (SYN_DROPPED)
#     Event code 4 ((null))
#     Event code 5 ((null))
#     Event code 6 ((null))
#     Event code 7 ((null))
#     Event code 8 ((null))
#     Event code 9 ((null))
#     Event code 10 ((null))
#     Event code 11 ((null))
#     Event code 12 ((null))
#     Event code 13 ((null))
#     Event code 14 ((null))
#     Event code 15 (SYN_MAX)
#   Event type 1 (EV_KEY)
#     Event code 28 (KEY_ENTER)
# Properties:
N: gpio-keys
I: 0019 0001 0001 0100
P: 00 00 00 00 00 00 00 00
B: 00 0b 00 00 00 00 00 00 00
B: 01 00 00 00 10 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 01 00 00 00 00 00 00 00 00
B: 02 00 00 00 00 00 00 00 00
B: 03 00 00 00 00 00 00 00 00
B: 04 00 00 00 00 00 00 00 00
B: 05 00 00 00 00 00 00 00 00
B: 11 00 00 00 00 00 00 00 00
B: 12 00 00 00 00 00 00 00 00
B: 14 00 00 00 00 00 00 00 00
B: 15 00 00 00 00 00 00 00 00
B: 15 00 00 00 00 00 00 00 00
################################
#      Waiting for events      #
################################
E: 0.000001 0001 001c 0000      # EV_KEY / KEY_ENTER            0
E: 0.000001 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +0ms
E: 0.200008 0001 001c 0001      # EV_KEY / KEY_ENTER            1
E: 0.200008 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +200ms
E: 0.799998 0001 001c 0000      # EV_KEY / KEY_ENTER            0
E: 0.799998 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +599ms
E: 1.049998 0001 001c 0001      # EV_KEY / KEY_ENTER            1
E: 1.049998 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +250ms
E: 1.699994 0001 001c 0000      # EV_KEY / KEY_ENTER            0
E: 1.699994 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +650ms
E: 2.609999 0001 001c 0001      # EV_KEY / KEY_ENTER            1
E: 2.609999 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +910ms

次に、記録したユーザースイッチの入力を再生するにはevemu-playコマンドを使用します。
また、確認用にevtestコマンドをバックグランドジョブで実行します。 <code lang="sh> [armadillo ~]# evtest /dev/input/event0 & [2] 895 Input driver version is 1.0.1 Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100 Input device name: "gpio-keys" Supported events: Event type 0 (EV_SYN) Event type 1 (EV_KEY) Event code 28 (KEY_ENTER) Properties: Testing ... (interrupt to exit) [armadillo ~]# evemu-play /dev/input/event0 < out.log Event: time 1637804736.787019, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0 Event: time 1637804736.787019, -------------- SYN_REPORT ------------ Event: time 1637804736.987389, type 1 (EV_KEY), code 28 (KEY_ENTER), value 1 Event: time 1637804736.987389, -------------- SYN_REPORT ------------ Event: time 1637804737.588492, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0 Event: time 1637804737.588492, -------------- SYN_REPORT ------------ Event: time 1637804737.838729, type 1 (EV_KEY), code 28 (KEY_ENTER), value 1 Event: time 1637804737.838729, -------------- SYN_REPORT ------------ Event: time 1637804738.489767, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0 Event: time 1637804738.489767, -------------- SYN_REPORT ------------ Event: time 1637804739.400006, type 1 (EV_KEY), code 28 (KEY_ENTER), value 1 Event: time 1637804739.400006, -------------- SYN_REPORT ------------ [armadillo ~]# kill $! //バックグラウンドのevtestを終了