KeyHandler // Add FW numeral input support.

This commit is contained in:
ShikiSuen 2022-07-26 13:38:15 +08:00
parent 74785b0df2
commit 29dc4b0268
2 changed files with 27 additions and 0 deletions

View File

@ -115,6 +115,9 @@ enum KeyCodeBlackListed: UInt16 {
/// 95 Key Code JIS
let arrNumpadKeyCodes: [UInt16] = [65, 67, 69, 71, 75, 78, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 95]
/// KeyCode
let arrMainAreaNumKey: [UInt16] = [18, 19, 20, 21, 22, 23, 25, 26, 28, 29]
// CharCodes: https://theasciicode.com.ar/ascii-control-characters/horizontal-tab-ascii-code-9.html
enum CharCode: UInt16 {
case yajuusenpaiA = 114
@ -211,8 +214,15 @@ struct InputSignal: CustomStringConvertible {
return code.rawValue != KeyCode.kNone.rawValue
}
// Alt+Shift+ macOS
// KeyCode
let mapMainAreaNumKey: [UInt16: String] = [
18: "1", 19: "2", 20: "3", 21: "4", 23: "5", 22: "6", 26: "7", 28: "8", 25: "9", 29: "0",
]
/// flags KeyCode
var isNumericPadKey: Bool { arrNumpadKeyCodes.contains(keyCode) }
var isMainAreaNumKey: Bool { arrMainAreaNumKey.contains(keyCode) }
var isShiftHold: Bool { flags.contains([.shift]) }
var isCommandHold: Bool { flags.contains([.command]) }
var isControlHold: Bool { flags.contains([.control]) }

View File

@ -423,6 +423,23 @@ extension KeyHandler {
}
}
// MARK: / (FW / HW Arabic Numbers Input)
if state is InputState.Empty {
if input.isMainAreaNumKey, input.isShiftHold, input.isOptionHold, !input.isControlHold, !input.isCommandHold {
// NOTE: macOS 10.11 El Capitan CFStringTransform StringTransform:
// https://developer.apple.com/documentation/foundation/stringtransform
guard let stringRAW = input.mapMainAreaNumKey[input.keyCode] else { return false }
let string = NSMutableString(string: stringRAW)
CFStringTransform(string, nil, kCFStringTransformFullwidthHalfwidth, true)
stateCallback(
InputState.Committing(textToCommit: mgrPrefs.halfWidthPunctuationEnabled ? stringRAW : string as String)
)
stateCallback(InputState.Empty())
return true
}
}
// MARK: Punctuation
///