以编程方式模拟用户输入的简单方法是什么?
我有一个由于错误情况而弹出的对话框。我希望对话框保持打开状态至少 30 秒,并在收到最后一次用户输入(鼠标或键盘)后关闭 30 秒。
我可以通过检查 GetLastInputInfo 返回的值并在超过 30 秒前关闭对话框来实现此目的,但如果在用户 30 秒内没有使用鼠标或键盘时弹出对话框,则 GetLastInputInfo 测试通过立即,对话框立即再次关闭。我可以使用另一个计时器来完成此操作,但我认为在对话框打开之前模拟鼠标移动一点或发出(无害的)按键会更简单。它还可能具有将系统踢出屏幕保护程序的优点。
实现此目的最简单的 1 行 Delphi 代码片段是什么?
I have a dialog that pops up as result of an error condition. I want the dialog to remain open for at least 30 seconds, and close 30 seconds after the last user input (mouse or keyboard) is received.
I can implement this by checking the value returned by GetLastInputInfo and closing the dialog when this is more than 30 seconds ago, but if the dialog pops up when the user hasn't been at the mouse or keyboard for 30 seconds, the GetLastInputInfo test passes immediately, and the dialog closes again immediately. I could do this with another timer, but I figure it would be much simpler to simulate the mouse being moved a bit, or issuing a (harmless) keypress, just before the dialog opens. It would also have the advantage presumably of kicking the system out of screensaver.
What's the simplest 1-line Delphi code fragment to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的是使用 < code>keybd_event 函数(一行代码)
也可以使用
SendInput
< /a> 功能,但需要多行:)the most simple is using the
keybd_event
function (one line of code)Also you can use the
SendInput
function but requires more than one line :)使用 keybd_event 输入多个字节字符:
Input multiple byte characters with keybd_event:
https://github.com/WladiD/SendInputHelper 作者:Waldemar Derr 先生。
简单和通用,选择2。
例子:
https://github.com/WladiD/SendInputHelper by Mr. Waldemar Derr.
Simple and versatile, choose 2.
Example: