未检测到SDL按键事件 [英] No SDL Keypress events being detected
问题描述
我完全被解释为什么这段代码没有得到任何SDL keypress事件。其他SDL事件(为了清晰而删除)工作正常。它不工作在我的XP或Vista机器。没有编译/链接错误,只是从未收到keydown事件。
I am completely stumped as to why this code does not get any SDL keypress events. The other SDL events (removed for clarity) work fine. It does not work on my XP or Vista machines. No compile/link errors, just never recieve a keydown event.
#include "SDL/SDL.h"
// Yes SDL.lib and SDLmain.lib are linked
Uint32 TimeLeft(void)
{
static Uint32 next_time = 0;
Uint32 now;
now = SDL_GetTicks();
if ( next_time <= now ) {
next_time = now + tickInterval;
return 0;
}
return(next_time-now);
}
int main( int argc, char **argv )
{
if( -1 == SDL_Init( SDL_INIT_EVERYTHING ) )
{
cerr << "Error: SDL_Init failed" << endl;
return -1;
}
SDL_Event event;
bool quit = false;
while( !quit )
{
while( SDL_PollEvent( &event ) )
{
switch( event.type )
{
case SDL_KEYDOWN:
switch( event.key.keysym.sym )
{
case SDLK_ESCAPE:
case SDLK_q:
quit = true;
break;
default:
break;
}
break;
case SDL_JOYAXISMOTION:
// stuff removed
break;
case SDL_QUIT:
quit = true;
break;
default:
break;
}
}
SDL_Delay( TimeLeft() );
}
SDL_Quit();
return 0;
}
推荐答案
一个带有 SDL_SetVideoMode 以获取鼠标和键盘事件的窗口。
You'll need to create a window with SDL_SetVideoMode to get mouse and keyboard events.
我不认为你会有运气试图 SDL_WM_GrabInput 鼠标和键盘没有窗口。它也可能在moderm Windows机器上第一次引发安全警报。
I don't think you'll have luck trying to SDL_WM_GrabInput the mouse and keyboard without a window. It may also raise security alerts the first time on moderm Windows machines.
这篇关于未检测到SDL按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!