释放按键时会触发 SDL 左控件 keydown 事件

发布于 2024-11-28 16:29:33 字数 757 浏览 1 评论 0原文

因此,我有以下代码,用于侦听 keydown 事件,然后在收到事件后立即退出:

int main(int argc, char** argv) {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF);
    SDL_Event _event;
    while (1) {
        while (SDL_PollEvent(&_event)) {
            if (_event.type == SDL_KEYDOWN) {
                return 0;
            }
        }
        SDL_GL_SwapBuffers();
    }
}

当我运行它时,我可以按任何箭头键、字母、数字、F1-F12...几乎任何键,除了左控制键,程序立即退出。
但是当我按下左控制键时,程序不会退出,直到我释放该键。

虽然示例没有显示它,但在向左按另一个键-control 被按住(例如 ctrl+s)会导致触发缺少的 control keydown 事件(以及第二个事件,表示 's' 被按下)。

有什么方法可以禁用左控制键的这种奇怪行为吗?

顺便说一句,这是在 Windows 上使用 mingw 实现的。我尚未使用任何其他编译器/操作系统测试此行为。

So I have the following code that listens for a keydown event and then exits as soon as it receives one:

int main(int argc, char** argv) {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF);
    SDL_Event _event;
    while (1) {
        while (SDL_PollEvent(&_event)) {
            if (_event.type == SDL_KEYDOWN) {
                return 0;
            }
        }
        SDL_GL_SwapBuffers();
    }
}

When I run it, I can press any arrow key, letter, number, F1-F12... pretty much any key except for the left control key, and the program will exit instantly.
But when I press the left control key, the program doesn't exit until I release the key.

And although the example doesn't show it, pressing another key while left-control is being held down (eg ctrl+s) causes the missing control keydown event to be triggered (along with a second event that says 's' was pressed).

Is there any way to disable this strange behavior for the left-control key?

Btw, this is on Windows using mingw. I haven't tested this behavior with any other compilers/operating systems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

渔村楼浪 2024-12-05 16:29:33

事实证明,我忘记将 sdl.dll 放入与我的可执行文件相同的目录中。它正在加载恰好位于路径环境变量上的其他一些 sdl.dll。我将与我正在编译的版本(1.2.14)相匹配的 sdl.dll 放入我的应用程序目录中,现在它工作正常。

So it turns out that I had forgotten to put sdl.dll into the same directory as my executable. It was loading some other sdl.dll that happened to be on the path environment variable. I put the sdl.dll that matched the version I was compiling against (1.2.14) into my application's directory, and it works fine now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文