3

In order to block ALL keyboard access, mouse access and keyboard shortcut events in one of my projects, I:

  1. Created a full screen transparent borderless window, in front of other windows, but invisible.
  2. Handle all keyboard and mouse events with simple return; the window itself.
  3. Make the window modal [NSApp runModalForWindow:myWindow] in order to block keyboard shortcuts.
  4. Release window from touchpad's gesture events only.

But this guy made it look simple in a tiny app -MACIFIER:

How did he do it?

Julian
  • 2,814
  • 21
  • 31
Jiulong Zhao
  • 1,313
  • 1
  • 15
  • 25
  • related: http://stackoverflow.com/questions/5049217/cgeventtap-blocks-application-input – clt60 Jul 12 '12 at 22:27

2 Answers2

0

I believe you can use Quartz Event Services. In particular, have a look at CGEventTapCreate, and note the 4th parameter, which allows you to specify what kinds of events you'd like to intercept. The available kinds of events are listed in the CGEventType enum.

If you set your tap to be an active filter, returning NULL from the callback will delete the event.

user1071136
  • 15,636
  • 4
  • 42
  • 61
  • do you mean block all events except gesture? any code in detail? – Jiulong Zhao Jul 13 '12 at 20:55
  • I've edited my answer; you can intercept all key-down, key-up, mouse movements, and so on. I think gestures is a more high-level mouse event, but that's ok - if you intercept all mouse movements, you also intercept gestures. – user1071136 Jul 13 '12 at 21:00
  • Where were you lost? I believe the documentation is quite easy to follow. – user1071136 Jul 14 '12 at 12:21
  • As the documentation says, your program must either be run as root, or the access for assistive devices be enabled. There's also a method called `CGEventTapCreateForPSN` which does the same for a specific process, and does not require root privileges. – user1071136 Jul 17 '12 at 07:08
  • found sample code here, but too hard to me. http://keymagic.googlecode.com/svn-history/r117/trunk/OSX/EventHandler.m – Jiulong Zhao Jul 18 '12 at 17:31
0

not really sure if this would be usable, but you could use the program hotkeynet (generally used for gaming, but I have had success using other methods) and map every single key/mouse action to do nothing. I did something similar by blocking access to a specific program with it in about 20-30 minutes.

not sure if it will help; but it might be the solution you need?

NRGdallas
  • 395
  • 1
  • 8
  • 20