Intercepting keyboard input

I have a C program that is using putchar() for output and getchar() for input.

output redirection to a pipe and establishing a readabilityHandler now works. At least in a separate test app where I'm using print() and printf()s. That test app doesn't yet use getchar().

Problem still is how I can intercept what normally is typed into the keyboard panel so I can interpret it prior to sending it to the textView.

The words “keyboard panel” and “textView” make this sound like a question about the AppKit or UIKit libraries, which would belong elsewhere. This forum is about the Swift language itself.

However, NSTextViewDelegate might be a good place to start looking. Otherwise, Apple’s developer forums or stackoverflow.com would be good places to ask.


Just please, please don’t listen for keypresses if you are working with text. I’ve used too many programs that listened to and overrode only the keys they cared about, and let the rest through as unprocessed text. But since they misjudged my keyboard layout, the result left me with two of some letters and none of others.

And if you are not working with text, please, please don’t listen for text input. I’ve also tried to play enough games where the controls incorrectly assumed a certain keyboard layout, resulting in the buttons for left and right movement being on opposite ends of the keyboard and backwards.

1 Like

Thanks. Will turn to the appropriate forums.