I have an application which detects pressed keys on C# winform. The problem is on client side there are some other applications which also detects the pressed keys and suppresses them and because of that my App's form does not get the notification for the pressed key. I have used traditional form.KeyDown event to detect the key. How can I take higher precedence than the other application?
问题:
回答1:
If you're worried about other apps basically stealing your keystroke then you need to look into Global Hooks which is almost definitely how they other apps are stealing yours. You can roll your own code or use a wrapper library that someone else already wrote.
回答2:
You could be fighting a losing battle. Or at least an ever-escalating one. You've discovered that some other application is suppressing keystrokes. So you create a global hook so that you get the keystrokes first. But then that other application discovers that it's not first in line anymore, so it removes its own global hook and re-installs one in front of yours. You discover this and insert yourself in front of the list again . . .
It's a game of walls and ladders that nobody can win. So either deal with your application losing keystrokes or remove the offending application from the client machine.