OSX HID辅助键盘过滤器? [英] OSX HID Filter for Secondary Keyboard?

查看:73
本文介绍了OSX HID辅助键盘过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想过滤第二个键盘上的键盘输入,并防止该第二个键盘的按键事件到达操作系统(请自己处理).该怎么办?

I would like to filter keyboard input on a second keyboard, and prevent the key events for that second keyboard from reaching the OS (handle them myself). How can this be done?

推荐答案

可以通过使用IOKit和HIDManager类来完成.

It can be done by using IOKit and the HIDManager class.

如果需要排他性地使用键盘,则可以使用kIOHIDOptionsTypeSeizeDevice选项,但是该程序必须具有root特权才能运行.

If exclusive access to the keyboard is desired, the kIOHIDOptionsTypeSeizeDevice option can be used, but the program will have to be run with root privileges.

获得此结果所需的代码存根如下所示:

A stub of the code required to obtain this result is shown below:

// Create a manager instance
IOHIDManagerRef manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDManagerOptionNone);

if (CFGetTypeID(manager) != IOHIDManagerGetTypeID()) {
    exit(1);
}

// Setup device filtering using IOHIDManagerSetDeviceMatching
//matchingdict = ...
IOHIDManagerSetDeviceMatching(manager, matchingdict);

// Setup callbacks
IOHIDManagerRegisterDeviceMatchingCallback(manager, Handle_DeviceMatchingCallback, null);
IOHIDManagerRegisterDeviceRemovalCallback(manager, Handle_RemovalCallback, null);
IOHIDManagerRegisterInputValueCallback(manager, Handle_InputCallback, null);

// Open the manager and schedule it with the run loop
IOHIDManagerOpen(manager, kIOHIDOptionsTypeSeizeDevice);
IOHIDManagerScheduleWithRunLoop(manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

// Start the run loop
//...

更详细的信息可以在下面的Apple文档中找到: http://developer.apple.com/library/mac/#documentation/DeviceDrivers/Conceptual/HID/new_api_10_5/tn2187.html

More detailed information can be found in the Apple docs over here: http://developer.apple.com/library/mac/#documentation/DeviceDrivers/Conceptual/HID/new_api_10_5/tn2187.html

我用于应用程序的完整代码可以在这里找到: https://gist.github.com/3783042

The complete code I used for my application can be found here: https://gist.github.com/3783042

这篇关于OSX HID辅助键盘过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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