0

I'm trying to use the I/O Kit framework for recognize when a user press a key and when he release it. I've found this: How to tap/hook keyboard events in OSX and record which keyboard fires each event, but with this code I can only know the "scancode" and when the key is pressed, consequently I'm unable to know at which character correspond the "scancode". The unique solution I've founded is that I have to write an enormous switch statement like this

switch(scancode) {
case 4:
    printf("a")
case 40:
    printf(" ")
case ...:
    printf(...)

but I'm sure that there's a better solution. I've tried to read Apple's guide about HID in the I/O kit but I didn't find a solution... Anyone know how to solve this problem?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
pino
  • 25
  • 8
  • I've read somewhere that the MLX (small graphic lib) had some kind of hook to grab the keys you were typing – juleslasne Mar 11 '17 at 15:34
  • What is your high-level goal? There's likely a much better approach. For example, you might be able to use a Cocoa event monitor or a Quartz event tap. – Ken Thomases Mar 11 '17 at 18:04
  • I can't use Cocoa event monitor beacuse is written in Objective-C instead of mine that is written in C. I'm going to read what is the Quartz event tap. However my goal is to know wich letter was pressed by user for use it as a musician keyboard (for example 'a' correspond to the note C). juleslasne, I don't know if I can use a graphic library because for now my application is command-line.. – pino Mar 11 '17 at 18:55
  • I saw that also Quartz event is part of a graphical library... Is possible use them if my application is command-line? – pino Mar 11 '17 at 19:09

0 Answers0