键盘敲击事件
我想要做的是有一个后台应用程序,它本身或其模块仅在按下某个键时运行。就像当我按 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的可能是 SetWindowsHookEx 与
WH_KEYBOARD
或WH_KEYBOARD_LL
挂钩类型。从 C# 调用它可能有点令人讨厌,但这是可能的。Simplest is probably SetWindowsHookEx with the
WH_KEYBOARD
orWH_KEYBOARD_LL
hook type. Calling it from C# may be a bit obnoxious, but it's possible.你为什么不尝试 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()