views:

398

answers:

4

In iPhone applications you can catch touch events through the UIEvent and its associated set of UITouch instances, but this happens at Objective-C level. What I am looking for is a way to get this information at a lower level, in C code (no Objective-C involved), and in particular I'm thinking of Core Foundation data structures, similarly to the way CFStringRef (and other opaque data structures) are bridged into NSString ones.

Is there a "CFTouchRef" structure available? Does anyone know if this is possible through other functions or structures? Thanks for any hints.

A: 

I think these C-based api's are only available in the older Carbon framework for legacy mac applications. I think iPhone OS only supports Cocoa-type applications which, as you say, uses the UIKit Objective-C frameworks for touch events.

darren
That's the conclusion I got after searching for information about this. But somehow I can't help wondering where the Objective-C runtime receives that information from, from somewhere "lower", hence my curiosity. Thanks!
Adrian Kosmaczewski
It could be the case that the API is presented in Objective-C syntax but the actual compiled library (e.g AppKit.o or whatever) was C code wrapped with Objective-C to satisfy the header.
darren
+4  A: 

Nope, you can't do that. Given that Objective-C is a superset of C, it is trivial, though, to create a simple class that implements the "catch the touches" mechanisms you need and then forwards the touches on to whatever C API you want.

That's the conclusion I got after searching for information about this. But somehow I can't help wondering where the Objective-C runtime receives that information from, from somewhere "lower", hence my curiosity. Thanks!

Yup -- the UIKit speaks to the underlying event mechanisms on the device. Since those mechanisms are not a part of the public API, they are not designed nor intended to be used by your application directly.

Use the shim class mechanism. If there is some particular reason why you have found that unworkable, post details and I'm sure someone can help.

bbum
+1  A: 

Using pure C I think you should be able to manipulate the Objective-C Runtime to do what you want:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Introduction/Introduction.html

You'd have to construct the appropriate classes/objects (such as a Window class with a sendEvent: method) using that stuff, but I'm not sure why you'd want to do all that with explicit Objective-C runtime calls when you have a compiler that will generate all of that for you.

Nimrod
+1  A: 

If you target for AppStore, there is no way you can capture events with pure C since UIKit is an Objective-C framework.


Nevertheless, there's indeed a lower level undocumented API handling events in the private framework GraphicsServices, and that's called GSEvents. From a GSEvent you can extract a struct about touches. You can search in Google for how to handle GSEvents.

There is an even lower level semi-documented API called IOHIDEvent in IOKit which is also pure C, but that's even more difficult to work with.

KennyTM
That's exactly what I was looking for. Thanks!
Adrian Kosmaczewski