Created
December 25, 2013 23:01
-
-
Save garretraziel/8127761 to your computer and use it in GitHub Desktop.
Simple program for mouse control using Leap Motion controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Leap | |
import pyatspi | |
debounce = False | |
WIDTH = 1366 | |
HEIGHT = 768 | |
class MouseListener(Leap.Listener): | |
def on_frame(self, controller): | |
global debounce | |
frame = controller.frame() | |
if not frame.pointables.is_empty: | |
pointable = frame.pointables.frontmost | |
stabilized = pointable.stabilized_tip_position | |
touched = pointable.touch_distance < 0 | |
interactionBox = frame.interaction_box | |
fingers_pos = interactionBox.normalize_point(stabilized) | |
pyatspi.Registry.generateMouseEvent(WIDTH*fingers_pos[0], HEIGHT-HEIGHT*fingers_pos[1], pyatspi.MOUSE_ABS) | |
if pointable.touch_distance < 0: | |
if not debounce: | |
pyatspi.Registry.generateMouseEvent(WIDTH*fingers_pos[0], HEIGHT-HEIGHT*fingers_pos[1], pyatspi.MOUSE_B1C) | |
debounce = True | |
else: | |
debounce = False | |
listener = MouseListener() | |
controller = Leap.Controller() | |
controller.add_listener(listener) | |
raw_input("press any key to quit") | |
controller.remove_listener(listener) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment