diff --git a/PanoPainter-OSX/main.cpp b/PanoPainter-OSX/main.cpp index 4e27c76..5c9b6ca 100644 --- a/PanoPainter-OSX/main.cpp +++ b/PanoPainter-OSX/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#import #import "objc_utils.h" #include @@ -21,6 +22,46 @@ @import AppCenterAnalytics; @import AppCenterCrashes; +NSString* keyCodeToString(NSUInteger keyCode, NSUInteger mods) +{ + TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); + CFDataRef uchr = + (CFDataRef)TISGetInputSourceProperty(currentKeyboard, + kTISPropertyUnicodeKeyLayoutData); + const UCKeyboardLayout *keyboardLayout = + (const UCKeyboardLayout*)CFDataGetBytePtr(uchr); + + if(keyboardLayout) + { + UInt32 deadKeyState = 0; + UniCharCount maxStringLength = 255; + UniCharCount actualStringLength = 0; + UniChar unicodeString[maxStringLength]; + + OSStatus status = UCKeyTranslate(keyboardLayout, + keyCode, kUCKeyActionDown, mods, + LMGetKbdType(), 0, + &deadKeyState, + maxStringLength, + &actualStringLength, unicodeString); + + if (actualStringLength == 0 && deadKeyState) + { + status = UCKeyTranslate(keyboardLayout, + kVK_Space, kUCKeyActionDown, mods, + LMGetKbdType(), 0, + &deadKeyState, + maxStringLength, + &actualStringLength, unicodeString); + } + if(actualStringLength > 0 && status == noErr) + return [[NSString stringWithCharacters:unicodeString + length:(NSUInteger)actualStringLength] lowercaseString]; + } + + return nil; +} + @implementation View { NSSharingService *airdrop_service; diff --git a/src/objc_utils.cpp b/src/objc_utils.cpp index 1196103..5fca9ee 100644 --- a/src/objc_utils.cpp +++ b/src/objc_utils.cpp @@ -6,7 +6,6 @@ #include #include #include -#import #ifdef __OBJC__ #import @@ -57,46 +56,6 @@ NSString* StringWToNSString ( const std::wstring& Str ) return pString; } -NSString* keyCodeToString(CGKeyCode keyCode, NSUInteger mods) -{ - TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); - CFDataRef uchr = - (CFDataRef)TISGetInputSourceProperty(currentKeyboard, - kTISPropertyUnicodeKeyLayoutData); - const UCKeyboardLayout *keyboardLayout = - (const UCKeyboardLayout*)CFDataGetBytePtr(uchr); - - if(keyboardLayout) - { - UInt32 deadKeyState = 0; - UniCharCount maxStringLength = 255; - UniCharCount actualStringLength = 0; - UniChar unicodeString[maxStringLength]; - - OSStatus status = UCKeyTranslate(keyboardLayout, - keyCode, kUCKeyActionDown, mods, - LMGetKbdType(), 0, - &deadKeyState, - maxStringLength, - &actualStringLength, unicodeString); - - if (actualStringLength == 0 && deadKeyState) - { - status = UCKeyTranslate(keyboardLayout, - kVK_Space, kUCKeyActionDown, mods, - LMGetKbdType(), 0, - &deadKeyState, - maxStringLength, - &actualStringLength, unicodeString); - } - if(actualStringLength > 0 && status == noErr) - return [[NSString stringWithCharacters:unicodeString - length:(NSUInteger)actualStringLength] lowercaseString]; - } - - return nil; -} - std::string base_address; std::atomic_flag handler_executed; diff --git a/src/objc_utils.h b/src/objc_utils.h index 83721c2..0a2ba27 100644 --- a/src/objc_utils.h +++ b/src/objc_utils.h @@ -16,6 +16,6 @@ void delete_all_files_in_path(const std::string& source_path); void export_mp4(const std::string& rec_path, int width, int height, int tot, void(^progress_callback)(float)); void save_image_library(const std::string& path); bool apple_create_dir(const std::string& path); -NSString* keyCodeToString(CGKeyCode keyCode, NSUInteger mods); +NSString* keyCodeToString(NSUInteger keyCode, NSUInteger mods); std::wstring NSStringToStringW(NSString* Str); NSString* StringWToNSString(const std::wstring& Str);