Files
VirtualBuddy/VirtualUI/Source/Session/Components/InputControl/VMInputDevice.swift
Guilherme Rambo bac5b9a3ca Implement key combinations and UI for keyboard/mouse toggles (#782)
* Implement key combination holds for enabling/disabling keyboard or trackpad

* Improve keyboard/trackpad connection status HUD
2026-10-05 16:41:13 -03:00

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]
}