win32: simulate a click without simulating mouse movement?

后端 未结 2 999
终归单人心
终归单人心 2020-12-09 11:53

I\'m trying to simulate a mouse click on a window. I currently have success doing this as follows (I\'m using Python, but it should apply to general win32):

         


        
2条回答
  •  囚心锁ツ
    2020-12-09 12:31

    Try WindowFromPoint() function:

    POINT pt;
        pt.x = 30; // This is your click coordinates
        pt.y = 30;
    
    HWND hWnd = WindowFromPoint(pt);
    LPARAM lParam = MAKELPARAM(pt.x, pt.y);
    PostMessage(hWnd, WM_RBUTTONDOWN, MK_RBUTTON, lParam);
    PostMessage(hWnd, WM_RBUTTONUP, MK_RBUTTON, lParam);
    

提交回复
热议问题