How can I access IOHIDManager using Swift? I'm wanting to use a third-party gaming mouse (which also masquerades as a keyboard).
Replies
I don't think you will be able to do it in pure Swift, because IOKit combines C w/ C++
You can get the headers/declarations into a Swift playground using
import IOKit
import IOKit.hid
But it will just result in a runtime error:
Error in auto-import: failed to get module 'hid' from AST context
I think you would need to write all of the code which interacts with IOKit as objective-C, and then have that code provide a "clean" objective-C interface that your Swift code can interact with.
Hello,
I've been using Dave Dribin's DDHidLib from Swift to access raw gamepad & keyboard events for some time now and it seems to be working perfectly for what I need.
You can get it from here: https://github.com/Daij-Djan/DDHidLib
I hope this help you as much as it did for me.
I was able to get it working in Swift 1 a little while ago; see https://gist.github.com/mprudhom/607560e767942063baaa
I haven't checked to see if it still works with Swift 2, but it might be enough to get you started.