How can I capture a key press, outside of the form?

为君一笑 提交于 2019-12-11 02:10:43

问题


I have been trying to capture the keys pressed outside of my winform, but obviously a KeyPress event won't work.

I haven't been able to get any closer than the KeyPress event, which only works on the form level, as specified

I suspect that I will have to do the

[DllImportAttribute("user32.dll")]

, but I have little to no experience with that.


回答1:


Being able to capture key presses anywhere requires using Hooks.

There is a library on CodePlex which simplifies implementing Application and Global Mouse and Keyboard Hooks for C# users.



来源:https://stackoverflow.com/questions/19171081/how-can-i-capture-a-key-press-outside-of-the-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!