Skip to content

thomas-brx/iphone-event-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

iphone-event-simulator

Map apple keyboard events to events on the iPhone simulator

About:

There are 2 components, one python-script (requires pygame on your system), and sourcecode to link in your app. The python-script polls the keyboard for key-down and key-up events and sends broadcasts (UDP) those on the local network. The Objective-C part will poll for events and trigger event-handlers accordingly.

Usage:

In your app, add the files iPhoneEventSimulator.h and iPhoneEventSimulator.mm.

To register events:

// first get a copy of the iPhoneEventSimulator singleton:
// The port 10552 is hardcoded in the python program.
iPhoneEventSimulator *sim = [iPhoneEventSimulator sharedSimulatorWithPort:10552];

// Then register events for different key-codes:
[sim addHandlersForKey:K_LEFT
	   keyDown:^() {
	       [hero moveLeft];
	   }
	     keyUp:^() {
	       [hero stopMoving];
	   }
];
[sim addHandlersForKey:K_ESCAPE
	   keyDown:^() {
	       exit(1);
	   }
	     keyUp:nil
];


// To unregister events:

[sim resetHandlers];

Compile and run the app in the simulator. When it is runnning, start the python program from the terminal:

$ ./bin/iPhoneEventSimulator.py

Make sure the spawned Python-app has focus. Now all key-presses are broadcasted and will trigger the corresponding event-handlers in the iPhone simulator.

Notes:

  • The key-codes are defined in the header-file.
  • This code should only be used on the simulator, so protect it by:
#if TARGET_IPHONE_SIMULATOR
#endif

About

Map apple keyboard event to events on the iPhone simulator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published