diff --git a/sources/MacOSKeyCodes.swift b/sources/MacOSKeyCodes.swift index f4316e35b..0613fc648 100644 --- a/sources/MacOSKeyCodes.swift +++ b/sources/MacOSKeyCodes.swift @@ -10,21 +10,21 @@ import AppKit struct SquirrelKeycode { - static func osxModifiersToRime(modifiers: UInt) -> UInt32 { + static func osxModifiersToRime(modifiers: NSEvent.ModifierFlags) -> UInt32 { var ret: UInt32 = 0 - if modifiers & NSEvent.ModifierFlags.capsLock.rawValue != 0 { + if modifiers.contains(.capsLock) { ret |= kLockMask.rawValue } - if modifiers & NSEvent.ModifierFlags.shift.rawValue != 0 { + if modifiers.contains(.shift) { ret |= kShiftMask.rawValue } - if modifiers & NSEvent.ModifierFlags.control.rawValue != 0 { + if modifiers.contains(.control) { ret |= kControlMask.rawValue } - if modifiers & NSEvent.ModifierFlags.option.rawValue != 0 { + if modifiers.contains(.option) { ret |= kAltMask.rawValue } - if modifiers & NSEvent.ModifierFlags.command.rawValue != 0 { + if modifiers.contains(.command) { ret |= kSuperMask.rawValue } return ret diff --git a/sources/SquirrelInputController.swift b/sources/SquirrelInputController.swift index e0eae3648..4a72bc387 100644 --- a/sources/SquirrelInputController.swift +++ b/sources/SquirrelInputController.swift @@ -58,7 +58,7 @@ final class SquirrelInputController: IMKInputController { break } // print("[DEBUG] FLAGSCHANGED client: \(sender ?? "nil"), modifiers: \(modifiers)") - var rimeModifiers: UInt32 = SquirrelKeycode.osxModifiersToRime(modifiers: modifiers.rawValue) + var rimeModifiers: UInt32 = SquirrelKeycode.osxModifiersToRime(modifiers: modifiers) // For flags-changed event, keyCode is available since macOS 10.15 // (#715) let rimeKeycode: UInt32 = SquirrelKeycode.osxKeycodeToRime(keycode: event.keyCode, keychar: nil, shift: false, caps: false) @@ -99,7 +99,7 @@ final class SquirrelInputController: IMKInputController { shift: modifiers.contains(.shift), caps: modifiers.contains(.capsLock)) if rimeKeycode != 0 { - let rimeModifiers = SquirrelKeycode.osxModifiersToRime(modifiers: modifiers.rawValue) + let rimeModifiers = SquirrelKeycode.osxModifiersToRime(modifiers: modifiers) handled = processKey(rimeKeycode, modifiers: rimeModifiers) rimeUpdate() }