0

嗨,我想从键盘(数字字母)中获取所有可用字符的列表,以便创建一个 NSArray。

TISInputSourceRef source = TISCopyCurrentKeyboardInputSource(); 
 NSLog(@"languages: %@", TISGetInputSourceProperty(source,       kTISPropertyInputSourceLanguages));
 NSLog(@"localized name: %@", TISGetInputSourceProperty(source, kTISPropertyLocalizedName));

我使用这些行,但找不到列出字符的正确函数。

我也试过这条线:

NSLog(@"List: %@", TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData));
4

2 回答 2

0
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
    CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
    const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr);

    Byte* buffer =
    (Byte*) malloc (sizeof(Byte) * CFDataGetLength(uchr));



    CFDataGetBytes(
                   uchr,
                   CFRangeMake(0,CFDataGetLength(uchr)),
                   buffer
                   );

如何读取 CFDataRef 中包含的信息?

于 2012-10-28T09:56:11.457 回答
0

你能通过调用得到它:

TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData);

这将返回键盘布局的“uchr”数据(如果存在),作为CFDataRef. 您可以在此处阅读“uchr”数据的布局。您需要从 中获取字节CFDataRef,可能通过调用类似CFDataGetBytes()or的方法CFDataGetBytePtr()

于 2012-10-27T14:43:57.497 回答