I found out how to receive non-printable key codes from a bluetooth device connected to iOS in HID mode.
For reference, a 2D barcode has the general format:
[)><RS>'01'<GS>'9612345'<GS>'111'<GS>'000'<GS>'012345678901234'<GS>'FDEB'<GS><GS><GS><GS><GS>'25'<GS>'Y'<GS>'123 1ST AVE'<GS>'SEATTLE'<GS>'WA'<RS><EOT>
Where <RS> is char(30) or sequence ctrl-^, <GS> is char(29) or sequence ctrl-], and <EOT> is char(4) or ctrl-d, which are ASCII control codes.
In iOS 7 and above you can capture Key Down events from a HID bluetooth device using UIKeyCommand. UIKeyCommand is intended for capturing things like Command-A from a bluetooth keyboard, but it can also be used to map ASCII Sequences. The trick is to map the key code sequence as opposed to the ASCII code. For example in your view controller you can:
- (NSArray *) keyCommands {
// <RS> - char(30): ctrl-shift-6 (or ctrl-^)
UIKeyCommand *rsCommand = [UIKeyCommand keyCommandWithInput:@"6" modifierFlags:UIKeyModifierShift|UIKeyModifierControl action:@selector(rsKey:)];
// <GS> - char(29): ctrl-]
UIKeyCommand *gsCommand = [UIKeyCommand keyCommandWithInput:@"]" modifierFlags:UIKeyModifierControl action:@selector(gsKey:)];
// <EOT> - char(4): ctrl-d
UIKeyCommand *eotCommand = [UIKeyCommand keyCommandWithInput:@"D" modifierFlags:UIKeyModifierControl action:@selector(eotKey:)];
return [[NSArray alloc] initWithObjects:rsCommand, gsCommand, eotCommand, nil];
}
- (void) rsKey: (UIKeyCommand *) keyCommand {
NSLog(@"<RS> character received");
}
- (void) gsKey: (UIKeyCommand *) keyCommand {
NSLog(@"<GS> character received");
}
- (void) eotKey: (UIKeyCommand *) keyCommand {
NSLog(@"<EOT> character received");
}
I hope this helps.