gpt4 book ai didi

java - GLFW (LWJGL) 输入 - 按住 CTRL 会阻止 CharCallback

转载 作者:行者123 更新时间:2023-11-30 10:47:24 25 4
gpt4 key购买 nike

我尝试为游戏中的某些文本字段实现简单的 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);

关于java - GLFW (LWJGL) 输入 - 按住 CTRL 会阻止 CharCallback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36177689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com