Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created February 15, 2013 03:27
Show Gist options
  • Select an option

  • Save jcromartie/4958364 to your computer and use it in GitHub Desktop.

Select an option

Save jcromartie/4958364 to your computer and use it in GitHub Desktop.
import Leap, sys
class SampleListener(Leap.Listener):
def on_init(self, controller):
print "Initialized"
def on_connect(self, controller):
self.last_fingers = 0
print "Connected"
def on_disconnect(self, controller):
print "Disconnected"
def on_exit(self, controller):
print "Exited"
def on_frame(self, controller):
# Get the most recent frame and report some basic information
frame = controller.frame()
if not frame.fingers.empty:
new_fingers = len(frame.fingers)
if new_fingers != self.last_fingers:
print "fingers: %d" % new_fingers
self.last_fingers = new_fingers
def main():
# Create a sample listener and controller
listener = SampleListener()
controller = Leap.Controller()
# Have the sample listener receive events from the controller
controller.add_listener(listener)
# Keep this process running until Enter is pressed
print "Press Enter to quit..."
sys.stdin.readline()
# Remove the sample listener when done
controller.remove_listener(listener)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment