Post

Replies

Boosts

Views

Activity

Reply to keyboardGetUnicodeString returns carrier return
Okay i was able to fix my problem. The problem was not shown in the code of the original post. As the comment of OOPer correctly stated, the output '\r' was actually to be expected (when CTRL + M is pressed). My goal was to print the key without modifier keys. The code for this would be (create new event where i'd expect that the modifiers are NOT beeing printed):  let keycode = CGKeyCode(event.getIntegerValueField(.keyboardEventKeycode))  let keycodeEvent = CGEvent.init(keyboardEventSource: nil, virtualKey: keycode, keyDown: true) var length = 0   keycodeEvent!.keyboardGetUnicodeString(maxStringLength: 0, actualStringLength: &length, unicodeString: nil)   var chars = [UniChar](repeating: 0, count: length)       keycodeEvent!.keyboardGetUnicodeString(maxStringLength: chars.count, actualStringLength: &length, unicodeString: &chars)       debugPrint("keycode \(keycode) -> \(String(utf16CodeUnits: chars, count: length).uppercased())") However the problem is that this would still print '\r' ... the solution is as follows: Replace line 2 with: let keycodeEvent = CGEvent.init(keyboardEventSource: .init(stateID: .privateState), virtualKey: keycode, keyDown: true) Without .privateState, the modifier states seem to be carried over...
Jun ’21