Snarfing Keyboard Events

  • Howdy,

    In my application I need to be able to intercept keyboard events from
    the entire system. The Carbon path using GetEventMonitorTarget()
    sorta works except that it fails to intercept events for hot keys
    setup with RegisterEventHotKey, nor does it catch certain system-
    handled keyboard shortcuts like Cmd-Shift-3. Another issue is that I
    also (at times) need to be the sole listener of a particular event.
    Hot keys work great except that it can have multiple listeners (for
    example, installing a hot key for Cmd-Shift-3 still allows the system
    to use it to take a screenshot). So the only option I know to deal
    with all of these problems is using an event tap.

    Creating an event tap is easy and you can filter out events, so it
    works perfectly for me, though the biggest issue with using it is
    that either your app has to be running with root access, or "Enable
    access for assistive devices" must be turned on in Universal Access.
    I can accept that if it's the law, though I have a feeling it isn't
    the law because of Snapz.

    Snapz certainly doesn't run as root, nor does it spawn a dedicated
    root-run process, but even with "Enable access for assistive devices"
    turned off, Snapz can happily capture Cmd-Shift-3 and block the
    system and other applications from responding to it. Is there any
    known way to do this? If I Shark Snapz I see it's responding to some
    CGS method, so I'm reasonably confident it's using entirely private
    methods, but I'm still curious.

    Anyone have any info?

    --
    Seth Willits
  • On 2007/10/08, at 7:17, Seth Willits wrote:
    > Snapz certainly doesn't run as root, nor does it spawn a dedicated
    > root-run process, but even with "Enable access for assistive
    > devices" turned off, Snapz can happily capture Cmd-Shift-3 and
    > block the system and other applications from responding to it. Is
    > there any known way to do this? If I Shark Snapz I see it's
    > responding to some CGS method, so I'm reasonably confident it's
    > using entirely private methods, but I'm still curious.

    The function you are asking may be the global hot key.

    http://developer.apple.com/documentation/Carbon/Reference/
    Carbon_Event_Manager_Ref/Reference/reference.html

    RegisterEventHotKey
    Registers a global hot key.

    OSStatus RegisterEventHotKey (
        UInt32 inHotKeyCode,
        UInt32 inHotKeyModifiers,
        EventHotKeyID inHotKeyID,
        EventTargetRef inTarget,
        OptionBits inOptions,
        EventHotKeyRef * outRef
    );

    Satoshi
    -----------------------------------------------------
    Satoshi Matsumoto <satoshi...>
    816-5 Odake, Odawara, Kanagawa, Japan 256-0802
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today