How to detect a command key as a modifier in a glut program running on a Mac?

I am developing a GLUT program on mac. It looks like the Mac seems to be using GLUT to skip modifiers. Alt and control keys are not captured by glutGetModifiers (), but they are translated into an int button. The command key does not seem to be captured by either glutGetModifiers () or the int button. Also, it does not appear as a key in my glutKeyboardFunc (...).

Is there any way to capture / detect a command (apple) in GLUT?

+4
source share
2 answers

glutGetModifiers only detects CTRL, ALT, and SHIFT, not the ⌘ key.

The only way I know is to use Carbon ,

 #include <Carbon/Carbon.h> KeyMap keyStates ; bool IS_KEYDOWN( uint16_t vKey ) { uint8_t index = vKey / 32 ; uint8_t shift = vKey % 32 ; return keyStates[index].bigEndianValue & (1 << shift) ; } void checkInput() { // This grabs all key states, then checks if you were holding down ⌘ or not GetKeys(keyStates) ; if( IS_KEYDOWN( kVK_Command ) ) puts( "⌘" ) ; } 
+2
source

While Carbon's solution is better in some cases, you can also directly fix and replace the GLUT structure on mac os x to support the command key. This patch captures the command key and defines the corresponding GLUT_ACTIVE_COMMAND modifier GLUT_ACTIVE_COMMAND .

0
source

All Articles