Skip to content

Instantly share code, notes, and snippets.

@cieslak
Created March 25, 2017 20:07
Show Gist options
  • Save cieslak/61ab6ee858c30c7e6cb035e6e9f680b3 to your computer and use it in GitHub Desktop.
Save cieslak/61ab6ee858c30c7e6cb035e6e9f680b3 to your computer and use it in GitHub Desktop.
// kbunfuck.m
//
// sets keyboard back to normal
#import <Foundation/Foundation.h>
#import <IOKit/hidsystem/IOHIDEventSystemClient.h>
#import <IOKit/hidsystem/IOHIDServiceClient.h>
#import <IOKit/hid/IOHIDUsageTables.h>
int main(int argc, const char * argv[]) {
IOHIDEventSystemClientRef system;
CFArrayRef services;
NSMutableArray *map = [[NSMutableArray alloc] init];
for (uint64_t i = 0x04; i < 0xf0; i++) {
uint64_t ori = i | 0x700000000;
NSDictionary *code = @{@kIOHIDKeyboardModifierMappingSrcKey:@(ori), @kIOHIDKeyboardModifierMappingDstKey:@(ori)};
[map addObject: code];
}
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment