I'm using an OpenGL project made on Windows, which add the "windows.h" library to solve the GetKeyState error. How can I do this on Mac OS X? Is there a library or do I need to use a similar call?

没有正确的解决方案

其他提示

Ye Olde classic Carbon API has a similar GetKeys function that returns a 128 bit / 16 byte bitmap state of the keyboard. The Carbon API has been deprecated for a couple of MacOS versions, isn't 64 bit, etc, etc. In short, you shouldn't use it.

For Cocoa, the nearest equivalent is to have your own static keyboard state array. Implement handlers for keyDown and keyUp events, and use [event keyCode] to set or clear the keyboard state array.

For the actual keycodes, you need to find the Carbon HIToolbox/Event.h header file and copy out the chunk that has key codes independent of keyboard layout. They've been constant since the days of 68000 Macs.

Hope this helps.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top