Hello,
As part of developing a DLP system, I need to block input devices upon detection of data leakage. Could you advise if it's possible to temporarily disable the built-in keyboard and camera?
Thank you in advance, Pavel
So, separating the two cases here:
temporarily disable the built-in keyboard
Yes, this is possible. Most straightforward approach would be to use CGEventTapCreate, which lets you hook your process into the system event delivery system. The API lets you modify or discard events, which will effectively block normal user input. Strictly speaking that could be bypassed by going directly to the HID system**, however, I wouldn't expect that to matter particularly for keyboard events*.
*The process of converting keyboards HID events into actual "keystrokes" is both remarkably complex and incredibly obscure. For example, the only public documentation I'm aware of that describes how keycodes map to basic ASCII is a chart from one of our old "Inside Macintosh" books, and that's just that start of the problem.
**Games are the only apps I'm aware of that regularly bypass the CGEvent system and that's because they can "cheat" their way around the mapping issue. They generally ship with some kind of "default" configuration that relies on a hard coded key map, then allow the user to modify that mapping by directly touching the key. That lets them just use whatever HID event that got without worrying about the actual mapping.
temporarily disable the built-in camera
This is a trickier problem. Two answers:
-
You can block the connection at the point it's opened. Starting in macOS 26, ES_EVENT_TYPE_AUTH_IOKIT_OPEN has been made significantly more useful/capable. See my forum post here for more detail. Note that while the same event exists prior to macOS 26, the lack of information about the specific object being targeted would make it very difficult to reliably target the "right" connection attempts. It could still be used to block connection attempts, but it's also very likely that you'd block the "wrong" things.
-
I can't think of any way to block the connection once it's open. Honestly, if that's a critical concern then I think the best option would be to use #1 to track "activity" (so you "know" that the camera could be open) and then terminate that process.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware