Klas. S
Klas. S

Reputation: 682

Read input device in C

I'm creating a 2-D platformer game in C that will run in the terminal. I need a way to register "KEY_DOWN" and "KEY_RELEASE" events. As far as I know getchar() reads from stdin and thus can not be used for registering "KEY_RELEASE" events. Neither can it be used for registering if multiple keys are being pressed down at the same time.

Is there a Mac OSX 10.10.5 C library that I can use to solve this problem? Maybe a library which reads input directly from the keyboard instead of the terminal?

Upvotes: 0

Views: 704

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54515

None of the potential answers are likely to be simple:

  • if you are running an application in the terminal, and lacking (as OSX does) a set of system calls for reading the keyboard state directly, it won't work.
  • the available sources describe non-terminal applications (mostly using Cocoa, the OSX GUI, and mostly using ObjectiveC).

Here are a few:

For reference (Cocoa Event Handling Guide):

Upvotes: 1

Related Questions