Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将鼠标单击发送到另一个窗口c#_C#_Winapi - Fatal编程技术网

将鼠标单击发送到另一个窗口c#

将鼠标单击发送到另一个窗口c#,c#,winapi,C#,Winapi,我想在窗口(背景)x/y坐标处模拟左键单击 我已经搜索并找到了很多东西来模拟鼠标点击到其他窗口,但它不能100%正常工作 我的代码: private const int WM_LBUTTONDOWN = 0x201; //Left mousebutton down private const int WM_LBUTTONUP = 0x202; //Left mousebutton up [DllImport("user32.dll", EntryPoint = "PostMessageA"

我想在窗口(背景)x/y坐标处模拟左键单击

我已经搜索并找到了很多东西来模拟鼠标点击到其他窗口,但它不能100%正常工作

我的代码:

private const int WM_LBUTTONDOWN = 0x201; //Left mousebutton down
private const int WM_LBUTTONUP = 0x202;   //Left mousebutton up

[DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)]
public static extern bool PostMessage(IntPtr hwnd, uint Msg, IntPtr wParam, IntPtr lParam);

public void SimulateMouseLeft(IntPtr hwnd, int x,int y)
{
    int coordinates = x | (y << 16);
    //PostMessage(hwnd, WM_LBUTTONDOWN, IntPtr.Zero, (IntPtr)coordinates);
    //PostMessage(hwnd, WM_LBUTTONUP, IntPtr.Zero, (IntPtr)coordinates);
    PostMessage(hwnd, WM_LBUTTONDOWN, (IntPtr)0x1, (IntPtr)coordinates);
    PostMessage(hwnd, WM_LBUTTONUP, (IntPtr)0x1, (IntPtr)coordinates);
    //send left button up
    //PostMessage(hwnd, 0x202, (IntPtr)0x1, (IntPtr)coordinates);
}  
private const int WM_LBUTTONDOWN=0x201//鼠标左键向下
私有常量int WM_LBUTTONUP=0x202//左鼠标按钮向上
[DllImport(“user32.dll”,EntryPoint=“PostMessageA”,SetLastError=true)]
公共静态外部bool PostMessage(IntPtr hwnd、uint Msg、IntPtr wParam、IntPtr lParam);
公共无效模拟使用左(IntPtr hwnd、int x、int y)
{

int coordinates=x |(y)我的水晶球说您没有意识到鼠标位置是在相对坐标中报告的。ScreenToClient()是必需的。可能是