android 模拟物理按键
16lz
2021-01-23
package com.example.sh04799.myapplication2;import android.app.Instrumentation;import android.util.Log;/** * Created by zhangwei on 2017/6/19. */public class CustomFuncManager { private static CustomFuncManager mInstance; // 模拟物理按键onKey事件 private Instrumentation instrumentation = new Instrumentation();; public static CustomFuncManager getInstance() { if (mInstance == null) { mInstance = new CustomFuncManager(); } return mInstance; } public void sendKeyEvent(final int keyCode) { Thread thread = new Thread(new Runnable() { @Override public void run() { if (instrumentation != null) { instrumentation.sendKeyDownUpSync(keyCode); } else { Log.d("zw", "instrumentation is null"); } } }); thread.start(); }}
更多相关文章
- android添加外部按键
- 隐藏Android下的虚拟按键
- Android交互体验必知:功能按键事件
- android:imeOptions 控制软键盘右下角按键
- Android面面观——Android事件处理下(按键、触摸屏和滚动球的一些
- Android 通过按键旋转屏幕
- android 实现模拟按键
- android沉浸式+虚拟按键+Fragment+CoordinatorLayout(1)
- android监听软键盘enter按键