Android KeyEvent

软件模拟按键事件

Posted by LXG on January 19, 2020

adb shell input


Usage: input [<source>] <command> [<arg>...]

The sources are: 
      keyboard
      mouse
      joystick
      touchnavigation
      touchpad
      trackball
      dpad
      stylus
      gamepad
      touchscreen

The commands and default sources are:
      text <string> (Default: touchscreen)
      keyevent [--longpress] <key code number or name> ... (Default: keyboard)
      tap <x> <y> (Default: touchscreen)
      swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
      press (Default: trackball)
      roll <dx> <dy> (Default: trackball)

input_keyevent

KeyEvent

KeyEvent.java


public class KeyEvent extends InputEvent implements Parcelable {

    private int mDeviceId;      // 按键设备
    private int mSource;        // 设备类型:键盘、鼠标,InputDevice
    private int mMetaState;     // 组合键功能键状态按下状态,例如CTRL、SHIFT
    private int mAction;        // down up
    private int mKeyCode;       // 键值
    private int mScanCode;      // 底层按键扫描码
    private int mRepeatCount;   // 长按时的重复次数
    private int mFlags;         // flags The flags for this key event
    private long mDownTime;     // 按下的时间
    private long mEventTime;    // 事件发生的时间
    private String mCharacters;

}