Skip to content

Commit

Permalink
fix: handle a key correctly as keycode 0
Browse files Browse the repository at this point in the history
  • Loading branch information
socsieng committed Jan 7, 2021
1 parent c4a4997 commit 29209a3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/SendKeysLib/KeyPresser.swift
Expand Up @@ -32,11 +32,11 @@ class KeyPresser {
}

private func createKeyEvent(key: String, modifiers: [String], keyDown: Bool) throws -> CGEvent? {
let keycode = KeyCodes.getKeyCode(key) ?? 0
let keycode = KeyCodes.getKeyCode(key)
let flags = try! KeyPresser.getModifierFlags(modifiers)
let keyEvent = CGEvent(keyboardEventSource: nil, virtualKey: keycode, keyDown: keyDown)
let keyEvent = CGEvent(keyboardEventSource: nil, virtualKey: keycode ?? 0, keyDown: keyDown)

if keycode == 0 {
if keycode == nil {
if key.count == 1 {
let utf16Chars = Array(key.utf16)
keyEvent!.keyboardSetUnicodeString(stringLength: utf16Chars.count, unicodeString: utf16Chars)
Expand Down

0 comments on commit 29209a3

Please sign in to comment.