Duplicate values for different key presses

Has anyone ever encountered the situation where you press different keys on your keyboard, you can cout identical values? E.g. “g” and the down arrow both cout 103. Anyone know why this is happening? And how to get unique values out?

this is happening because glut has two keyboard input callback functions, glutKeyboardFunc and glutSpecialKeyboardFunc and for some reason they decided to have keys share the same values.

we did notice this recently and it’s been fixed for the next release, you can see some code on the svn (in ofConstants) that adds a modifier to the special keys so that the two functions don’t overlap.

if you don’t want to wait, you can likely add this to ofConstants:

  
  
  
//--------------------------------------------  
//  
// 	Keyboard definitions  
//  
// 	ok -- why this?  
// 	glut key commands have some annoying features,  
// 	in that some normal keys have the same value as special keys,  
// 	but we want ONE key routine, so we need to redefine several,  
// 	so that we get some normalacy across keys routines  
//  
// 	(everything that comes through "glutSpecialKeyFunc" will get 256 added to it,  
// 	to avoid conflicts, before, values like "left, right up down" (ie, 104, 105, 106) were conflicting with  
// 	letters.. now they will be 256 + 104, 256 + 105....)  
  
  
#define OF_KEY_MODIFIER 	0x0100  
  
// zach - there are more of these keys, we can add them here...  
// these are keys that are not coming through "special keys"  
// via glut, but just other keys on your keyboard like 'a', 'b'  
  
  
#define OF_KEY_BACKSPACE	8  
#define OF_KEY_RETURN		13  
#define OF_KEY_PRINTSCR		127  
  
// now the problem keys:  
  
#define OF_KEY_F1			(GLUT_KEY_F1 | OF_KEY_MODIFIER)  
#define OF_KEY_F2			(GLUT_KEY_F2 | OF_KEY_MODIFIER)  
#define OF_KEY_F3			(GLUT_KEY_F3 | OF_KEY_MODIFIER)  
#define OF_KEY_F4			(GLUT_KEY_F4 | OF_KEY_MODIFIER)  
#define OF_KEY_F5			(GLUT_KEY_F5 | OF_KEY_MODIFIER)  
#define OF_KEY_F6			(GLUT_KEY_F6 | OF_KEY_MODIFIER)  
#define OF_KEY_F7			(GLUT_KEY_F7 | OF_KEY_MODIFIER)  
#define OF_KEY_F8			(GLUT_KEY_F8 | OF_KEY_MODIFIER)  
#define OF_KEY_F9			(GLUT_KEY_F9 | OF_KEY_MODIFIER)  
#define OF_KEY_F10			(GLUT_KEY_F10 | OF_KEY_MODIFIER)  
#define OF_KEY_F11			(GLUT_KEY_F11 | OF_KEY_MODIFIER)  
#define OF_KEY_F12			(GLUT_KEY_F12 | OF_KEY_MODIFIER)  
  
#define OF_KEY_LEFT			(GLUT_KEY_LEFT | OF_KEY_MODIFIER)  
#define OF_KEY_UP			(GLUT_KEY_UP | OF_KEY_MODIFIER)  
#define OF_KEY_RIGHT		(GLUT_KEY_RIGHT | OF_KEY_MODIFIER)  
#define OF_KEY_DOWN			(GLUT_KEY_DOWN | OF_KEY_MODIFIER)  
#define OF_KEY_PAGE_UP		(GLUT_KEY_PAGE_UP | OF_KEY_MODIFIER)  
#define OF_KEY_PAGE_DOWN	(GLUT_KEY_PAGE_DOWN | OF_KEY_MODIFIER)  
#define OF_KEY_HOME			(GLUT_KEY_HOME | OF_KEY_MODIFIER)  
#define OF_KEY_END			(GLUT_KEY_END | OF_KEY_MODIFIER)  
#define OF_KEY_INSERT		(GLUT_KEY_INSERT | OF_KEY_MODIFIER)  
  
  
//--------------------------------------------  
  
  
  

and change this is ofGlutGlue.h

  
  
void special_key_cb(int key, int x, int y) {  
   OFSAptr->keyPressed((key | OF_KEY_MODIFIER));  
  
}  
  

so then you can check, if (key == OF_KEY_LEFT) for example…

hope that helps !

take care,
zach

I’ve said it before, and I’ll say it again: YOU THE MAN!