Skip to content

Commit

Permalink
fix: address modifier key issue on key up
Browse files Browse the repository at this point in the history
  • Loading branch information
socsieng committed Jan 2, 2021
1 parent 26ad67e commit 0bfa58a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/SendKeysLib/KeyPresser.swift
Expand Up @@ -24,8 +24,8 @@ class KeyPresser {
}

func keyUp(event: CGEvent) -> CGEvent? {
let keyUpEvent = CGEvent(keyboardEventSource: CGEventSource(event: event), virtualKey: 0, keyDown: false)
keyUpEvent?.flags = event.flags
let keyCode = UInt16(event.getIntegerValueField(.keyboardEventKeycode))
let keyUpEvent = CGEvent(keyboardEventSource: CGEventSource(event: event), virtualKey: keyCode, keyDown: false)
keyUpEvent?.post(tap: CGEventTapLocation.cghidEventTap)

return keyUpEvent
Expand All @@ -45,7 +45,7 @@ class KeyPresser {
}
}

if !flags.isEmpty {
if !modifiers.isEmpty {
keyEvent?.flags = flags
}

Expand Down
9 changes: 9 additions & 0 deletions Tests/SendKeysTests/CommandIteratorTests.swift
Expand Up @@ -23,6 +23,15 @@ final class CommandIteratorTests: XCTestCase {
])
}

func testParsesKeyPressDelete() throws {
let commands = getCommands(CommandsIterator("<c:delete>"))
XCTAssertEqual(
commands,
[
Command(CommandType.keyPress, ["delete"])
])
}

func testParsesKeyPressesWithModifierKey() throws {
let commands = getCommands(CommandsIterator("<c:a:command>"))
XCTAssertEqual(
Expand Down

0 comments on commit 0bfa58a

Please sign in to comment.