java - not able to move mouse and capture gesture using Leapmotion controller in scala -
i'm trying use leapmotion jar replicate mouse motion gesture , hand movement, i've created 2 methods
def executegesture(gesture: gesture) = { val robot = new robot(); gesture.match { case gesture.type.type_circle => { println("circle is") val circle = new circlegesture(gesture); if (circle.pointable().direction().angleto(circle.normal()) <= math.pi / 4) { // clockwise if angle less 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 moves mouse in direction of hand, when comment out executemovement, executegesture recognizes gestures, when run both these methods, not detect key_tap , screen_tap events. . , i'm not able understand reason behind it
i suspect skipping frames when run both functions. if onframe handler doesn't return enough, leap motion software skip frames until done. screen , keytap gestures appear in single frame, easy miss them if code dropping frames. way around save reference last frame code processed , pass frame.gestures(sinceframe)
function. gives gestures objects have been generated between sinceframe , current frame.
Comments
Post a Comment