ASCII / OpenGL

closed account (N7LhAqkS)
i found this article http://brebru.com/asciicodes.html

but the F12 or F10 or ANY F button on keyboard no working

you know im making an EXIT button in OpenGL it work with 27 on ESC but i need have exit game on F12 and the ASCII code for it doesn't work... :/ you doesn't know someone what is wrong ?
Are you using GLUT? If that's the case, you can use glutSpecialFunc to detect the F keys.

1
2
3
4
5
6
7
//example of a function you might pass to glutSpecialFunc
void specialKeyDown(int key, int x, int y){
	if (key == GLUT_KEY_F12){
		printf("F12 key detected");
		exit(0);
	}
}

Register the callback with glutSpecialFunc before entering the loop.
1
2
3
4
//[initialization stuff goes here]
glutSpecialFunc(specialKeyDown);
//[more initialization stuff]
glutMainLoop();


EDIT: Or, if you're not using GLUT and are handling windows messages yourself, you want to use Virtual Key Codes instead of ASCII key codes.
http://msdn.microsoft.com/en-us/library/ms927178.aspx

1
2
3
4
5
6
//In your windows procedure
case WM_KEYDOWN:
	if (wParam == VK_F12){
		printf("\nF12 Detected");
	}
break;
Last edited on
Topic archived. No new replies allowed.