From 1dfae4e6d428bd57867684f8065f88e730d26b60 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 20 Aug 2022 13:43:13 +0800 Subject: [PATCH] IMKCandidates // +replaceNumPadKeyCodes(). --- .../CandidateUI/ctlCandidateIMK.swift | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/Modules/UIModules/CandidateUI/ctlCandidateIMK.swift b/Source/Modules/UIModules/CandidateUI/ctlCandidateIMK.swift index 03d46b92..ae9a8ef6 100644 --- a/Source/Modules/UIModules/CandidateUI/ctlCandidateIMK.swift +++ b/Source/Modules/UIModules/CandidateUI/ctlCandidateIMK.swift @@ -346,3 +346,25 @@ var currentTISInputSource: TISInputSource? { } return result } + +// MARK: - Translating NumPad KeyCodes to Default IMK Candidate Selection KeyCodes. + +extension ctlCandidateIMK { + public static func replaceNumPadKeyCodes(target event: NSEvent) -> NSEvent? { + let mapNumPadKeyCodeTranslation: [UInt16: UInt16] = [ + 83: 18, 84: 19, 85: 20, 86: 21, 87: 23, 88: 22, 89: 26, 91: 28, 92: 25, + ] + return NSEvent.keyEvent( + with: event.type, + location: event.locationInWindow, + modifierFlags: event.modifierFlags, + timestamp: event.timestamp, + windowNumber: event.windowNumber, + context: nil, + characters: event.characters ?? "", + charactersIgnoringModifiers: event.charactersIgnoringModifiers ?? event.characters ?? "", + isARepeat: event.isARepeat, + keyCode: mapNumPadKeyCodeTranslation[event.keyCode] ?? event.keyCode + ) + } +}