屏蔽系统鼠标按键

在机顶盒系统开发中,有时需要阻止鼠标按键的响应。实现这一功能的方法是在ViewRootImpl.java中操作,通过修改setView方法中mInputChannel的处理,来中断鼠标按键事件的传递,从而达到屏蔽的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在一些系统开发中(例如机顶盒)有可能遇到需求不响应鼠标按键,在开发中怎么解决呢?下面我来给大家演示:

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;






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值