【问题标题】:Detecting the layout of an internal Apple hardware keyboard检测内部 Apple 硬件键盘的布局
【发布时间】:2021-12-31 02:16:41
【问题描述】:

是否有 API 或方法可以检测 Mac 笔记本使用的三种主要键盘布局(ANSIISOJapanese)中的哪一种?

经过相当广泛的研究,我找不到任何有关此的信息。

【问题讨论】:

    标签: swift macos keyboard hardware macos-carbon


    【解决方案1】:

    经过无数小时的搜索和翻阅满是灰尘的手册,我终于找到了一种方法来确定 Mac 上的物理键盘布局类型。

    通过使用古老的Carbon API,您可以结合LMGetKbdType 调用KBGetLayoutType 以返回所需的常量。这在 macOS Monterey 中仍然有效。

    对于任何在未来寻找解决方案的人,这里使用的是 Swift 5.5:

    import Carbon
    
    // Determine the physical keyboard layout type.
    // macOS recognizes three keyboard types: ANSI, JIS (Japan), and ISO (Europe).
    
    let physicalKeyboardLayoutType = KBGetLayoutType(Int16(LMGetKbdType()))
    switch physicalKeyboardLayoutType {
    case _ where physicalKeyboardLayoutType == kKeyboardJIS:
        print("JIS")
    case _ where physicalKeyboardLayoutType == kKeyboardISO:
        print("ISO")
    default:
        print("ANSI")
    }
    

    【讨论】:

      猜你喜欢
      • 2011-02-28
      • 2012-10-27
      • 2017-12-04
      • 1970-01-01
      • 2023-03-06
      • 2011-04-17
      • 2020-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多