控制与蓝牙鼠标/ presenter Android应用 [英] Controlling Android app with bluetooth mouse/ presenter

查看:173
本文介绍了控制与蓝牙鼠标/ presenter Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是一个简单的问题,因为大多数的所有答复涉及使用手机作为指针,但我想要做的就是使用鼠标/ presenter /指针来控制Android平板电脑上搜索。我买了这个泰格斯Bluetoogh presenter (亚马逊),我想接口,可在我的7英寸平板电脑的应用程序。现在,我已经花了两个小时未果搜索谷歌和计算器我想我应该寻求帮助。

This is not an easy question to search on as most all replies involve using a phone as a pointer but what I want to do is use a mouse/ presenter/ pointer to control an Android tablet. I bought this Targus Bluetoogh Presenter (Amazon) and I want to interface to an app on my 7in tablet. Now that I have spent two hours unsuccessfully searching Google and stackoverflow I thought I should ask for help.

蓝牙presenter工作正常。它的作用就像一个鼠标,我可以滚动,点击和运行我的应用程序就好了。但是,这是该平板电脑将被安装在一个移动的船光天化日之下,用鼠标指针的这个优良的增益调整是不会工作的应用程序。我相信,即使我能控制的指针,我可能甚至无法看到它。这是与黑色背景上的1英寸高的白色字母高生存力的应用程序。你不能看到一个小小的鼠标指针。

The bluetooth presenter works fine. It acts like a mouse and I can scroll and click and run my app just fine. But this is an application where the tablet will be mounted in broad daylight on a moving boat and using this fine gain adjustment of the mouse pointer isn't going to work. I am sure even if I could control the pointer, I likely could not even see it. This is a high viability app with 1 inch high white letters on a black background. You just can't see a tiny mouse pointer.

我需要的是让在presenter两个可编程按钮,以推进对应用程序的几个按钮的焦点,然后让另一个按钮preSS他们。眼下,对presenter可编程按钮之一,突出了在我的应用程序的按钮中的一个,但用右键单击刚刚触发了哪个按钮是鼠标指针下。我想我需要两个可编程按钮是提前进入,但,这只是一个猜测。我打开,将工作的任何解决方案。

What I need is to get the two programmable buttons on the presenter to advance the focus on the few buttons on the app and then have the other button press them. Right now, one of the programmable buttons on the presenter highlights one of the buttons on my app but using the right click just fires off whichever button is under the mouse pointer. I am thinking I need the two programmable buttons to be advance and enter but that is just a guess. I am open to any solution that will work.

我不知道,即使从哪里开始。我应该编程的东西在我的应用程序?我需要一个接口的应用程序编程按钮?有什么在Play商店,这将只是做我想要什么?当我搜索蓝牙鼠标所有我看到的是,使用手机来控制电脑的应用程序。不是我想要的方向。我需要一些帮助或指导。

I don't know even where to start. Should I be programming something in my app? Do I need an interface app to program the buttons? Is there something in the Play store that will just do what I want? When I search on bluetooth mouse all I see is apps that use the phone to control a computer. Not the direction I want. I need some help or direction.

推荐答案

好吧,我想我已经为你准备了一个可行的解决方案。原来我有几件事情是错误的。对于一个 dispatchKeyEvent()的onkeydown()更好,因为它停止了音量键presses从使它通过对系统(我的设备上便引起蜂鸣声打,但没有成交量的变化)。而且它也证明,你需要使用仪表类发送恶搞的KeyEvent,而不是手动调用 dispatchKeyEvent()。仪器仪表类不会使主线程的方法调用要么,所以你一定要包裹在自己的线程中调用。

Ok I think I've got a working solution for you. Turns out I had a few things wrong. For one dispatchKeyEvent() is better than onKeyDown() because it stops the volume button presses from making it through to the system(on my device they caused a beep sound to play, but no volume change). And it also turns out that you need to use the Instrumentation class to send the spoof KeyEvents instead of manually calling dispatchKeyEvent(). The Instrumentation class won't make its method calls from the main thread either, so you've got to wrap the calls in their own thread.

