将鼠标事件发送到另一个窗口,Win 7下的C#
有没有办法将鼠标事件发送到 Window 7 中的另一个窗口?
我曾经这样做过:
<代码> [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] 公共静态外部无效mouse_event(长dwFlags,长dx,长dy,长cButtons,长dwExtraInfo);
但这在 Win7 中似乎不再起作用了。
有什么想法吗?
谢谢。
Is there a way to send mouse events to another window in Window 7 ?
I used to do this :
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
But this does not seem to work anymore in Win7.
Any ideas ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不工作怎么办?
可能相关的一件事(这很难,因为您提供的细节太少)是不允许非提升的(在 UAC 下)应用程序与提升的应用程序进行通信。因此,如果一个应用程序被提升而另一个应用程序没有提升,您会说它“似乎不起作用”。但您无法通过更改您使用的 API 来解决这个问题。
Not work how?
One thing that might be relevant (it's hard because you've given so little detail) is that non-elevated (under UAC) apps are not allowed to communicate with elevated ones. So if one app is elevated and one not, you would say it "doesn't seem to work". But you can't fix that by changing the API you use.
这对您不起作用的最可能原因是您使用的 P/Invoke 签名不正确。您已将参数指定为
long
,它在 .NET 中表示 64 位整数。 Win32 API 声明 的参数定义为DWORD,表示32位整数,这会导致堆栈不平衡。将您的签名更改为以下内容,您应该会有更好的运气。另外,您应该考虑凯特的观点,一旦签名修复,这也可能会对您的结果产生影响。
The most likely reason that this is not working for you is the fact that the P/Invoke signature that you are using is incorrect. You have specified the arguments as
long
which in .NET represents a 64bit integer. The Win32 API decleration has the arguments defined as DWORD, which represents 32 bit integers, this will result in a stack imbalance. Change your signature to the following and you should have better luck.Also, you should consider Kate's point and this might also have a bearing on your results once the signature is fixed.
user32.dll 中的 SendMessage:就可以了。
您可能还需要 FindWindow 和 WM 常量。
pinvoke.net 非常适合此类内容。
SendMessage in user32.dll: would do the trick.
You'll also probably need FindWindow and the WM constants.
pinvoke.net is good for this sort of stuff.