GLFW (LWJGL) 输入 - 按住 CTRL 会阻止 CharCallback
GLFW (LWJGL) Input - Holding CTRL down blocks the CharCallback
我尝试为游戏中的某些文本字段实现简单的 CTRL + V。因此,每当按下或释放 ctrl 时,我都会在 KeyCallback 中为 CTRL 设置一个标志(我测试了这个)。当我现在尝试键入 "V" 时,不会调用 CharCallback。它不应该这样工作吗?如果是,我该怎么做才对?
这就是我在 KeyCallback 中对其进行轮询的方式:
if(key == GLFW_KEY_LEFT_CONTROL && action == GLFW_PRESS) {
controlPressed = true;
}
if(key == GLFW_KEY_LEFT_CONTROL && action == GLFW_RELEASE) {
controlPressed = false;
}
我使用 glfwSetKeyCallback(...) 来设置回调。
这是有意为之的行为。 documentation for glfwSetCharCallback 说(强调我的):
The character callback behaves as system text input normally does and will not be called if modifier keys are held down that would prevent normal text input on that platform, for example a Super (Command) key on OS X or Alt key on Windows. There is a character with modifiers callback that receives these events.
但是,它还声明您可以使用 char mods callback,即使按下修改键也会调用它。
This function sets the character with modifiers callback of the specified window, which is called when a Unicode character is input regardless of what modifier keys are used.
例如:
GLFWCharModsCallback charModsCallback = new GLFWCharModsCallback() {
@Override
public void invoke(long window, int codepoint, int mods) {
// do something with the character and modifier flags
}
};
glfwSetCharModsCallback(window, charModsCallback);
我尝试为游戏中的某些文本字段实现简单的 CTRL + V。因此,每当按下或释放 ctrl 时,我都会在 KeyCallback 中为 CTRL 设置一个标志(我测试了这个)。当我现在尝试键入 "V" 时,不会调用 CharCallback。它不应该这样工作吗?如果是,我该怎么做才对?
这就是我在 KeyCallback 中对其进行轮询的方式:
if(key == GLFW_KEY_LEFT_CONTROL && action == GLFW_PRESS) {
controlPressed = true;
}
if(key == GLFW_KEY_LEFT_CONTROL && action == GLFW_RELEASE) {
controlPressed = false;
}
我使用 glfwSetKeyCallback(...) 来设置回调。
这是有意为之的行为。 documentation for glfwSetCharCallback 说(强调我的):
The character callback behaves as system text input normally does and will not be called if modifier keys are held down that would prevent normal text input on that platform, for example a Super (Command) key on OS X or Alt key on Windows. There is a character with modifiers callback that receives these events.
但是,它还声明您可以使用 char mods callback,即使按下修改键也会调用它。
This function sets the character with modifiers callback of the specified window, which is called when a Unicode character is input regardless of what modifier keys are used.
例如:
GLFWCharModsCallback charModsCallback = new GLFWCharModsCallback() {
@Override
public void invoke(long window, int codepoint, int mods) {
// do something with the character and modifier flags
}
};
glfwSetCharModsCallback(window, charModsCallback);