从外部蓝牙扫描仪的iOS键code捕获 [英] iOS key code capture from external bluetooth scanner

查看:366
本文介绍了从外部蓝牙扫描仪的iOS键code捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图扫描的iOS二维条形码code包含非打印字符。我有多个扫描器,我想支持。当使用SDK通过串行端口配置文件(SPP)连接我可以读取所有这些数据就好了。一个我想支持的设备只有人机接口设备(HID)支持(外接键盘)。

当我使用HID模式扫描仪来填充的UITextField的不可打印的字符被剥离出来。我已连接的设备到我的笔记本电脑和使用的密钥code拍摄设备以查看该数据实际上被发送。

有没有一种方法来填充非打印字符的UITextField是来自连为HID蓝牙设备?


解决方案

我发现了如何在HID模式连接到iOS蓝牙设备接收非打印键codeS。

作为参考,二维条码code具有一般格式为:

<$p$p><$c$c>[)><RS>'01'<GS>'9612345'<GS>'111'<GS>'000'<GS>'012345678901234'<GS>'FDEB'<GS><GS><GS><GS><GS>'25'<GS>'Y'<GS>'123第一大道'&LT; GS&GT;'西雅图'&LT; GS&GT;'WA'&LT; RS和GT;&LT;&EOT GT;

其中,&lt; RS和GT;为char(30)或序列CTRL- ^&LT; GS&GT;为char(29)或序列CTRL-],和&lt;&EOT GT;为char(4)或Ctrl-D,这是 ASCII控制codeS

在的iOS 7及以上的,您可以捕捉使用UIKeyCommand一个HID蓝牙设备按键事件。 UIKeyCommand旨在用于从蓝牙键盘捕获之类的命令A,但它也可以被用于映射的ASCII序列。关键是要映射的关键code序列相对于ASCII code。例如,在您的视图控制器,您可以:

   - (NSArray的*)keyCommands {
    //&LT; RS和GT; - CHAR(30):CTRL移6(或CTRL- ^)
    UIKeyCommand * rsCommand = [UIKeyCommand keyCommandWithInput:@6modifierFlags:UIKeyModifierShift | UIKeyModifierControl行动:@选择(rsKey :)]。
    //&LT; GS&GT; - CHAR(29):CTRL-]
    UIKeyCommand * gsCommand = [UIKeyCommand keyCommandWithInput:@]modifierFlags:UIKeyModifierControl行动:@选择(gsKey :)]。
    //&LT;&EOT GT; - CHAR(4):CTRL-D
    UIKeyCommand * eotCommand = [UIKeyCommand keyCommandWithInput:@DmodifierFlags:UIKeyModifierControl行动:@选择(eotKey :)]。
    返回[[NSArray的页头] initWithObjects:rsCommand,gsCommand,eotCommand,零]
} - (无效)rsKey:(UIKeyCommand *)keyCommand {
    的NSLog(@&LT; RS和GT;字符接收);
} - (无效)gsKey:(UIKeyCommand *)keyCommand {
    的NSLog(@&LT; GS&GT;字符接收);
} - (无效)eotKey:(UIKeyCommand *)keyCommand {
    的NSLog(@&LT;&EOT GT;字符接收);
}

我希望这有助于。

I'm trying to scan a 2D barcode in iOS that contains non-printable characters. I have a multiple scanners that I would like to support. When connected via Serial Port Profile (SPP) using an SDK I can read all of that data just fine. One of the devices I would like to support only has Human Interface Device (HID) support (external keyboard).

When I use the scanner in HID mode to populate a UITextField the unprintable characters are stripped out. I've connected the device to my laptop and used a key code capturing device to see that the data is actually being sent.

Is there a way to populate a UITextField with non-printable characters that come from a bluetooth device connected as a HID?

解决方案

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.

这篇关于从外部蓝牙扫描仪的iOS键code捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