如何在 .NET 中重复单击鼠标

发布于 2024-07-29 22:20:12 字数 319 浏览 2 评论 0原文

我的应用程序作为另一个窗口应用程序中的插件运行。 因此,我的窗口经常没有焦点。 现在,如果有人将鼠标移到按钮/菜单上并单击一次,它所做的就是将焦点设置到我的窗口。 然后他(她)需要再次单击才能获得实际的按钮功能。

这是一个小烦恼,但我想摆脱它。 首先,我尝试在鼠标进入对话框空间时声明焦点,但这被证明更烦人。 所以我想做的是重复鼠标单击,这样看起来就好像一次单击既改变了焦点又按下了按钮。

显然,我应该只在单击导致 SetFocus 时执行此操作,否则它将运行按钮功能两次。

有什么建议么?

深深地、永远地亏欠, 大卫

My app runs as a plugin inside another windowed app. Thus, my window often doesn't have the focus. Now, if someone moves the mouse over a button/menu and clicks once, all it does is set focus to my window. Then (s)he needs to click again to get the actual button functionality.

This is a minor annoyance but I'd like to get rid of it. First I tried claiming focus whenever the mouse enters my dialog space, but this proved to be even more annoying. So what I'd like to do is repeat the mouse click, so it looks as though a single click both changed focus AND pressed the button.

Obviously I should ONLY do this when the click resulted into a SetFocus, otherwise it will run the button function twice.

Any suggestions?

Deeply and eternally indebted,
David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漆黑的白昼 2024-08-05 22:20:14

我建议你保持原有的行为; 这是操作系统的标准行为,更改它可能会违反标准的可用性准则。

I would suggest that you keep the behavior as is; this is standard behavior for the operating system and changing it could break standard usability guidelines.

向日葵 2024-08-05 22:20:14

鼠标点击模拟在这里似乎有点混乱,但您始终可以通过 SendInput API 通过 P/Invoke:

[DllImport("user32.dll", SetLastError=true)]
static extern uint SendInput(uint nInputs, INPUT [] pInputs, int cbSize);

您还可以直接摆弄传播/生成 WM_MOUSEXXXXX 消息,但我已经玩过很多次了,相信我,当我说这完全是一个拼凑的东西时。

Mouse click simulation seems a little messy here, but you can always simulate any mouse click at any (X,Y) via the SendInput API through P/Invoke:

[DllImport("user32.dll", SetLastError=true)]
static extern uint SendInput(uint nInputs, INPUT [] pInputs, int cbSize);

You can also fiddle around with propagating/generating WM_MOUSEXXXXX messages directly but I've played with this a lot and believe me when I say it's a total kludge.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文