Skip to content

Instantly share code, notes, and snippets.

@garretraziel
Created December 25, 2013 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garretraziel/8127761 to your computer and use it in GitHub Desktop.
Save garretraziel/8127761 to your computer and use it in GitHub Desktop.
Simple program for mouse control using Leap Motion controller
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