Delphi中如何判断哪个设备触发了特定事件?

发布于 2024-12-29 06:46:41 字数 489 浏览 4 评论 0原文

我想知道是否有一种简单的方法来判断哪个输入设备触发了特定的 GUI 事件。

例如:TButton.OnClick 事件被触发。用户是否通过按下键盘(快捷键、默认按钮的 Enter 键、聚焦按钮的 space 键等)触发它,还是通过鼠标单击触发?有什么简单的方法可以辨别吗?

我想知道的原因是,当用户使用鼠标启动也可以使用键盘完成的操作时,我可以在我们的一些应用程序中实现键盘使用提示。我们车间的系统处于相当多灰尘/肮脏的环境中,老鼠在其中往往无法很好地承受。而且,在许多情况下,根本没有足够的空间来使用鼠标。 (不,没有数字小键盘的键盘不是解决方案。它们被过度依赖。)

但是,由于我们的应用程序在 Windows 中运行,用户倾向于像在家里一样使用鼠标来使用程序。这并没有什么特别的问题,但我们努力优化输入工作流程,使其对键盘也友好。如果有一种影响较小的方式向我们的用户表明他们有一种方法可以做他们正在做的事情而无需抓住鼠标,那就太好了。

I'm wondering if there's an easy way to tell which input device triggered a particular GUI event.

For example: A TButton.OnClick event gets fired. Did the user trigger it with a keyboard press (shortcut, Enter key for default button, space key for a focused button, etc.) or was it triggered with a mouse click? Is there any easy way to tell?

The reason I'd like to know is so that I can implement keyboard usage hints into some of our applications when the user uses the mouse to initiate actions that could also be done with the keyboard. Our systems on the shop floor are in pretty dusty/dirty environments, and mice tend to not hold up so well in them. Also, in many cases, there's simply not that much room for a mouse to be used. (No, keyboards without numeric keypads is not a solution. They're relied on too heavily.)

However, since our apps run in Windows, users tend to simply use the programs like they would at home -- with a mouse. There's nothing particularly wrong with that, but we've worked hard to optimize the input workflow to be keyboard friendly as well. It'd be nice if there was a low-impact way to indicate to our users that there's a way for them to do the things they're doing without having to grab the mouse.

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

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

发布评论

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

评论(1

没有伤那来痛 2025-01-05 06:46:42

无法从 OnClick 内部进行判断。但是,您也可以将事件附加到当鼠标滑过该控件时将触发的事件,这可能更适合您尝试执行的操作。看一下 OnMouseEnterOnMouseLeave 事件。另外,如果您确实希望单击鼠标时发生特定的操作,可以将其附加到 OnMouseUp

There's no way to tell from within OnClick. However, you can also attach events to a control that will fire when the mouse rolls over it, which would probably be more appropriate for what you're trying to do anyway. Take a look at the OnMouseEnter and OnMouseLeave events. Also, if you really want something specific to happen when the mouse is clicked, you can attach it to OnMouseUp.

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