获取键盘类型的macOS并检测内置的,屏幕上的或USB [英] Get keyboard type macOS and detect built-in, onscreen or USB

查看:96
本文介绍了获取键盘类型的macOS并检测内置的,屏幕上的或USB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个用于检测macOS键盘类型的应用程序.我看过阅读文档中应该返回键盘ID的几个函数.

I am developing an application to detect keyboard type for macOS. I have seen several functions which reading the documentation are supposed to return keyboard id.

但是,当我在笔记本电脑上对其进行测试时,它始终会打印59.

However when I test those on my laptop it always print 59.

有人可以告诉我这59个值是从哪里来的吗?

Can someone tell me where does this 59 value come from and its meaning ??

到目前为止,我已经尝试使用增量键盘和内置键盘.我也尝试过使用不同的布局,但是我不断得到59

So far I have tried with oncreen keyboard and built-in keyboard. I have also tried with different layouts but I keep getting that 59

这是我的代码:

- (CGEventRef)processEvent:(CGEventRef)cgEvent
{
   uint32_t kbdType = LMGetKbdType();
   NSLog(@"Testing LMGetKbdType  ----------> %d", kbdType);
   NSEvent* event = [NSEvent eventWithCGEvent:cgEvent];

   NSEventType type = [event type];
   if(type==NSKeyDown || type==NSKeyUp) {
      int64_t val = CGEventGetIntegerValueField(cgEvent, kCGKeyboardEventKeyboardType);
      NSLog(@"CGEventGetIntegerValueField: %lld",val);
      EventRef ce = (EventRef)[event eventRef];

      if(ce) {
         unsigned kbt;
         GetEventParameter(
                        ce,
                        kEventParamKeyboardType,
                        typeUInt32, NULL,
                        sizeof kbt, NULL,
                        & kbt
                        );

         NSLog(@"CARBON Keyboard type: %d",kbt);
      }

      CGEventSourceRef evSrc = CGEventCreateSourceFromEvent( cgEvent );

      if(evSrc) {
         unsigned kbt = (NSUInteger) CGEventSourceGetKeyboardType( evSrc );
         CFRelease(evSrc);
         NSLog(@"COCOA: %d",kbt);
      }
   }
}

推荐答案

我认为这些是未记录的值,没有任何外部含义.它们仅用于传回需要键盘类型的其他API(例如 UCKeyTranslate()).

I think these are undocumented values with no external meaning. They are only useful for passing back into other APIs that need a keyboard type (e.g. UCKeyTranslate()).

认为它们与以前在 gestaltKeyboardType 中的< CoreServices/CarbonCore/Gestalt.h> 中记录的类型相同.代码>.但是,该标头不再更新,并且未列出类型59.

I think that they are of the same kind that used to be documented in <CoreServices/CarbonCore/Gestalt.h>, under gestaltKeyboardType. However, that header is no longer being updated and doesn't list a type 59.

您到底想弄清楚键盘是什么?如果是常规布局,则可以使用 KBGetLayoutType()来了解它是ANSI,JIS还是ISO.您输入键盘类型,就像从 LMGetKbdType()中获得的那样.

What exactly are you trying to figure out about the keyboard? If it's general layout, you can use KBGetLayoutType() to learn if it's ANSI, JIS, or ISO. You pass in the keyboard type, like the one you're getting from LMGetKbdType().

有效的键盘布局(例如,美国vs.法国vs.Dvorak)不应影响键盘类型.键盘类型是硬件的一个方面,并且不会随着布局(将键解释为字符)的变化而改变.

The active keyboard layout (e.g. U.S. vs. French vs. Dvorak) should not affect the keyboard type. The keyboard type is an aspect of the hardware and doesn't change as the layout (the interpretation of keys into characters) changes.

这篇关于获取键盘类型的macOS并检测内置的,屏幕上的或USB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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