swift3cgeventtap

Swift Getting Character from Keycode Using CGEvent


I have a key code from:

let keycode = event.GetIntegerValueField(.keyboardEventKeycode)

Is there way to translate it into a character?

func keyboardGetUnicodeString(maxStringLength: Int, actualStringLength: UnsafeMutablePointer <Int>?, unicodeString: UnsafeMutablePointer <UniChar>?)

It seems this is what I need, but it looks scary! Could someone explain how to call that function from swift? Thanks!


Solution

  • var char = UniChar()
    var length = 0
    event.keyboardGetUnicodeString(maxStringLength: 1, actualStringLength: &length, unicodeString: &char)