繁体   English   中英

使用加速度计和陀螺仪移动鼠标光标

[英]Move mouse cursor with accelerometer and gyroscope

希望你能帮我!

我想用陀螺仪和加速度计的值来控制我的电脑光标。 所以基本上当我移动传感器时,光标应该被移动。 我使用了 MPU-6050 芯片和 ESP32。

我如何获得光标的位置:

public static void main (String[] args){

        for(int i = 0; i<= 1000000; i++) {

        PointerInfo info = MouseInfo.getPointerInfo();

        Point location = info.getLocation();

        System.out.println("x="+ location.x + " y=" + location.y);

}

我将如何从传感器获取值:

 public SensorData(JsonObject data) {
    //accerlation accelerometer
    ax = data.get("ax").asDouble()/ASENSETIFITY;
    ay = data.get("ay").asDouble()/ASENSETIFITY;
    az = data.get("az").asDouble()/ASENSETIFITY;

    //temperature 
    temp = data.get("t").asDouble()/340.00+36.53;

    //gyroscope
    gx = data.get("gx").asDouble()/GSENSETIFITY;
    gy = data.get("gy").asDouble()/GSENSETIFITY;
    gz = data.get("gz").asDouble()/GSENSETIFITY;

}

public String toString() {
    return "ax: " + Double.toString(ax) +", ay: " + Double.toString(ay)
        +", az: " + Double.toString(az) +", temp: " + Double.toString(temp)
        +", gx: " + Double.toString(gx) +", gy: " + Double.toString(gy)
        +", gz: " + Double.toString(gz);

}

到目前为止我得到了什么:

package mouse;

import java.awt.AWTException;

import java.awt.Robot;
import Connection.SensorData;

public class MouseMoving {
Robot robot;

public MouseMoving(){
    try {
        robot = new Robot();
    } catch (AWTException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


    public static void verarbeite(SensorData data){

    System.out.print("Deine Maus befindet sich da:");
    System.out.println(data);

    //robot.mouseMove(1,1);
}


}   

我的问题:

我现在如何控制光标? 你有想法吗?

我想,您需要鼠标光标的最后一个位置,然后获取传感器的当前位置并更改鼠标位置。 但是我怎么能用我的价值观写这个呢?

我找到了这个网站,当传感器移动时,有 3 个物体在 PC 上旋转。 但这不是用 Java 编写的,我不明白他的解决方案。

我也发现了这个这个问题。 也许它会像那样工作。 但是我编程时间不长,不明白。

如果我很好地理解了您的问题,那么您正在尝试使用 Java 移动鼠标光标。 为此,您可以使用Robot类,该类具有MouseMove(int x, int y)方法。

默认情况下,它将光标定位在主屏幕上。 如果您有多个屏幕设置,则必须传递一个GraphicsDevice对象来指示应使用哪个屏幕。

例如,将光标向右移动 10 个像素

PointerInfo pointerInfo = MouseInfo.getPointerInfo();
Point mouseLocation = pointerInfo.getLocation();
GraphicsDevice graphicsDevice = pointerInfo.getDevice();
new Robot(graphicsDevice).MouseMove(mouseLocation.getX()+10, mouseLocation.getY());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM