用java中的操纵杆控制PC光标

时间:2016-05-19 02:02:41

标签: java xbox360

我有一个程序可以允许我的计算机使用xbox 360遥控器。操纵杆的方向是度,直接向上是0度,右边是90度,向下是180度,左边是270度。当然,这些价值观之间也存在着一切。我对如何将这些角度测量值转换为鼠标的可用x和y坐标的数学有点困惑。我已经知道如何使用操纵杆幅度计算鼠标速度,操纵杆幅度是0到1的双倍值。

我的问题是如何使用操纵杆的度数值来移动光标?

public void main()
    {
        //Wait for a controller to connect before program continues
        xc = new XboxController();
        while (!xc.isConnected())
        {
            System.out.println("Waiting for controller...");
            xc = new XboxController();
        }
        System.out.println("Connected!");

        try
        {
            //This robot will be used to change the mouse coordinates and perform clicks
            robot = new Robot();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        //Get the screen dimensions
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        screenWidth = (int)screenSize.getWidth();
        screenHeight = (int)screenSize.getHeight();

        xc.addXboxControllerListener(new XboxControllerAdapter()
        {
            //Is called every time the leftThumbStick's direction is changed
            //The direction value is in degrees
            public void leftThumbDirection(double direction)
            {
                System.out.println("Left degree direction: "+(int)direction);
                //Need to calculate the new coordinates of the mouse based on the joystick
            }
        });
    }

1 个答案:

答案 0 :(得分:0)

您可以使用robot.mouseMove()