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.