Is there a way to programmatically check if a Mac or PC keyboard is attached?
Is there a way to reliably check programmatically if the keyboard attached to a computer is a Mac keyboard with Command (⌘) and option keys, or a PC keyboard with Windows, Alt, and Menu keys? For simplicity's sake assume that there is only one keyboard attached to the computer. An operating system independent solution would b开发者_运维问答e best if there is one, but if you have to assume an OS, assume Windows 7.
Enumerate the attached USB devices and look for a keyboard. If you find one, and it's got a vendor id of 0x05AC (Apple Inc), then it's definitely an Apple keyboard. If the vendor is something else, or if you don't find any USB keyboards (e.g, the keyboard is probably hooked up via PS2), then it's probably not an Apple keyboard.
精彩评论