特殊键输入不起作用(输入、退格、制表符等)
Special key input not working (Enter, backspace, tab etc)
我的按键代码适用于所有键盘字母,但不适用于 Enter 或 Tab.
等键
glfwSetCharCallback(window, character_callback);
void character_callback(GLFWwindow* window, unsigned int codepoint)
{
char c = codepoint;
printf("%c", c);
}
当我按 Tab 或 Enter 时,该功能甚至没有 运行 但它确实适用于 Space 吧,我将如何接收所有按键?
你应该使用 glfwSetKeyCallback
, not glfwSetCharCallback
, since you're interested in keys instead of characters. See the Keyboard Input docs and the list of keyboard key macros.
我不确定为什么 Tab 和 Enter 不产生字符:它们通常会分别产生 0x09
和 0x0d
在其他工具包中(例如 freeglut 和 Qt)。但显然,这就是 GLFW 想要的方式,请参阅他们的问题 Backspace not reported to character callbacks:
elmindreda commented on Apr 12, 2017 •
Use the key callback for keys like Enter and Backspace. It provides press, repeat and release events.
我的按键代码适用于所有键盘字母,但不适用于 Enter 或 Tab.
等键glfwSetCharCallback(window, character_callback);
void character_callback(GLFWwindow* window, unsigned int codepoint)
{
char c = codepoint;
printf("%c", c);
}
当我按 Tab 或 Enter 时,该功能甚至没有 运行 但它确实适用于 Space 吧,我将如何接收所有按键?
你应该使用 glfwSetKeyCallback
, not glfwSetCharCallback
, since you're interested in keys instead of characters. See the Keyboard Input docs and the list of keyboard key macros.
我不确定为什么 Tab 和 Enter 不产生字符:它们通常会分别产生 0x09
和 0x0d
在其他工具包中(例如 freeglut 和 Qt)。但显然,这就是 GLFW 想要的方式,请参阅他们的问题 Backspace not reported to character callbacks:
elmindreda commented on Apr 12, 2017 •
Use the key callback for keys like Enter and Backspace. It provides press, repeat and release events.