释放按键时会触发 SDL 左控件 keydown 事件
因此,我有以下代码,用于侦听 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,我忘记将 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.