我正在尝试使用 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 事件。. 而且我无法理解其背后的原因