c# - 检测整个系统何时发生粘贴事件

标签 c# windows

我需要检测何时有人在整个系统中粘贴了一些东西。例如在记事本或 word 中不仅在 C# 应用程序中。我找到的示例仅描述了一些 WinForms 应用程序。

当我能够检测到该事件时,我想修改粘贴的值。

谢谢

最佳答案

要实现您的要求,您必须将您的应用程序注入(inject)系统上运行的所有其他窗口。该过程称为 Hook 。

摘自 How to set a Windows hook in Visual C# .NET

.NET Framework 不支持全局 Hook

Except for the WH_KEYBOARD_LL low-level hook and the WH_MOUSE_LL low-level hook, you cannot implement global hooks in the Microsoft .NET Framework. To install a global hook, a hook must have a native DLL export to inject itself in another process that requires a valid, consistent function to call into. This behavior requires a DLL export. The .NET Framework does not support DLL exports. Managed code has no concept of a consistent value for a function pointer because these function pointers are proxies that are built dynamically. Low-level hook procedures are called on the thread that installed the hook. Low-level hooks do not require that the hook procedure be implemented in a DLL.

什么是 Hooks :

A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure.

关于c# - 检测整个系统何时发生粘贴事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29546344/

相关文章:

c# - 如何在 C# 中增加控制台窗口的大小?

Python - Jupyter 无法识别 Unix 命令

windows - Zig 的文件系统示例不适用于 Windows

c# - 如何检测是否安装了 Microsoft Edge?

c++ - C/C++ iTunes API 在哪里? (不是 COM!)

c# - 在 Azure 辅助角色中使用 Lucene.NET 引发未处理的异常

c# - 静态方法的含义

c# - 单击时如何使命令不禁用按钮

c# - 您能否在迭代期间在 LINQ 语句中实时设置/更新值?

c# - FileNotFoundException 从 Windows 应用商店应用程序的 Assets 文件夹中读取 JSON 文件