我还了解到,为什么你的一些设备上的按钮进行了发送两个关键事件117和71的那些比赛多达<大骨节病>切换 + <大骨节病> [对于我们而言,我们可以忽略移位preSS和只使用<大骨节病> [采取行动对我们来说。

I also learned why some of the buttons on your device were sending two key events 117 and 71. Those match up to shift+[ For our purposes we can ignore the shift press and use just the [ to take action for us.

下面是一个重写的dispatchKeyEvent()方法,这似乎是为我工作。

Here is an overridden dispatchKeyEvent() method that seems to be working for me.

@Override
public boolean dispatchKeyEvent(KeyEvent ke){
int keyCode = ke.getKeyCode();
if(ke.getAction() == KeyEvent.ACTION_DOWN){
    if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) 
    { 
        /************************************** 
         * What ever code snippet you put 
         * here will run whenever you press the
         * volume down button on your presenter
         * device
         **************************************/
        return true;
    }else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP) 
    { 
        /************************************** 
         * What ever code snippet you put 
         * here will run whenever you press the
         * volume up button on your presenter
         * device
         **************************************/
        return true;
    }else if (keyCode == 30){ 
        /************************************** 
         * What ever code snippet you put 
         * here will run whenever you press the
         * left programmable button on your 
         * presenter device
         **************************************/
         return true;
        }
    else if (keyCode == 59){
        /************************************** 
         * This was an attempt to get it to ignore
         * the shift keypress coming from the
         * left/right arrow keys on the devices
         * ignoring that would in theory make
         * those keys function as up/down focus
         * movers. Didn't seem to work though.
         * you could probably remove this branch
         * of the if statement if you want.
         * However since those buttons do send 
         * key events to the device it should 
         * should still be possible override these
         * buttons somehow.
         **************************************/
        return true;
    }
}else if(ke.getAction() == KeyEvent.ACTION_UP){
    /************************************** 
     * This section will catche the "release"
     * events from all of the keys we are using
     * and tell the system that we've handled
     * them. So that the system will not pass
     * the events along to anything else.
     **************************************/
    if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) 
    { 
        /************************************** 
         * If you had any reason / desire to
         * you could put a code snipet here and it
         * would be run when you let go after 
         * pressing the volume down button on your
         * presenter device.
         **************************************/
        return true;
    }else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP) 
    { 
        return true;
    }else if (keyCode == 59){
        return true;
    }else if (keyCode == 30) {
        return true;
    }
}

/************************************** 
 * The following line is needed so that
 * the system will treat any key events 
 * that we aren't interested in normally.
 * i.e. the back button on the tablet, by
 * by calling super.dispatchKeyEvent(), we
 * ensure that the back button still behaves
 * like normal.
 **************************************/
return super.dispatchKeyEvent(ke);
}

这将允许你把你的presenter设备上的3个按钮(卷起来,卷下,左可​​编程按钮)控制,把你的code片段的if语句的适当的分支你可以做任何的那些3个按钮做任何你想要的。

This will allow you to take control of 3 buttons on your presenter device (Vol Up, Vol Down, and the Left programmable button), by putting your code snippets in the appropriate branch of the if statement you can make any of those 3 buttons do whatever you want.

我创建了一个测试项目,该项目实现了这一点,你可以下载这里压缩项目文件夹的,如果你想看到整个事情。在这个测试项目中,我将它设置,使体积上/下将作为D-垫向上/向下,让您将焦点移动到您的活动中不同的看法。

I've created a test project that implements this you can download the zipped project folder here if you'd like to see the whole thing. In this test project I've set it up so that vol up/down will function as d-pad up/down which will allow you to move focus to different views within your activity.

下面是code,你可以把里面的if语句的分支之一,以欺骗D - 垫箭头按钮:

Here is the code that you could put inside one of the branches of the if statement to spoof a d-pad arrow button:

new Thread(new Runnable() {         
    @Override
    public void run() {                 
        new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
    }   
}).start();

您可以替换 KeyEvent.KEY code_DPAD_DOWN 与您要为实例的任何其他关键事件 KeyEvent.KEY code_DPAD_UP KeyEvent.KEY code_DPAD_CENTER 的后者将作为一个选择按钮将发送一个单击事件到目前拥有的按钮关注的焦点。

you can replace the KeyEvent.KEYCODE_DPAD_DOWN with any other key event that you want for instance KeyEvent.KEYCODE_DPAD_UP or KeyEvent.KEYCODE_DPAD_CENTER the latter of which would act as a select button which will send a click event to the button that currently has focus.

这篇关于控制与蓝牙鼠标/ presenter Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