简体   繁体   English

在特定位置模拟鼠标按下,而不关注我定位的窗口

[英]Emulating mouse press at certain location, without focus on windows I target

I think title of this question is pretty clear. 我认为这个问题的标题很清楚。

        const int WM_KEYDOWN = 0x100;
        const int WM_KEYUP = 0x101;
        const int WM_SYSCOMMAND = 0x018;
        const int SC_CLOSE = 0x053;
        const int WM_MOUSEMOVE = 0x200;
        int WindowToFind = FindWindow(null, "Untitled - Paint");
        PostMessage(WindowToFind, WM_MOUSEMOVE, 400, 500);
        PostMessage(WindowToFind, WM_KEYDOWN, ((int)Keys.LButton), 0);
        PostMessage(WindowToFind, WM_KEYUP, ((int)Keys.LButton), 0);

above, is current code. 以上是当前代码。 which does NOT work.(however postmessage DOES post actual keys like if I want to press A, it does that. However it fails on mouse, or I fail) 这是行不通的。(但是postmessage确实会发布实际的按键,例如我想按A的那样,但是确实如此。但是鼠标失败,或者我失败了)

I also must point out that I dont even know what does lparam actually, I just used to set it to null and wparam to key. 我还必须指出,我什至不知道lparam实际上是什么,我只是将其设置为null而将wparam设置为key。 Im not even sure if im supposed to use wm_mousemove because it looks like its to "receive" rather than actually setting location. 我什至不确定我是否应该使用wm_mousemove,因为它看起来像是在“接收”而不是实际设置位置。 Then I read Lparam should be set to contain both x and y like 500 * 0x10000 + 500, and wparam as 0 etc., it didnt help. 然后我读到Lparam应该设置为同时包含x和y,如500 * 0x10000 + 500,而wparam为0等,这没有帮助。 Googling for other ways didnt help either. 谷歌搜索其他方式也没有帮助。 I really dont care about ways, I just want to press leftmouse, on another window without focus, on certain location. 我真的不在乎方法, 我只想在没有焦点的另一个窗口上按鼠标左键的某个位置。

Perhaps you're looking for SendInput ( P/Invoke ) 也许您正在寻找SendInputP / Invoke

The sample code at P/Invoke also shows how you can use FindWindow and SetForegroundWindow if you want to programatically give another window focus (unsure if that's what you are trying to accomplish). P / Invoke上的示例代码还显示了如果要以编程方式赋予另一个窗口焦点(不确定这是否是您要实现的目标),则如何使用FindWindowSetForegroundWindow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅当我用鼠标按下按钮时,Windows窗体才会执行 - Windows form only executs when I press the buttons with the mouse 如何在不添加焦点的情况下捕获Windows窗体应用程序中的按键事件? - How to capture key press events in Windows Form application without adding focus? 在Windows 8 Metro应用程序中禁用鼠标移过焦点 - Disable Mouse Over focus in Windows 8 Metro Application c#移动鼠标没有焦点就无法工作 - c# moving mouse not working without focus 从代码更改“当我按下Ctrl键时显示指针的位置” Windows设置 - Change 'Show location of pointer when I press the Ctrl key' Windows setting from code 通过窗口(或手柄)共享鼠标单击和按键事件 - sharing mouse click and key press events through windows (or handles) Windows 10中的Monogame鼠标仅在移动后才感觉按下 - Monogame mouse in windows 10 feels press only after move C#模拟按键,而无需将鼠标移到Forms Webbrowser - C# simulate key press without moving the mouse to Forms Webbrowser 在Windows 2012中聚焦后的C#鼠标单击事件 - C# mouse click event after focus in windows 2012 如何在Windows 10应用程序中将图像聚焦中心设置为鼠标位置? - how to set the image focus center to mouse position in windows 10 apps?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM