Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

PostMessage send right mouse button

  1. User

    PostMessage send right mouse button

  2. Assistant

    To send a right mouse button click using the PostMessage function in Windows, you can use the following code:

    #include <Windows.h>
    
    int main() {
        HWND targetWindow = FindWindow(NULL, "Window Title"); // Replace "Window Title" with the title of the window you want to send the click to
    
        if (targetWindow != NULL) {
            // Calculate the coordinates where you want to send the click
            int x = 100;
            int y = 100;
    
            LPARAM pt = MAKELPARAM(x, y);
    
            // Send right mouse button down event
            PostMessage(targetWindow, WM_RBUTTONDOWN, MK_RBUTTON, pt);
    
            // Send right mouse button up event
            PostMessage(targetWindow, WM_RBUTTONUP, 0, pt);
    
            return 0;
        } else {
            // Window not found
            return 1;
        }
    }
    

    Make sure to replace "Window Title" with the actual title of the window you want to send the right mouse button click to. You also need to provide the coordinates (x and y) where you want to send the click.

    This code snippet will find the window with the specified title using the FindWindow function. Then, it will send a right mouse button down event followed by a right mouse button up event using PostMessage.

    Note: MK_RBUTTON is used to specify that the right mouse button is held down while sending the message.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.