Skip to content

Commit 541fc47

Browse files
Caldisclaude
andcommitted
fix: prevent duplicate modifier display when recording single modifier key
When pressing Shift alone, flags contains .maskShift AND keyCode maps to "⇧", causing displayComponents to show ["⇧", "⇧"]. Now excludes the modifier flag that corresponds to the key being pressed itself using KeyCode.getKeyMask(code) to identify self-referencing flags. Only affects display - matching logic (matchesMosInput) unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 18a3fda commit 541fc47

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Mos/InputEvent/MosInputEvent.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ struct MosInputEvent {
144144
/// 构造展示用名称组件
145145
var displayComponents: [String] {
146146
var components: [String] = []
147-
// 修饰键
148-
if modifiers.rawValue & CGEventFlags.maskShift.rawValue != 0 { components.append("") }
149-
if modifiers.rawValue & CGEventFlags.maskControl.rawValue != 0 { components.append("") }
150-
if modifiers.rawValue & CGEventFlags.maskAlternate.rawValue != 0 { components.append("") }
151-
if modifiers.rawValue & CGEventFlags.maskCommand.rawValue != 0 { components.append("") }
147+
// 修饰键 (排除自身: 按下 Shift 时 flags 含 .maskShift, 但 keyCode 也是 Shift, 避免重复)
148+
let selfMask = KeyCode.getKeyMask(code).rawValue
149+
if modifiers.rawValue & CGEventFlags.maskShift.rawValue != 0 && CGEventFlags.maskShift.rawValue & selfMask == 0 { components.append("") }
150+
if modifiers.rawValue & CGEventFlags.maskControl.rawValue != 0 && CGEventFlags.maskControl.rawValue & selfMask == 0 { components.append("") }
151+
if modifiers.rawValue & CGEventFlags.maskAlternate.rawValue != 0 && CGEventFlags.maskAlternate.rawValue & selfMask == 0 { components.append("") }
152+
if modifiers.rawValue & CGEventFlags.maskCommand.rawValue != 0 && CGEventFlags.maskCommand.rawValue & selfMask == 0 { components.append("") }
152153
// 按键名称
153154
switch type {
154155
case .keyboard:

0 commit comments

Comments
 (0)