public void sendKeySync(KeyEvent event) {
??????? long downTime = event.getDownTime();
??????? long eventTime = event.getEventTime();
??????? int action = event.getAction();
??????? int code = event.getKeyCode();
??????? int repeatCount = event.getRepeatCount();
??????? int metaState = event.getMetaState();
??????? int deviceId = event.getDeviceId();
??????? int scancode = event.getScanCode();
??????? int source = event.getSource();
??????? int flags = event.getFlags();
??????? if (source == InputDevice.SOURCE_UNKNOWN) {
??????????? source = InputDevice.SOURCE_KEYBOARD;
??????? }
??????? if (eventTime == 0) {
??????????? eventTime = SystemClock.uptimeMillis();
??????? }
??????? if (downTime == 0) {
??????????? downTime = eventTime;
??????? }
??????? KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState,
??????????????? deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source);
??????? InputManager.getInstance().injectInputEvent(newEvent,
??????????????? InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
??? }
?? ?
??? /**
???? * Sends an up and down key event sync to the currently focused window.
???? *?
???? * @param key The integer keycode for the event.
???? */
??? public void sendKeyDownUpSync(int key) {?????? ?
??????? sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, key));
??????? sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, key));
??? }
需要系统权限才能使用
详细解决方案
Android4.0之后添加虚拟按键方法
热度:102 发布时间:2016-05-01 10:02:22.0
相关解决方案
- Android4.4.2KK竖屏强制更改替横屏的初步简略方案
- Stk简介跟核心类(android4.0 RIL Framework Java 部分)
- Android4.0中Alertdialog对话框点击边缘外部消失有关问题解决
- Android4.4中回绝发送Intent.ACTION_MEDIA_MOUNTED扫描SD卡的广播
- [odroid-pc] ubuntu12.04 64bit Android4.0.3 源代码编译报错及解决方法
- Android4.4KK中BOOT_COMPLETED广播有关问题的分析
- Android4.4 sd卡 写入权限有关问题 急求
- Android4.4的源码毕竟有多大
- Android4.0是不是不能开机自启动了?该如何解决
- android4.0 Launcher AppsCustomizePagedView里page滑动效果,该怎么解决
- android4.4 Launcher3如何修改主菜单布局
- Android4.4(MT8685)源码WIFI-初始化二
- Android4.4(MT8685)源码WIFI-初始化一
- Android4.4 应用分析——批改Launcher3应用以适应单屏壁纸
- Android4.4(MT8685)源码WIFI-起动
- Android4.4(MT8685)源码蓝牙解析-BLE搜寻
- android4.0.4 3G网络不能看视频,wifi可以瞧视频
- Android4.4 Framework分析——Android默许Home应用Launcher3的加载过程分析
- Android4.4 Framework分析——Activity窗口的创设过程(一)
- android4.0自定义锁屏apk模式总结
- Android4.1 开机logo的initlogo.rle在哪替换解决办法
- android4.0上网设立
- android4.0.4怎么将不带activity的widget应用一开机时就显示在桌面上
- android4.1.2的年历
- android4.0中在onCreate方法中findViewById()返回null解决方案
- Android4.0 对网络Jason对象的解析(1) 服务端
- Android4.0环境搭建要略
- android4.0后不能在住线程中使用网络连接。于是小弟我新开了一个线程,可是还是有异常
- android4.4 编译有关问题
- Android4.4深入显出之SurfaceFlinger框架-渲染一个surface(二)