Skip to content

first mouse click in window after window creation not registered #8358

@u-an-i

Description

@u-an-i

Window created with SDL_CreateWindow("name", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, SDL_WINDOW_RESIZABLE).

Polled events checked for SDL_MOUSEBUTTONDOWN.

Many attempts at workarounding did not succeed, eg. neither SDL_WINDOW_MOUSE_FOCUS nor SDL_RaiseWindow.

printf to attached console does let the first mouse click register.

Current solution:

int x, y;
SDL_GetWindowPosition(window, &x, &y);
SDL_WarpMouseGlobal(x + centerX, y + centerY);
INPUT fakeFirstClick[2];
fakeFirstClick[0].type = INPUT_MOUSE;
fakeFirstClick[0].mi.dx = 0;
fakeFirstClick[0].mi.dy = 0;
fakeFirstClick[0].mi.mouseData = 0;
fakeFirstClick[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
fakeFirstClick[0].mi.time = 0;
fakeFirstClick[0].mi.dwExtraInfo = (ULONG_PTR)NULL;
fakeFirstClick[1].type = INPUT_MOUSE;
fakeFirstClick[1].mi.dx = 0;
fakeFirstClick[1].mi.dy = 0;
fakeFirstClick[1].mi.mouseData = 0;
fakeFirstClick[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
fakeFirstClick[1].mi.time = 0;
fakeFirstClick[1].mi.dwExtraInfo = (ULONG_PTR)NULL;
SendInput(2, fakeFirstClick, sizeof(INPUT));

Details at https://discourse.libsdl.org/t/first-mouse-click-in-window-after-window-creation-not-registered/46441

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions