Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使跳跃运动鼠标在后台运行(Java)_Java_Eclipse_Background_Mouse_Leap Motion - Fatal编程技术网

使跳跃运动鼠标在后台运行(Java)

使跳跃运动鼠标在后台运行(Java),java,eclipse,background,mouse,leap-motion,Java,Eclipse,Background,Mouse,Leap Motion,我为支持跳跃运动的鼠标编写了一个代码。这个程序也在按我想要的方式运行,但是,一旦eclipse不在我的桌面上(比如如果我最小化窗口或打开google chrome或类似的东西),我就不能再使用leap motion作为mosue了。当eclipse最小化时,程序仍在运行,当我单击eclipse并使其成为主窗口时,leapmotion鼠标又开始工作了。所以我的问题是,在最小化eclipse的情况下,如何将我的leap motion作为鼠标与我的leap motion鼠标java程序一起使用 这是代

我为支持跳跃运动的鼠标编写了一个代码。这个程序也在按我想要的方式运行,但是,一旦eclipse不在我的桌面上(比如如果我最小化窗口或打开google chrome或类似的东西),我就不能再使用leap motion作为mosue了。当eclipse最小化时,程序仍在运行,当我单击eclipse并使其成为主窗口时,leapmotion鼠标又开始工作了。所以我的问题是,在最小化eclipse的情况下,如何将我的leap motion作为鼠标与我的leap motion鼠标java程序一起使用

这是代码。同样,它运行和工作完美(抱歉,有点凌乱)

