[英]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 ) 也许您正在寻找SendInput ( P / 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上的示例代码还显示了如果要以编程方式赋予另一个窗口焦点(不确定这是否是您要实现的目标),则如何使用FindWindow和SetForegroundWindow 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.