SDL在启动时没有按下鼠标左键事件

时间:2016-02-25 21:43:05

标签: mouseevent sdl sdl-2

在我的SDL程序启动时,在没有按下物理鼠标左键的情况下注册了鼠标左键事件。按下下一个物理左按钮未注册。所有其他键和按钮正常工作。单击.exe时,鼠标不在窗口的位置。

以下是该事件的规范(取自SDL_Event结构):

type=1025 (SDL_MOUSEBUTTONDOWN)
timestamp=24
windowID=1
which=0
button=1 (SDL_BUTTON_LEFT)
state=1
clicks=1
x=0
y=0

我在使用MinGW(gcc版本4.8.1)进行Windows 8.1编译。

我有SDL版本2.0.3

这是我的源代码:

#include <stdio.h>
#include <SDL.h>

int main(int argc, char* argv[])
{
    SDL_Window* window = NULL;
    SDL_Surface* screen = NULL;
    SDL_Event ev;

    SDL_Init(SDL_INIT_EVERYTHING);

    window = SDL_CreateWindow("SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, 0);
    screen = SDL_GetWindowSurface(window);

    while (1) {
        while (SDL_PollEvent(&ev)) {
            if (ev.type == SDL_QUIT)
                return 0;
            else {
                if (ev.type == SDL_MOUSEBUTTONDOWN) {
                    if (ev.button.button == SDL_BUTTON_LEFT) {
                        printf("MOUSE DOWN\n");
                        printf("type=%d\n", ev.button.type);
                        printf("timestamp=%d\n", ev.button.timestamp);
                        printf("windowID=%d\n", ev.button.windowID);
                        printf("which=%d\n", ev.button.which);
                        printf("button=%d\n", ev.button.button);
                        printf("state=%d\n", ev.button.state);
                        printf("clicks=%d\n", ev.button.clicks);
                        printf("x=%d\n", ev.button.x);
                        printf("y=%d\n\n", ev.button.y);
                    }
                }
            }
        }

        SDL_UpdateWindowSurface(window);

        SDL_Delay(5);
    }

    SDL_FreeSurface(screen);
    SDL_DestroyWindow(window);

    SDL_Quit();

    return 0;
}

我试图通过调用SDL_PumpEvents()和SDL_FlushEvents()来解决它,虽然这删除了第一个(错误的)事件,但第二次按下仍未注册。

我注意到一些奇怪的事情是,当我通过右键单击然后按下&#39;打开&#39;打开程序.exe时,它按预期工作。

如果有人能够阐明这个问题,我们将非常感激。

0 个答案:

没有答案
相关问题