How to tap/hook keyboard events in OSX and record which keyboard fires each event

前端 未结 2 1014
轻奢々
轻奢々 2021-01-18 09:13

I\'ve now discovered how to hook/tap keyboard events on OS X at a low level: How to tap (hook) F7 through F12 and Power/Eject on a MacBook keyboard

Printing out the

2条回答
  •  借酒劲吻你
    2021-01-18 09:31

    If you register the callback on each device of interest individually with IOHIDDeviceRegisterInputValueCallback then the sender argument will be a IOHIDDeviceRef indicating the device. (instead of using IOHIDManagerRegisterInputValueCallback where the sender will be the HID manager reference)

    The only downside for this is that you'll need to register for and handle notification of hotplugging events for matching devices. (register whenever a new device appears, and deregister when a device disappears)

    You can get HID device references using IOHIDDeviceCreate() - this takes an io_service_t as an argument. This in turn means you need to use the standard IOKit IOService matching functions to obtain and watch your list of devices, but you do indeed get an explicit list of individual devices, which you can query for names to show to the user, etc. The key function for this is IOServiceAddMatchingNotification.

提交回复
热议问题