4

I am writing an application in C++ using CGL/OpenGL, and need keyboard/mouse input. I was trying to avoid Objective-C and Cocoa if possible. I am aware that one can capture input using Carbon, but seems that Carbon is slowly being phased out, plus it is not clear if it plays well with 64-bit applications. Does anybody know if there any other alternatives in OSX for mouse/keyboard input using C++ without going to something very low level (e.g. I/O kit)? Any code snippets to get me started?

Thank you-

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
cjcela
  • 268
  • 1
  • 10
  • What do you use for windowing ? Doesn't it provide input ? – fouronnes Mar 22 '11 at 21:11
  • I'm using CGL, which provides a full screen OpenGL surface, but no event loop or input. I was hoping to be able to run a custom event loop. – cjcela Mar 22 '11 at 22:41
  • On a longshot, would GLUT help you out here? I've used it for keyboard/mouse handling in prototype code. – holtavolt Mar 23 '11 at 23:51
  • I have used GLUT before as well, but I was hoping there was a way to handle my own event loop. To my knowledge, GLUT handles events only withing its own event loop. – cjcela Mar 25 '11 at 00:05

2 Answers2

2

Quartz event taps might do what you want. Without knowing why you are trying to avoid using the Cocoa event system it's hard to know what technology would be best for what you are trying to do.

smorgan
  • 20,228
  • 3
  • 47
  • 55
  • Thank you - I will look into it. I am not trying to avoid Cocoa per se.. what I cannot use is Objective-C.. see, I have some C++ code I want to use, and while Objective-C++ mostly works, it does not like virtual functions (which I need to use because of the way the C++ code is structured). So any C or C++ API that works with 64 bits should do it. – cjcela Mar 30 '11 at 23:38
  • 1
    Do you have a specific example of what doesn't work? I've worked in several large Objective-C++ codebases, and never had any problems with virtual functions. – smorgan Mar 31 '11 at 00:12
0

Gaffer on Games wrote an article doing just what you want, context and surface creation with CGL and a minimal event loop (although it's a little out of date, for El Capitan you need CGLSetFullScreenOnDisplay())

http://gafferongames.com/2009/01/19/opengl-on-macosx/

It uses InstallApplicationEventHandler, one of the two keyboard APIs mentioned here:

Keyboard input on OSX

Community
  • 1
  • 1