Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

向窗口发送ESC #17

Open
suhao opened this issue Nov 24, 2022 · 0 comments
Open

向窗口发送ESC #17

suhao opened this issue Nov 24, 2022 · 0 comments

Comments

@suhao
Copy link
Member

suhao commented Nov 24, 2022

在Windows系统的界面编程中,浏览器编程是一种热门技术。

内嵌一个浏览器窗口并全屏播放,如果浏览器窗口在A屏,此时在B屏执行相关的窗口操作,此时可能浏览器未正常退出全屏,我们可以向窗口发送ESC命令。

    POINT position = {0};
    ::GetCursorPos(&position);

    CRect full_rect;
    ::GetWindowRect(full_sreen_hwnd_, &full_rect);

    INPUT input[2];
    memset(input, 0, sizeof(input));

    input[0].type = INPUT_MOUSE;
    input[0].mi.dx =
        static_cast<long>(65535.0f / (GetSystemMetrics(SM_CXSCREEN) - 1) *
                          (full_rect.left + 100));
    input[0].mi.dy = static_cast<long>(
        65535.0f / (GetSystemMetrics(SM_CYSCREEN) - 1) * (full_rect.top + 100));
    input[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE |
                          MOUSEEVENTF_MIDDLEDOWN | MOUSEEVENTF_MIDDLEUP;

    input[1].ki.wVk = VK_ESCAPE;
    input[1].type = INPUT_KEYBOARD;
    input[1].ki.wScan =
        static_cast<BYTE>(MapVirtualKey(VK_ESCAPE, MAPVK_VK_TO_VSC));

    ::SendInput(2, input, sizeof(INPUT));

    ::SetCursorPos(position.x, position.y);

其中,full_sreen_hwnd_可以通过OnActivateApp消息时取GetForegroundWindow,然后判断与浏览器同进程、同线程等约束条件而得。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant