Capture key events from a Windows Service in C#

后端 未结 3 2120
时光取名叫无心
时光取名叫无心 2021-01-22 04:22

I have to write an application in C# that listens to any keys being pressed. In actuality I have a bar code scanner sending the \"key pressed\" event, and I need to listen it..

3条回答
  •  自闭症患者
    2021-01-22 05:01

    If you need to see keyboard presses for all apps, system-wide Hooks would be the way to go normally, but the problem is that the security changes in Vista and above make hooks rather less useful. A process cannot hook another process at a higher integrity level, so there's no guarantee you will see all events.

    However if you only need to see events going to a particular app - the one reading the bar codes - then provided you can identify that process, a thread-specific hook will suffice and the integrity question will not arise.

提交回复
热议问题