KeyHandler(Input) // Use KeyCode to handle symbol menu.

- CharCode is not reliable at all. KeyCode is the most accurate. KeyCode doesn't give a phuque about the character sent through macOS keyboard layouts but only focuses on which physical key is pressed.
This commit is contained in:
ShikiSuen 2022-03-06 10:10:47 +08:00
parent e05278c53e
commit 634cf3b9d9
2 changed files with 9 additions and 6 deletions

View File

@ -532,7 +532,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
} }
// MARK: Punctuation list // MARK: Punctuation list
if ([input isSymbolMenuKey]) { if ([input isSymbolMenuPhysicalKey] && ![input isShiftHold]) {
// 得在這裡先 commit buffer不然會導致「在摁 ESC 離開符號選單時會重複輸入上一次的組字區的內容」的不當行為。 // 得在這裡先 commit buffer不然會導致「在摁 ESC 離開符號選單時會重複輸入上一次的組字區的內容」的不當行為。
// 於是這裡用「模擬一次 Enter 鍵的操作」使其代為執行這個 commit buffer 的動作。 // 於是這裡用「模擬一次 Enter 鍵的操作」使其代為執行這個 commit buffer 的動作。

View File

@ -41,11 +41,13 @@ import Cocoa
case leftShift = 56 case leftShift = 56
case rightShift = 60 case rightShift = 60
case capsLock = 57 case capsLock = 57
case symbolMenuPhysicalKey = 50
} }
// CharCodes: https://theasciicode.com.ar/ascii-control-characters/horizontal-tab-ascii-code-9.html // CharCodes: https://theasciicode.com.ar/ascii-control-characters/horizontal-tab-ascii-code-9.html
enum CharCode: UInt16 { enum CharCode: UInt/*16*/ {
case symbolMenuKey_ABC = 96 case yajuusenpai = 1145141919810893
// - CharCode is not reliable at all. KeyCode is the most accurate. KeyCode doesn't give a phuque about the character sent through macOS keyboard layouts but only focuses on which physical key is pressed.
} }
class KeyHandlerInput: NSObject { class KeyHandlerInput: NSObject {
@ -231,9 +233,10 @@ class KeyHandlerInput: NSObject {
KeyCode(rawValue: keyCode) == verticalModeOnlyChooseCandidateKey KeyCode(rawValue: keyCode) == verticalModeOnlyChooseCandidateKey
} }
@objc var isSymbolMenuKey: Bool { @objc var isSymbolMenuPhysicalKey: Bool {
// CharCode // KeyCode macOS Apple
CharCode(rawValue: charCode) == CharCode.symbolMenuKey_ABC // ![input isShift] 使 Shift
KeyCode(rawValue: keyCode) == KeyCode.symbolMenuPhysicalKey
} }
} }