How to create your own modifier key using HID on OSX Sierra

Karabiner (a great OSX override tool) recently stopped working on Sierra.

I was just reading that it is possible to remap keys using HID and I tried the example code below that remaps a

and b

. However, it is not clear how to create your own modifier key (say modifier-X) like TAB in Modifier-X.

Then create mappings like TAB + X -> X Launcher, etc.

The Carabinieri supported this, now the Carabinieri doesn't work, so I'm trying to find another way to do it.

Any suggestions how this can be implemented using HID?

#import <Foundation/Foundation.h>

#import <IOKit/hidsystem/IOHIDEventSystemClient.h>

#import <IOKit/hidsystem/IOHIDServiceClient.h>

#import <IOKit/hid/IOHIDUsageTables.h>

int main(int argc, char *argv[])
{
    IOHIDEventSystemClientRef system;
    CFArrayRef services;

    uint64_t aKey = 0x700000004;
    uint64_t bKey = 0x700000005;

    NSArray *map = @[
                     @{@kIOHIDKeyboardModifierMappingSrcKey:@(aKey),
                        @kIOHIDKeyboardModifierMappingDstKey:@(aKey)},
                     @{@kIOHIDKeyboardModifierMappingSrcKey:@(bKey),
                        @kIOHIDKeyboardModifierMappingDstKey:@(bKey)},
                     ];

    system = IOHIDEventSystemClientCreateSimpleClient(kCFAllocatorDefault);
    services = IOHIDEventSystemClientCopyServices(system);
    for(CFIndex i = 0; i < CFArrayGetCount(services); i++) {
        IOHIDServiceClientRef service = (IOHIDServiceClientRef)CFArrayGetValueAtIndex(services, i);
        if(IOHIDServiceClientConformsTo(service, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)) {
            IOHIDServiceClientSetProperty(service, CFSTR(kIOHIDUserKeyUsageMapKey), (CFArrayRef)map);
        }
    }

    CFRelease(services);
    CFRelease(system);

    return 0;
}

      

+3
objective-c macos-sierra hid macos karabiner


source to share


No one has answered this question yet

Check out similar questions:

661
How do I create delegates in Objective-C?
536
How can I create a basic UIButton programmatically?
421
How can I check if NSDictionary or NSMutableDictionary contains a key?
7
OSX HID filter for keypad?
4
How to install osx sierra on virtualbox (on my mac)
2
Simple HID OSX Application
0
C ++ headers not found on OSX Sierra
0
OpenGL / GLUT problem on OSX Sierra
0
OSX HID touch event handling
0
How to configure KeyRepeat and RepeatDelay in OSX Sierra?



All Articles
Loading...
X
Show
Funny
Dev
Pics