键盘敲击事件

发布于 2024-08-02 13:18:51 字数 269 浏览 1 评论 0原文

我想要做的是有一个后台应用程序,它本身或其模块仅在按下某个键时运行。就像当我按 F10 时,我编写的一些代码会执行,然后退出或进入睡眠状态,然后当我按 F10 时,我再次执行并进入睡眠状态,但在击键之间,它不会占用任何处理器时间。我该怎么做

例如,一个执行其语句的线程,然后

thread.Sleep( "till i press F10" );

这是一个虚构的函数。来自现实世界的任何帮助:)

C# + Winforms

what i want to do is have a background application which by itself or its modules run only when a certain key is pressed. Like when i press F10 some code that i have written executes and then quits or goes to sleep then again when i press F10 i executes again and goes to sleep but in between keystrokes it does not takes any processor time. How can i do it

For example a thread that executes its statements and then

thread.Sleep( "till i press F10" );

well this is an imaginary function. Any help from the real world :)

C# + Winforms

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

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

发布评论

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

评论(2

白云悠悠 2024-08-09 13:18:51

最简单的可能是 SetWindowsHookExWH_KEYBOARDWH_KEYBOARD_LL 挂钩类型。从 C# 调用它可能有点令人讨厌,但这是可能的。

Simplest is probably SetWindowsHookEx with the WH_KEYBOARD or WH_KEYBOARD_LL hook type. Calling it from C# may be a bit obnoxious, but it's possible.

幼儿园老大 2024-08-09 13:18:51

你为什么不尝试 console.ReadKey ,它会读取密钥并立即执行一些操作 n 一旦任务完成你调用 thread.Sleep()

why dont you try console.ReadKey which will read the key and immediately perform some operation n as soon as task gets finished u call thread.Sleep()

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