导入com.leapmotion.leap.*;
导入com.leapmotion.leap.signature.State;
导入com.leapmotion.leap.signature.Type;
导入java.awt.Dimension;
导入java.awt.Robot;
导入java.awt.event.InputEvent;
导入java.awt.event.KeyEvent;
类CustomListener扩展了Listener{
公共机器人;
公共连接无效(控制器c)
{
c、 启用手势(手势.类型.类型\圆圈);
c、 启用手势(手势.类型.类型\屏幕\点击);
c、 启用手势(手势.类型.类型\u滑动);
c、 启用手势(手势.类型.类型\按键\轻触);
}
公共框架(控制器c)
{
尝试{robot=newrobot();}catch(异常e){}
框架=c.框架();
InteractionBox=frame.InteractionBox();
对于(Finger f:frame.fingers())
{
对于(Finger t:frame.fingers())
{
对于(Finger p:frame.fingers())
{
对于(Finger m:frame.fingers())
{
对于(Finger r:frame.fingers())
{
if(f.type()==Finger.type.type\u索引)
{
if(t.type()==Finger.type.type\u THUMB)
{
if(p.type()==Finger.type.type\u PINKY)
{
if(m.type()==Finger.type.type\u MIDDLE)
{
if(r.type()==Finger.type.type\u环)
{
向量indexPos=f.稳定的位置();
向量thumbPos=t.稳定的位置();
向量middlePos=p.稳定的位置();
向量notTouching1=新向量(20,20,20);
向量notTouching2=新向量(-20,-20,-20);
float leftClickX=indexPos.get(0)-thumbPos.get(0);
float leftClickY=indexPos.get(1)-thumbPos.get(1);
float leftClickZ=indexPos.get(2)-thumbPos.get(2);
float rightClickX=中间位置获取(0)-拇指位置获取(0);
float rightClickY=middlePos.get(1)-thumbPos.get(1);
float rightClickZ=middlePos.get(2)-thumbPos.get(2);
向量leftClick=新向量(leftClickX、leftClickY、leftClickZ);
向量rightClick=新向量(rightClickX、rightClickY、rightClickZ);
/**
如果((leftClick.get(0))<(notTouching1.get(0))&&(leftClick.get(0))>(notTouching2.get(0)))
{
如果((leftClick.get(1))<(notTouching1.get(1))&&(leftClick.get(1))>(notTouching2.get(1)))
{
如果((leftClick.get(2))<(notTouching1.get(2))&&(leftClick.get(2))>(notTouching2.get(2)))
{
机器人鼠标按键(InputEvent.BUTTON1\u DOWN\u MASK);
试试{Thread.sleep(50);}catch(异常e){}
robot.mouseRelease(InputEvent.BUTTON1_掩码);
试试{Thread.sleep(50);}catch(异常e){}
}
}
}
如果((rightClick.get(0))<(notTouching1.get(0))&&(rightClick.get(0))>(notTouching2.get(0)))
{
如果((rightClick.get(1))<(notTouching1.get(1))&&(rightClick.get(1))>(notTouching2.get(1)))
{
如果((rightClick.get(2))<(notTouching1.get(2))&&(rightClick.get(2))>(notTouching2.get(2)))
{
机器人鼠标按键(InputEvent.BUTTON3\u DOWN\u MASK);
试试{Thread.sleep(50);}catch(异常e){}
robot.mouseRelease(InputEvent.BUTTON3_掩码);
试试{Thread.sleep(50);}catch(异常e){}
}
}
}
}
}
*/
如果(f.isExtended()&&m.isExtended()&&r.isExtended()&&p.isExtended())//4个手指
{
对于(手h:frame.hands())
{
向量handPos=h.手掌位置();
向量boxHandPos=box.normalizePoint(handPos);
维度screen=java.awt.Toolkit.getDefaultToolkit().getScreenSize();
robot.mouseMove((int)(screen.width*boxHandPos.getX()),(int)(screen.height-boxHandPos.getY()*screen.height));
}
}
for(手势g:frame.pirters())
{
if(g.type()==type.type\u圆)
{
圆圈=新的圆圈(g);
如果(f.isExtended()&&!m.isExtended()&&!r.isExtended()&&!p.isExtended()){
如果(circle.pointable().direction().angleTo(circle.normal())您只需要设置


正是我想要的。谢谢!
import com.leapmotion.leap.*;
import com.leapmotion.leap.Gesture.State;
import com.leapmotion.leap.Gesture.Type;

import java.awt.Dimension;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
class CustomListener extends Listener {

public Robot robot;

public void onConnect(Controller c)
{
    c.enableGesture(Gesture.Type.TYPE_CIRCLE);
    c.enableGesture(Gesture.Type.TYPE_SCREEN_TAP);
    c.enableGesture(Gesture.Type.TYPE_SWIPE);
    c.enableGesture(Gesture.Type.TYPE_KEY_TAP);
}

public void onFrame(Controller c)
{
    try {robot = new Robot();} catch(Exception e) {}
    Frame frame = c.frame();
    InteractionBox box = frame.interactionBox();

        for (Finger f : frame.fingers())
        {
        for (Finger t: frame.fingers())
            {
        for (Finger p: frame.fingers())
        {
        for (Finger m: frame.fingers())
        {
        for (Finger r: frame.fingers())
        {
        if (f.type() == Finger.Type.TYPE_INDEX)
            {

            if (t.type() == Finger.Type.TYPE_THUMB)
                {
                if (p.type() == Finger.Type.TYPE_PINKY)
                {
                    if (m.type() == Finger.Type.TYPE_MIDDLE)
                    {
                        if (r.type() == Finger.Type.TYPE_RING)
                        {


            Vector indexPos = f.stabilizedTipPosition();
            Vector thumbPos = t.stabilizedTipPosition();
            Vector middlePos = p.stabilizedTipPosition();

            Vector notTouching1 = new Vector(20, 20, 20);
            Vector notTouching2 = new Vector(-20, -20, -20);

            float leftClickX = indexPos.get(0) - thumbPos.get(0);
            float leftClickY = indexPos.get(1) - thumbPos.get(1);
            float leftClickZ = indexPos.get(2) - thumbPos.get(2);


            float rightClickX = middlePos.get(0) - thumbPos.get(0); 
            float rightClickY = middlePos.get(1) - thumbPos.get(1);  
            float rightClickZ = middlePos.get(2) - thumbPos.get(2); 

            Vector leftClick = new Vector(leftClickX, leftClickY, leftClickZ);
            Vector rightClick = new Vector(rightClickX, rightClickY, rightClickZ);


            /**
            if((leftClick.get(0)) < (notTouching1.get(0)) && (leftClick.get(0)) > (notTouching2.get(0)))
            {
                if ((leftClick.get(1)) < (notTouching1.get(1)) && (leftClick.get(1)) > (notTouching2.get(1)))
                {
                    if ((leftClick.get(2)) < (notTouching1.get(2)) && (leftClick.get(2)) > (notTouching2.get(2)))
                    {
                        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
                            try{Thread.sleep(50);} catch(Exception e){}
                        robot.mouseRelease(InputEvent.BUTTON1_MASK);
                            try{Thread.sleep(50);} catch(Exception e){}
                    }

                }

            }





                if((rightClick.get(0)) < (notTouching1.get(0)) && (rightClick.get(0)) > (notTouching2.get(0)))
                {
                    if ((rightClick.get(1)) < (notTouching1.get(1)) && (rightClick.get(1)) > (notTouching2.get(1)))
                    {
                        if ((rightClick.get(2)) < (notTouching1.get(2)) && (rightClick.get(2)) > (notTouching2.get(2)))
                        {
                            robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
                            try{Thread.sleep(50);} catch(Exception e) {}
                            robot.mouseRelease(InputEvent.BUTTON3_MASK);
                            try{Thread.sleep(50);} catch(Exception e){}


                        }

                    }

                }

                }
                }
                */
            if (f.isExtended() && m.isExtended() && r.isExtended() && p.isExtended()) // 4 fingers
            {
            for (Hand h : frame.hands())
            {
                Vector handPos = h.palmPosition();
                Vector boxHandPos = box.normalizePoint(handPos);
                Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
                robot.mouseMove((int)(screen.width * boxHandPos.getX()), (int)(screen.height - boxHandPos.getY() * screen.height));
            }
            }

    for (Gesture g : frame.gestures())
    {
        if (g.type() == Type.TYPE_CIRCLE)
        {
            CircleGesture circle = new CircleGesture(g);
            if (f.isExtended() && !m.isExtended() && !r.isExtended() && !p.isExtended()){
            if (circle.pointable().direction().angleTo(circle.normal()) <= Math.PI/4)
            {
                robot.mouseWheel(1);
                try{Thread.sleep(50);} catch(Exception e){}
            }
            else
            {
                robot.mouseWheel(-1);
                try{Thread.sleep(50);} catch(Exception e) {}
            }
            }
        }
        if (g.type() == Type.TYPE_KEY_TAP)
        {
            if (f.isExtended() && !m.isExtended()){ // 
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            try{Thread.sleep(50);} catch(Exception e) {}
            robot.mouseRelease(InputEvent.BUTTON1_MASK);

        }
            if (f.isExtended() && m.isExtended()){ // first two fingers
                robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
                try{Thread.sleep(50);} catch(Exception e) {}
                robot.mouseRelease(InputEvent.BUTTON3_MASK);
        }
        }
        if (g.type() == Type.TYPE_SCREEN_TAP)
        {
            if (f.isExtended() && !m.isExtended()){ // 
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            try{Thread.sleep(50);} catch(Exception e) {}
            robot.mouseRelease(InputEvent.BUTTON1_MASK);

        }
            if (f.isExtended() && m.isExtended()){ // first two fingers
                robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
                try{Thread.sleep(50);} catch(Exception e) {}
                robot.mouseRelease(InputEvent.BUTTON3_MASK);
        }
        }
        }
    }
}
}
        }

}
}
}
}
}
}
}
}
public class LeapMouse {

public static void main(String[] args) {

    CustomListener l = new CustomListener();
    Controller controller = new Controller();

    controller.addListener(l);

    try {
        System.in.read();
    }
    catch(Exception e ) {}
    controller.removeListener(l);
    }
}
controller.setPolicy(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES);