mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-02 03:59:23 +08:00
* Implement key combination holds for enabling/disabling keyboard or trackpad * Improve keyboard/trackpad connection status HUD
40 lines
1.3 KiB
Swift
40 lines
1.3 KiB
Swift
import AppKit
|
|
|
|
/// An input device whose events can be delivered to or withheld from the virtual machine.
|
|
enum VMInputDevice: Hashable, CaseIterable, Sendable {
|
|
case keyboard
|
|
case pointingDevice
|
|
}
|
|
|
|
extension VMInputDevice {
|
|
var deliveryMask: VMEventDeliveryMask {
|
|
switch self {
|
|
case .keyboard: .keyboard
|
|
case .pointingDevice: .mouse
|
|
}
|
|
}
|
|
|
|
/// The modifier keys that toggle delivery of this device's events when held down on their own.
|
|
///
|
|
/// The shortcuts are made up of modifier keys only so that holding one down doesn't type anything in the guest.
|
|
var toggleModifiers: NSEvent.ModifierFlags {
|
|
switch self {
|
|
case .keyboard: [.control, .option, .command]
|
|
case .pointingDevice: [.control, .option, .shift]
|
|
}
|
|
}
|
|
|
|
/// The symbols for the keys in ``toggleModifiers``, in the order they're conventionally displayed.
|
|
var toggleShortcutSymbols: [String] {
|
|
switch self {
|
|
case .keyboard: ["⌃", "⌥", "⌘"]
|
|
case .pointingDevice: ["⌃", "⌥", "⇧"]
|
|
}
|
|
}
|
|
}
|
|
|
|
extension NSEvent.ModifierFlags {
|
|
/// The modifier keys that are taken into account when matching an input toggle shortcut.
|
|
static let inputToggleCandidates: NSEvent.ModifierFlags = [.control, .option, .shift, .command]
|
|
}
|