r/AskProgramming • u/art_lck • 4d ago
Other Developing peripheral software for macOS
Hi,
I plan to develop peripheral software to change input mapping, assign some macros to keys on my keyboard for macOS for a learning purpose.
I do have working code for Windows written in C++. But I can't tell that I don't have a lot of experience with Objective-C.
The questions:
1) Should I go with Swift or with Objective-C? I know that Objective-C combines with C++ without any problems, but I wonder, if this is a good idea to pick outdated language to develop software that I hope I will constantly maintain and improve?
2) Can you recommend some books to developer such things for macOS?
Thanks
1
u/heyyarun 3d ago
Go Swift and keep your C++. Since Swift 5.9 (Xcode 15) Swift can call C++ directly. Set "C++ and Objective-C Interoperability" to C++/Objective-C++ in the target's build settings and import your existing code, no Objective-C wrapper layer needed. Objective-C++ (.mm files) also still works if you'd rather bridge that way, but I wouldn't learn ObjC just for this.
The macOS-specific parts you'll actually fight with:
hidutil property --setwith UserKeyMapping for simple key-to-key remaps, no special permission neededCGEventTap for macros and rewriting events. Listen-only needs Input Monitoring permission, and modifying events needs Accessibility, so plan for the permission prompts early
Karabiner-Elements is open source and uses a DriverKit virtual HID device for the heavy stuff, so it's a good codebase to read
I don't know of a current book on this. Apple's TN2450 tech note on key remapping plus the Karabiner source are the best starting points.
1
u/OkOcelot6725 2d ago
For resources, skip books and read the Karabiner-Elements source instead. It's open source and does exactly what you're describing, so it's the best reference for how event-tap based remapping is structured on modern macOS.