How to detect command key as a modifier in a glut program running on a mac?
I am developing a GLUT program on a mac. Mac's seem to pass modifiers through GLUT in a funny way. Alt and control keys are not captured by glutGetModifiers() instead they're translated into the button开发者_Python百科 int. The command key doesn't seem to be captured by either glutGetModifiers() or the button int. Also, it doesn't show up as a key in my glutKeyboardFunc(...).
Is there any way to capture/detect the command (apple) key in GLUT?
glutGetModifiers
only detects CTRL, ALT and SHIFT, not the ⌘
key.
The only way I know how to do this 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( "⌘" ) ;
}
While the Carbon solution is better in some cases, one may also directly patch and replace the GLUT framework on mac os x to support the command key. This patch catches the command key and defines a respective modifier mask GLUT_ACTIVE_COMMAND
.
精彩评论