屏蔽系统鼠标按键
2013-10-15 11:51
239 查看
在一些系统开发中(例如机顶盒)有可能遇到需求不响应鼠标按键,在开发中怎么解决呢?下面我来给大家演示:
1.系统中按键的响应都是通过在ViewRootImpl中传递给View的,所以要想屏蔽按键就要在ViewRootImpl.java中寻找;
2.在setView中sWindowSession.add(mWindow, mSeq, mWindowAttributes,getHostVisibility(), mAttachInfo.mContentInsets,mInputChannel);建立View与WMS的联系这样WMS就能把消息传递给View了,但是怎么传递的呢?答案是:mInputChannel.
注册:
响应回掉处理:
3.下面看dispatchMotion函数:
看dispatchPointer函数,其实里面就是发送了DISPATCH_POINTER消息真正处理是在deliverPointerEvent函数;所以只需要在deliverPointerEvent函数中处理,具体代码:
1.系统中按键的响应都是通过在ViewRootImpl中传递给View的,所以要想屏蔽按键就要在ViewRootImpl.java中寻找;
2.在setView中sWindowSession.add(mWindow, mSeq, mWindowAttributes,getHostVisibility(), mAttachInfo.mContentInsets,mInputChannel);建立View与WMS的联系这样WMS就能把消息传递给View了,但是怎么传递的呢?答案是:mInputChannel.
注册:
if (mInputChannel != null) { if (mInputQueueCallback != null) { mInputQueue = new InputQueue(mInputChannel); mInputQueueCallback.onInputQueueCreated(mInputQueue); } else { InputQueue.registerInputChannel(mInputChannel, mInputHandler, Looper.myQueue()); } }
响应回掉处理:
private final InputHandler mInputHandler = new InputHandler() { public void handleKey(KeyEvent event, InputQueue.FinishedCallback finishedCallback) { startInputEvent(finishedCallback); dispatchKey(event, true);//处理按键 } public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { startInputEvent(finishedCallback); dispatchMotion(event, true);//处理触摸,鼠标,摇杆等消息 } };
3.下面看dispatchMotion函数:
private void dispatchMotion(MotionEvent event, boolean sendDone) { int source = event.getSource(); if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { Log.d(TAG,"----dispatchPointer----"); dispatchPointer(event, sendDone);//在有鼠标点击事件时会调用 } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { dispatchTrackball(event, sendDone); Log.d(TAG,"----dispatchTrackball----"); } else { dispatchGenericMotion(event, sendDone); Log.d(TAG,"----dispatchGenericMotion----"); } }
看dispatchPointer函数,其实里面就是发送了DISPATCH_POINTER消息真正处理是在deliverPointerEvent函数;所以只需要在deliverPointerEvent函数中处理,具体代码:
finishMotionEvent(event, sendDone, true); return;
相关文章推荐
- Qt 屏蔽系统按键、任务管理器、任务栏、鼠标,修改注册表
- 钩子编程(HOOK) 屏蔽全部按键、鼠标及系统功能键 (4)
- 钩子编程(HOOK) 屏蔽所有按键、鼠标及系统功能键 (4)
- 屏蔽系统按键(最简单方法)
- js屏蔽右键及各种按键 js蔽打印 js屏蔽鼠标右键 js禁止复制
- 使用Javascript封装实现屏蔽鼠标右键系统键菜单,并绑定自定义的事件
- 窗口置顶,并且屏蔽系统按键
- 网页屏蔽鼠标左右键和键盘按键功能
- js屏蔽鼠标左右键和键盘按键功能
- javascript屏蔽键盘和鼠标按键
- 如何不屏蔽Android系统的返回按键
- JavaScript 获取按键,并屏蔽系统 Window 事件
- 屏幕锁定源程序(屏蔽一般的系统热键以及键盘上任何你想要屏蔽的按键)
- 基于Android6.0源码修改屏蔽系统下方的虚拟按键以及上方的状态栏
- 怎么屏蔽鼠标所有左键消息在标题栏上(鼠标双击/单击系统图标,双击标题栏,最小化,最大化,关闭按钮)
- 修改系统鼠标左右按键快速切换
- 怎样不屏蔽Android系统的返回按键
- JavaScript屏蔽鼠标右键
- vmware虚拟机安装linux系统鼠标校准
- Windows系统的鼠标拖放操作的技巧