You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest adding a convenience function next to KeyCodeTransformer.transformValue(_:carbonModifiers:) that outputs a NSMenuItem-compatible String. Because transformValue produces a printable, upper-case letter, using this as NSMenuItem.keyEquivalent will result in always adding the ⇧ (Shift) modifier key.
The proposed KeyCodeTransformer.keyEquivalent should behave like this for example:
⌃⇧T should return "T"
⌥T should return "t"
⌘⌥⇧⌃1 should return "1"
What do you think?
It's basically a refactoring:
fileprivatefunc transformValue(_ keyCode:Int, modifiers:Int)->String{returnkeyEquivalent(keyCode, modifiers).uppercased
}fileprivatefunc keyEquivalent(_ keyCode:Int, modifiers:Int)->String{// Return Special KeyCode
if let unmappedString =transformSpecialKeyCode(keyCode){return unmappedString
}letsource=TISCopyCurrentASCIICapableKeyboardLayoutInputSource().takeUnretainedValue()letlayoutData=TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData)letdataRef=unsafeBitCast(layoutData, to:CFData.self)letkeyLayout=unsafeBitCast(CFDataGetBytePtr(dataRef), to: UnsafePointer<CoreServices.UCKeyboardLayout>.self)letkeyTranslateOptions=OptionBits(CoreServices.kUCKeyTranslateNoDeadKeysBit)vardeadKeyState:UInt32=0letmaxChars=256varchars=[UniChar](repeating:0, count: maxChars)varlength=0leterror=CoreServices.UCKeyTranslate(keyLayout,UInt16(keyCode),UInt16(CoreServices.kUCKeyActionDisplay),UInt32(modifiers),UInt32(LMGetKbdType()),
keyTranslateOptions,&deadKeyState,
maxChars,&length,&chars)
if error != noErr {return""}returnNSString(characters:&chars, length: length)}
The text was updated successfully, but these errors were encountered:
@DivineDominionKeyCodeTransformer.transformValue(_:carbonModifiers:) could not return T with ⇧T because it had not been able to correctly consider the modifier before.
From v3.0.0, string generation has been migrated to the Sauce.framework.
This library can be used to generate the correct string with modifiers 🎉
I suggest adding a convenience function next to
KeyCodeTransformer.transformValue(_:carbonModifiers:)
that outputs aNSMenuItem
-compatible String. BecausetransformValue
produces a printable, upper-case letter, using this asNSMenuItem.keyEquivalent
will result in always adding the ⇧ (Shift) modifier key.The proposed
KeyCodeTransformer.keyEquivalent
should behave like this for example:⌃⇧T
should return"T"
⌥T
should return"t"
⌘⌥⇧⌃1
should return"1"
What do you think?
It's basically a refactoring:
The text was updated successfully, but these errors were encountered: