MacBook Multitouch - in Python
I's gone an' outdone myself! Since the last post got so much attention, I realized more people were interested in reading the touch input than I thought.
So, I wondered how good ctypes is at using private frameworks from Apple. Turns out, pretty darn good.
This is an implementation of a simple multitouch listener which just prints the information:
@MTContactCallbackFunction def my_callback(device, data_ptr, n_fingers, timestamp, frame): print device, timestamp, frame for i in xrange(n_fingers): data = data_ptr[i] d = "x=%.2f, y=%.2f" % (data.normalized.position.x * 100, data.normalized.position.y * 100) print "%d: %s" % (i, d) return 0 devices = MultitouchSupport.MTDeviceCreateList() num_devices = CFArrayGetCount(devices) print "num_devices =", num_devices for i in xrange(num_devices): device = CFArrayGetValueAtIndex(devices, i) print "device #%d: %016x" % (i, device) MTRegisterContactFrameCallback(device, my_callback) MTDeviceStart(device, 0) # Why sleep instead of join? Ask David Beazley. while threading.active_count(): time.sleep(0.125)
See this paste for the whole body, including the ctypes definitions and mappings.
I also wondered how good pygame really is, so I decided to try it out. See this paste for the pygame-based thing. It uses only the SDL bindings, no SDL_* extras. To quit it (it's fullscreen), hold one finger still and swipe four fingers quickly downwards.

Um, ludvig, you're on reddit. How's the fanclub?
Oh, nice. It's doing alright.
The pasties does not work (for me).
Maybe you can put the project up somewhere? github for instance. People (like me) love to play with stuff like this.
