Skip to content

Commit

Permalink
Expose and fix missing numericPad flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jan 8, 2024
1 parent 4e69891 commit 30e9e8b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
jobs:
test:
name: Test
runs-on: macOS-latest
runs-on: macOS-13
strategy:
matrix:
destination:
Expand All @@ -27,7 +27,5 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install XCBeautify
run: brew install xcbeautify
- name: Test platform ${{ matrix.destination }}
run: set -o pipefail && xcodebuild -scheme KeyCodes -destination "${{ matrix.destination }}" test | xcbeautify --renderer github-actions
4 changes: 4 additions & 0 deletions Sources/KeyCodes/NSEvent+Key.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ extension NSEvent {
flags.insert(.alphaShift)
}

if deviceIndependentFlags.contains(.numericPad) {
flags.insert(.numericPad)
}

return flags
}

Expand Down
1 change: 0 additions & 1 deletion Tests/KeyCodesTests/KeyCodesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@ final class KeyCodesTests: XCTestCase {
XCTAssertEqual(Key(">"), Key(keyCode: .keyboardPeriod, characters: ">", modifierFlags: [.shift]))
XCTAssertEqual(Key("/"), Key(keyCode: .keyboardSlash, characters: "/"))
XCTAssertEqual(Key("?"), Key(keyCode: .keyboardSlash, characters: "?", modifierFlags: [.shift]))

}
}
17 changes: 17 additions & 0 deletions Tests/KeyCodesTests/NSEventTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import XCTest
import KeyCodes
import Carbon.HIToolbox

Check failure on line 3 in Tests/KeyCodesTests/NSEventTests.swift

View workflow job for this annotation

GitHub Actions / Test (platform=tvOS Simulator,name=Apple TV)

no such module 'Carbon.HIToolbox'

final class NSEventTests: XCTestCase {
func testDeviceIndependentOnly() throws {
let eventRef = try XCTUnwrap(CGEvent(keyboardEventSource: nil, virtualKey: CGKeyCode(kVK_ANSI_0), keyDown: true))
eventRef.flags = [.maskCommand, .maskNumericPad]

let event = try XCTUnwrap(NSEvent(cgEvent: eventRef))

XCTAssertEqual(event.modifierFlags, [.command, .numericPad])
XCTAssertEqual(event.modifierFlags.deviceIndependentOnly, [.command, .numericPad])

XCTAssertEqual(event.keyModifierFlags, [.command, .numericPad])
}
}

0 comments on commit 30e9e8b

Please sign in to comment.