Skip to content

Commit

Permalink
🐛 Fix #14
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Aug 31, 2023
1 parent 893d2ae commit 403dedb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Loop/Extensions/CGKeyCode+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ extension CGKeyCode {
static let kVK_DownArrow: CGKeyCode = 0x7D
static let kVK_UpArrow: CGKeyCode = 0x7E

// When the globe key is being pressed
static let kVK_LeftArrow_Globe: CGKeyCode = 0x73
static let kVK_RightArrow_Globe: CGKeyCode = 0x77
static let kVK_DownArrow_Globe: CGKeyCode = 0x79
static let kVK_UpArrow_Globe: CGKeyCode = 0x74

// ISO keyboards only
static let kVK_ISO_Section: CGKeyCode = 0x0A

Expand All @@ -151,6 +157,18 @@ extension CGKeyCode {
static let kVK_JIS_Eisu: CGKeyCode = 0x66
static let kVK_JIS_Kana: CGKeyCode = 0x68

// Some keycodes seem to alter when a modifier key (ex. the globe key) is being pressed.
var baseKey: CGKeyCode {
switch self {
case .kVK_ANSI_KeypadEnter: CGKeyCode.kVK_Return
case .kVK_LeftArrow_Globe: CGKeyCode.kVK_LeftArrow
case .kVK_RightArrow_Globe: CGKeyCode.kVK_RightArrow
case .kVK_DownArrow_Globe: CGKeyCode.kVK_DownArrow
case .kVK_UpArrow_Globe: CGKeyCode.kVK_UpArrow
default: self
}
}

var isModifier: Bool {
return (.kVK_RightCommand ... .kVK_Function).contains(self)
}
Expand Down
4 changes: 2 additions & 2 deletions Loop/Helpers/KeybindMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class KeybindMonitor {
}

if keyEvent.type == .keyUp {
KeybindMonitor.shared.pressedKeys.remove(keyEvent.keyCode)
KeybindMonitor.shared.pressedKeys.remove(keyEvent.keyCode.baseKey)
} else if keyEvent.type == .keyDown {
KeybindMonitor.shared.pressedKeys.insert(keyEvent.keyCode)
KeybindMonitor.shared.pressedKeys.insert(keyEvent.keyCode.baseKey)
}

KeybindMonitor.shared.performKeybind(event: keyEvent)
Expand Down

0 comments on commit 403dedb

Please sign in to comment.