Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import CoreGraphicsimport RealityDriverSupportimport Testing
struct DriverNativeKeyboardFlagsTests { @Test(arguments: [ (UInt64(0x0002_0000), UInt16(56)), (0x0004_0000, 59), (0x0008_0000, 58), (0x0010_0000, 55), (0x0080_0000, 63), ]) func modifierSideFlagsMatchNativeConstructors(_ pair: (UInt64, UInt16)) throws { let native = try #require(CGEvent(keyboardEventSource: nil, virtualKey: pair.1, keyDown: true)) let sequence = try DriverModifierSequence(flags: pair.0, initialFlags: 0, heldKeys: []) let event = try #require(sequence.pressed.first) #expect(native.type == .flagsChanged) let side = event.flags & 0x0000_FFFF #expect(native.flags.rawValue & side == side) #expect(pair.1 == 63 || side != 0) #expect(event.flags & pair.0 == pair.0) }
@Test(arguments: [UInt16(123), 124, 125, 126]) func arrowsKeepKeypadContextWithoutInventingAFnChord(_ key: UInt16) throws { let native = try #require(CGEvent(keyboardEventSource: nil, virtualKey: key, keyDown: true)) let sequence = try DriverModifierSequence(flags: 0x000C_0000, initialFlags: 0, heldKeys: []) let flags = DriverModifierSequence.keyboardFlags( intrinsicFlags: native.flags.rawValue, activeFlags: sequence.activeFlags) #expect(native.type == .keyDown) #expect(flags & 0x0020_0000 == native.flags.rawValue & 0x0020_0000) #expect(flags & 0x0080_0000 == 0) #expect(flags & 0x000C_0021 == 0x000C_0021) #expect(sequence.pressed.map(\.key) == [59, 58]) #expect(!sequence.pressed.contains { $0.key == 63 }) #expect(sequence.released.last?.flags == 0) }
@Test func keyboardContextCannotAdoptStaleLogicalOrDeviceModifiers() { let intrinsic: UInt64 = 0x209F_207F let flags = DriverModifierSequence.keyboardFlags(intrinsicFlags: intrinsic, activeFlags: 0x000C_0021) #expect(flags == 0x200C_0021) }
@Test func anExplicitFnChordStillPressesAndReleasesItsOwnFnKey() throws { let sequence = try DriverModifierSequence(flags: 0x008C_0000, initialFlags: 0, heldKeys: []) let flags = DriverModifierSequence.keyboardFlags(intrinsicFlags: 0, activeFlags: sequence.activeFlags) #expect(sequence.pressed.map(\.key) == [59, 58, 63]) #expect(flags & 0x0080_0000 != 0) #expect(sequence.released.last?.flags == 0) }
@Test func onlyTheBaselineCanPreserveCapsLock() throws { let withoutCaps = try DriverModifierSequence(flags: 0x000C_0000, initialFlags: 0, heldKeys: []) #expect( DriverModifierSequence.keyboardFlags(intrinsicFlags: 0x0001_0000, activeFlags: withoutCaps.activeFlags) & 0x0001_0000 == 0) let withCaps = try DriverModifierSequence(flags: 0x000C_0000, initialFlags: 0x0001_0000, heldKeys: []) #expect( DriverModifierSequence.keyboardFlags(intrinsicFlags: 0, activeFlags: withCaps.activeFlags) & 0x0001_0000 != 0) }}