Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
IOHIDFamily: Difference between revisions - iPhone Development Wiki

IOHIDFamily: Difference between revisions

From iPhone Development Wiki
("keyboard" events)
m (→‎Keyboard events: Generic ref to those usage page & usage.)
Line 50: Line 50:

== Keyboard events ==
== Keyboard events ==
The iPhoneOS button events are in fact treated as "keyboard" events. The following shows how to identify them:
The iPhoneOS button events are in fact treated as "keyboard" events. The following shows how to identify them<ref></ref>:
{| class="wikitable"
{| class="wikitable"

Revision as of 21:47, 1 January 2010

IOHIDFamily is a kernel extension that provides an abstract interface of with human interface devices (HID), e.g. the touchscreen, buttons, accelerometer, etc. In the user-land, there are 2 kinds of APIs associated to the IOHIDFamily: (1) the "public" ones, which are intended for HID driver writers; (2) the "private" ones, which are intended for event processing. This document will only outline the private APIs. References to the public one can be found in [1].

Class structure

Users of IOHID always first create an IOHIDEventSystem object that interfaces with the whole HID system. An event system consists of multiple IOHIDServices and IOHIDDisplays.

Services are various interfaces to the IOHIDLibPlugin kernel plugin (located at /System/Library/Extensions/IOHIDFamily.kext/PlugIns/IOHIDLib.plugin/IOHIDLib). They accept direct human input, and are the sources of all IOHIDEvents.

Displays are, obviously, the LCD screen. The IOHIDDisplay class can only control the brightness, not colors of individual pixels (Drawing is controlled by the VRAM). You only can control the displays indirectly by changing properties of the event system.

IOHID defines 20 types of events, of which the SpringBoard only handles 4 of them: keyboard (for buttons), digitizer (i.e. touchscreen), accelerometer and proximity events (temperature events are handled by IOKit directly). Each event may contain sub-events.


#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>

void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
  // handle the events here.
  printf("Received event of type %2d from service %p.\n", IOHIDEventGetType(event), service);

int main () {
  // Create and open an event system.
  IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
  IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);

  printf("HID Event system should now be running. Hit enter to quit any time.\n");

  IOHIDEventSystemClose(system, NULL);
  return 0;


To access the services, you have to first match them using IOHIDEventSystemCopyMatchingServices. These criteria can be obtained using ioreg -l.

Service Name match CFBundleIdentifier PrimaryUsagePage PrimaryUsage
AppleLIS302DL (Accelerometer) accelerometer,lis302dl 0xff00 3
AppleISL29003 (ALS) als,isl29003 0xff00 4
AppleM68Buttons (Buttons) buttons 11 1
AppleMultitouchZ2SPI (Touchscreen) multi-touch,z2 - -

Keyboard events

The iPhoneOS button events are in fact treated as "keyboard" events. The following shows how to identify them[1]:

Usage page Usage Button
1 0x83 Wake up (Calls -[SBUIController wakeUp:] in SpringBoard.)
11 0x21 Headset button
11 0x23 Obsolete hold
11 0x2e Ringer
12 0x30 Lock
12 0x40 Menu
12 0xe9 Volume increase
12 0xea Volume decrease
0x7ff 1 Headset availability changed