So I have an app that when you press the numbers on your keyboard on top, it normally types the symbols. But with the app it types the numbers.
But if I run it in xcode, everything works fine, but when i open the app outside of xcode it doesn't work.
I have the newest update of mac os x and xcode.
Video:
Can anybody help me please?
CGEventRef KeyHandler(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
UniCharCount actualStringLength;
UniCharCount maxStringLength = 1;
UniChar chars[3];
CGEventKeyboardGetUnicodeString(event, maxStringLength, &actualStringLength, chars);
NSString *rusLetters1 = @"&";
if (chars[0] == [rusLetters1 characterAtIndex:0]) {
chars[0] = '1';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters2 = @"é";
if (chars[0] == [rusLetters2 characterAtIndex:0]) {
chars[0] = '2';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters3 = @"\"";
if (chars[0] == [rusLetters3 characterAtIndex:0]) {
chars[0] = '3';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters4 = @"'";
if (chars[0] == [rusLetters4 characterAtIndex:0]) {
chars[0] = '4';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters5 = @"(";
if (chars[0] == [rusLetters5 characterAtIndex:0]) {
chars[0] = '5';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters6 = @"§";
if (chars[0] == [rusLetters6 characterAtIndex:0]) {
chars[0] = '6';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters7 = @"è";
if (chars[0] == [rusLetters7 characterAtIndex:0]) {
chars[0] = '7';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters8 = @"!";
if (chars[0] == [rusLetters8 characterAtIndex:0]) {
chars[0] = '8';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters9 = @"ç";
if (chars[0] == [rusLetters9 characterAtIndex:0]) {
chars[0] = '9';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters0 = @"à";
if (chars[0] == [rusLetters0 characterAtIndex:0]) {
chars[0] = '0';
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
//_________________________________________________________________________________________________________________
NSString *rusLetters11 = @"&";
if (chars[0] == '1') {
chars[0] = [rusLetters11 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters12 = @"é";
if (chars[0] == '2') {
chars[0] = [rusLetters12 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters13 = @"\"";
if (chars[0] == '3') {
chars[0] = [rusLetters13 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters14 = @"'";
if (chars[0] == '4') {
chars[0] = [rusLetters14 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters15 = @"(";
if (chars[0] == '5') {
chars[0] = [rusLetters15 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters16 = @"§";
if (chars[0] == '6') {
chars[0] = [rusLetters16 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters17 = @"è";
if (chars[0] == '7') {
chars[0] = [rusLetters17 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters18 = @"!";
if (chars[0] == '8') {
chars[0] = [rusLetters18 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters19 = @"ç";
if (chars[0] == '9') {
chars[0] = [rusLetters19 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
NSString *rusLetters10 = @"à";
if (chars[0] == '0') {
chars[0] = [rusLetters10 characterAtIndex:0];
CGEventKeyboardSetUnicodeString(event, 1, chars);
return event;
}
return event;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
CFMachPortRef eventTap;
CGEventMask eventMask;
CFRunLoopSourceRef runLoopSource;
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, eventMask, KeyHandler, NULL);
if (!eventTap) {
exit(1);
}
runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(eventTap, true);
CFRunLoopRun();
}
Here's what I would do. There are many ways to calculate the modified character, this is one of them.