美文网首页
C++鼠标API

C++鼠标API

作者: NullUser | 来源:发表于2023-01-15 10:01 被阅读0次

    Windows

    #include <Windows.h>
    int main()
    {
        INPUT input;
        input.type = INPUT_MOUSE;
        input.mi.dx = static_cast<long>(65535.0f / 1920 * 1880);
        input.mi.dy = static_cast<long>(65535.0f / 1080 * 1020);
        input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
        SendInput(1, &input, sizeof(INPUT));
    }
    
    • input.type代表输入类型,有以下枚举,分别代表鼠标、键盘和硬件。
    #define INPUT_MOUSE     0
    #define INPUT_KEYBOARD  1
    #define INPUT_HARDWARE  2
    
    • input.mi.dx/dy 代表输入坐标
    • input.mi.dwFlags代表输入的事件类型,有以下枚举
    #define MOUSEEVENTF_MOVE        0x0001 /* mouse move */
    #define MOUSEEVENTF_LEFTDOWN    0x0002 /* left button down */
    #define MOUSEEVENTF_LEFTUP      0x0004 /* left button up */
    #define MOUSEEVENTF_RIGHTDOWN   0x0008 /* right button down */
    #define MOUSEEVENTF_RIGHTUP     0x0010 /* right button up */
    #define MOUSEEVENTF_MIDDLEDOWN  0x0020 /* middle button down */
    #define MOUSEEVENTF_MIDDLEUP    0x0040 /* middle button up */
    #define MOUSEEVENTF_XDOWN       0x0080 /* x button down */
    #define MOUSEEVENTF_XUP         0x0100 /* x button down */
    #define MOUSEEVENTF_WHEEL                0x0800 /* wheel button rolled */
    #if (_WIN32_WINNT >= 0x0600)
    #define MOUSEEVENTF_HWHEEL              0x01000 /* hwheel button rolled */
    #endif
    #if(WINVER >= 0x0600)
    #define MOUSEEVENTF_MOVE_NOCOALESCE      0x2000 /* do not coalesce mouse moves */
    #endif /* WINVER >= 0x0600 */
    #define MOUSEEVENTF_VIRTUALDESK          0x4000 /* map to entire virtual desktop */
    #define MOUSEEVENTF_ABSOLUTE             0x8000 /* absolute move */
    

    相关文章

      网友评论

          本文标题:C++鼠标API

          本文链接:https://www.haomeiwen.com/subject/lcfacdtx.html