0

我正在尝试使用 jumpmotion jar 通过手势和手部运动来复制鼠标运动,我创建了两种方法

def executeGesture(gesture: Gesture) = {

    val robot = new Robot();
    gesture.match {
    case Gesture.Type.TYPE_CIRCLE => {
        println("CIRCLE IT IS")
        val circle = new CircleGesture(gesture);

        if (circle.pointable().direction().angleTo(circle.normal()) <= Math.PI / 4) { // Clockwise if angle is less than 90 degrees
            //              robot.mousePress(InputEvent.BUTTON1_MASK)
            //              robot.mouseRelease(InputEvent.BUTTON1_MASK)
            //              robot.mousePress(InputEvent.BUTTON1_MASK)
            //              robot.mouseRelease(InputEvent.BUTTON1_MASK)

        } else {

        }
    }
    case Gesture.Type.TYPE_SWIPE => {
        val swipe = new SwipeGesture(gesture)

        if (swipe.direction().getX() > 0) {
            println("SWIPE Right")

        } else {
            println("SWIPE Left ")
            robot.keyPress(KeyEvent.VK_ALT);
            robot.keyPress(KeyEvent.VK_F4);
            robot.keyRelease(KeyEvent.VK_ALT);
            robot.keyRelease(KeyEvent.VK_F4);
        }
    }
    case Gesture.Type.TYPE_SCREEN_TAP => {
        val ScreenTap = new ScreenTapGesture(gesture)
        println("Screen Tap " + ScreenTap.id())
    }
    case Gesture.Type.TYPE_KEY_TAP => {
        val KeyTap = new KeyTapGesture(gesture)
        println("Key Tap " + KeyTap.id())
        robot.mousePress(InputEvent.BUTTON1_MASK)
        robot.mouseRelease(InputEvent.BUTTON1_MASK)
    }
    case _ => println("Something ELSE!!. .")
    }
}

def executeMovement(frame: Frame) {
    val robot = new Robot
            val finger = frame.fingers().get(0)
            val gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            val Xwidth = gd.getDisplayMode().getWidth()
            val Xheight = gd.getDisplayMode().getHeight()

            val tipVelocity = finger.tipVelocity().magnitude().toInt
            val position = finger.tipPosition()

            if (tipVelocity > 2) {
                prevPoint.x = nextPoint.x
                        prevPoint.y = nextPoint.y

                        val mouseX = (Xwidth + Math.round(position.getX() * (Xwidth / 100)))
                        val mouseY = ((Xheight - (0.0F + position.getY() * 4.0F - Xheight / 5))).toInt

                        nextPoint.x = mouseX
                        nextPoint.y = mouseY

                        val diffx = (prevPoint.x - nextPoint.x).abs
                        val diffy = (prevPoint.y - nextPoint.y).abs

                        if ((diffx > 4) & (diffy > 4)) {
                            robot.mouseMove(nextPoint.x, nextPoint.y)
                            //        moveMouse(prevPoint.x, prevPoint.y, nextPoint.x, nextPoint.y, 200, 30)
                        }
            }
}

Executemovement 将鼠标移向您手的方向,当我注释掉 executemovement 时,executeGesture 会识别所有手势,但是当我同时运行这两种方法时,它不会检测到 Key_tap 和 Screen_tap 事件。. 而且我无法理解其背后的原因

4

1 回答 1

0

我怀疑您在运行这两个功能时都在跳帧。如果你的 onFrame 处理程序没有足够快地返回,Leap Motion 软件将跳过帧直到它完成。Screen 和 KeyTap 手势仅出现在单个帧中,因此如果您的代码丢帧,很容易错过它们。解决此问题的方法是保存对代码处理的最后一帧的引用并将其传递给Frame.gestures(sinceFrame)函数。这为您提供了在 sinceFrame 和当前帧之间生成的所有手势对象。

于 2013-09-10T17:07:47.803 回答