简体   繁体   English

C# 键盘按键检测优先级问题

[英]C# Keyboard Key detection precedence issue

I have an application which detects pressed keys on C# winform.我有一个应用程序可以检测 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.我使用传统的 form.KeyDown 事件来检测密钥。 How can I take higher precedence than the other application?我怎样才能获得比其他应用程序更高的优先级?

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.如果您担心其他应用程序基本上会窃取您的按键,那么您需要查看Global Hooks ,这几乎可以肯定其他应用程序窃取您的按键。 You can roll your own code or use a wrapper library that someone else already wrote.您可以滚动自己的代码或使用其他人已经编写的包装库

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.因此,要么处理您的应用程序丢失击键,要么从客户端计算机中删除有问题的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM