GLUT键按下并在CTRL键上按下 [英] GLUT key down and key up on CTRL key
问题描述
我发现了很多有关使用GLUT来检测是否使用GLUT_ACTIVE_CTRL宏按下 Ctrl 键的信息.显然,此宏仅在键盘或鼠标回调函数中有效.我需要知道是否在主循环中的某个点按下了 Ctrl 键,但是GLUT_ACTIVE_CTRL在这种情况下似乎不起作用.
I've found a lot of information about using GLUT to detect whether the Ctrl key is pressed using the GLUT_ACTIVE_CTRL macro. This macro only works, apparently, within a keyboard or mouse callback function. I need to know whether or not the Ctrl key is pressed at a point in my main loop, but GLUT_ACTIVE_CTRL doesn't seem to work in this context.
那么,有没有一种方法可以以平台无关的GLUT式方式检测 Ctrl 键上的键上移和键下事件(无需键入任何其他键)?
So, is there a way to detect key up and key down events on the Ctrl key (without any other keys being typed) in a platform independent GLUT-ish way?
按下 Ctrl 键时,不会触发键盘回调(至少对于默认设置而言).这是一个基本问题,我只能测试按下另一个键时是否按下了 Ctrl 键,从而触发了键盘回调.
The keyboard callback is not fired (at least for a default setup) when the Ctrl key is pressed. This is the basic problem, that I can only test whether the Ctrl key is or isn't pressed when another key is pressed and thus fires the keyboard callback.
我的设置类似于:
// ... in main function:
glutKeyboardFunc(keyboard);
//later in the code:
void keyboard(unsigned char key, int _x, int _y)
{
printf("keydown \n");
if (glutGetModifiers() == GLUT_ACTIVE_CTRL) {
printf("control key is pressed.\n");
}
//etc.
当我按下任何普通字符时,"keydown"将被打印到标准输出.当我按 Ctrl 键时,什么也没发生.如果我按 Ctrl + C ,则按下了键盘控制键."已打印.
When I press any normal character "keydown " is printed to stdout. When I press the Ctrl key, nothing happens. If I press Ctrl+C, "keydown control key is pressed." is printed.
但是,在主循环中我添加了:
However, in my main loop I added:
if (glutGetModifiers() == GLUT_ACTIVE_CTRL) {
printf("Control key down.\n");
} else {
printf("Control key up.\n");
}
,并且始终打印"Control key up".不管我是否按下 Ctrl 键.
and it always prints "Control key up." regardless of whether I am pressing the Ctrl key or not.
推荐答案
不使用GLUT GLFW .
Not using GLUT as specced. You may wish to check out GLFW.
这篇关于GLUT键按下并在CTRL键上按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!