低级别鼠标钩子和DirectX鼠标、钩子、级别、DirectX

2023-09-03 01:58:17 作者:掌心里的海

我要建一个需要过滤一些鼠标点击系统级的应用程序。也就是说,我需要让系统忽略了一些鼠标键点击,在特殊的场合。

I'm building an application which needs to filter some mouse clicks system-wide. That is, I need to make the system ignore some mouse button clicks at special occasions.

我用低级鼠标钩子和 SetWindowsHookEx函数来过滤掉这些点击。它的工作原理比较出色,除了 WPF 应用程序。我想这是因为这些应用程序使用的DirectX 的DirectInput 输入处理,这就是为什么我不能滤除的点击在这些应用中,因为它们直接由驾驶员获得输入

I use low level mouse hook and SetWindowsHookEx to filter out these clicks. It works relatively well, except for WPF applications. I guess that's because these applications use DirectX and DirectInput for input processing, and that's why I can't filter out clicks in these applications, since they get the input directly from the driver.

有什么办法如何筛选中点击 WPF / 的DirectX 应用程序?

Is there any way how to filter clicks in WPF/DirectX applications?

我知道这是一般不会在全球范围过滤器点击好主意,但它是我的应用程序至关重要,我将确保它不会在游戏和其他程序过滤。但 WPF 应用已经普通的 GUI ,所以我需要在其中筛选点击为好。

I know it is generally not good idea to globally filter clicks, but it is crucial for my application, and I will make sure that it is not filtered in games and other programs. But WPF applications have ordinary GUI, so I need to filter clicks in them as well.

我想我可以写我自己的过滤驱动程序解决了这个问题,但因为我没有在编写驱动程序的经验,请让我知道,如果有任何其他的解决办法。

I guess I could solve this problem by writing my own filtering driver, but since I don't have any experience in writing drivers, please let me know if there is any other solution.

我发现关于API钩子一些有用的链接。使用此作为参考。

I've found some helpful links regarding API hooking. Use this as a reference.

挂钩的Windows API API钩子透露 API钩子透露第2部分 劫持的TextOut呼叫从记事本 疯codeHook IAT功能挂钩

Hooking Windows API API hooking revealed API hooking revealed Part 2 Hijack Textout Calls From Notepad madCodeHook IAT Function Hooking

WPF不使用DirectInput的,但标准的Win32消息输入处理(除手写笔,这是来源为我所有的问题,因为我用手写笔的发展,我不知道WPF应用程序是手写笔识别)。然而,对于在使用DirectInput的应用程序过滤的点击,一会要挂钩API,作为公认的答案解释说。

WPF does not use DirectInput, but standard Win32 messages for input handling (except for stylus, which is the source for all problems for me, because I use stylus for development, and I wasn't aware WPF apps are stylus-aware). However for filtering clicks in apps that use DirectInput, one would have to hook API, as the accepted answer explains.

推荐答案

您可以使用的方法称为API钩子 - 你覆盖特定调用库函数,并给他们自己的行为。有很多挂钩库在那里,可以简化这个任务,最常用的有: * 微软走弯路 * 疯狂codeHook * Deviare API钩子 * API劫持

You could use a method called API hooking - you override specific calls to library functions and give them your own behavior. There are many hooking libraries out there that simplify this task, the most used ones are: * Microsoft Detours * MadCodeHook * Deviare API Hook * API Hijack

另请参阅挂钩的Direct3D 的维基百科的例子。 你只需要插入您的挂钩库到系统中的每一个过程,但是从你的问题来看我假设你已经实现了。

Also see Wikipedia example of hooking Direct3D. You just need to insert your hooking library into each process in the system but judging from your question I assume you've already achieved that.