Old thread I know, but replying in case someone finds their way here. What worked for me was to put a UITextField on my screen, then when I click it, it becomes first responder and accepts keyboard input. I then hide the keyboard window and respond to changes in the text field. Gonna try and include some code...
In my case I had a UIViewController, so this went into loadView
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 380, 50, 25)];
textField.borderStyle = UITextBorderStyleBezel;
textField.backgroundColor = [UIColor whiteColor];
textField.delegate = self;
[self.view addSubview:textField];
[textField release];
Then these delegate callbacks did the trick:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
for (UIWindow *w in [[UIApplication sharedApplication] windows]) {
if (!w.keyWindow) {
w.hidden = YES;
}
}
// could set textField.hidden=YES here if you want to really clean
// up your screen, say for video capture or whatever
}
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string
{
switch ([string characterAtIndex:0]) {
case 0xF700:
// up arrow pressed...
break;
case 0xF701:
// down arrow pressed...
break;
case 0xF702:
// left arrow pressed...
break;
case 0xF703:
// right arrow pressed...
break;
}
return NO;
}
Complete hackery, no idea if/how this would work in an OpenGL game, can't detect key up events (delegate just gets called upon key down), and messes up any real future keyboard input, but just for simple simulator testing it gets the job done.
- StadiaJack