如何在Windows中捕获粘贴事件? [英] How to capture the paste event in windows?

查看:677
本文介绍了如何在Windows中捕获粘贴事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在做一个研究项目,我使用Windows API来检测剪贴板中的变化。我重写了 WndProc ,到目前为止它工作正常,我可以检测到复制事件发生的时间。但现在的问题是如何检测粘贴事件。 WM_PASTE消息在所有方案中都不起作用。我的想法是:



全局挂钩Ctrl + v,Ctrl + Shift + v

挂钩shell上下文菜单并检测用户何时点击粘贴

挂钩应用程序编辑>粘贴



由于不同的应用程序可以以不同的方式实现此粘贴功能,因此这是一项非常繁琐的任务,我认为这不是最好的方法。我想对此有一些建议。



我尝试过:



我试图挂钩Ctrl + v注册表热键,它工作正常。但正如 中所述



Hi,

I am doing a research project and I use Windows API to detect changes in the clipboard. I override the WndProc and so far it works fine and I can detect whenever copy event is happening. But now the problem is how to detect paste event. WM_PASTE message doesn't work in all the scenarios. What I think to do is :

Global hook Ctrl + v , Ctrl + Shift + v
Hook shell context menu and detect when user clicks on paste
Hook application Edit > Paste

Since different applications can implement this paste function in different ways it is a very tedious task and I don't think that is the best way to do it. I would like to have some suggestions about this.

What I have tried:

I have tried to hook Ctrl + v registry hot key and it works fine. But as stated in here

引用:

钩子往往会减慢系统速度,因为它们增加了系统的处理量必须为每条消息执行。你应该只在必要时安装一个钩子,并尽快将其删除。

Hooks tend to slow down the system because they increase the amount of processing the system must perform for each message. You should install a hook only when necessary, and remove it as soon as possible.





但是,在我的应用程序中,我想要监视是否有任何粘贴事件正在发生。



But, In my application continuously I want to monitor is there any paste event is happening or not.

推荐答案

没有订阅全局粘贴事件这样的东西。



你的建议是关于你要做的最好的方法。



另外,钩子不会让系统慢下来完全取决于你的钩子代码。只是不要对每个按键进行大量的处理,你会没事的。
There is no such thing as a "global paste event" to subscribe to.

What you suggested is about the best way you're going to do this.

Also, hooks don't slow the system down very much at all, but that depends entirely on your hook code. Just don't do a ton of processing on every key stroke and you'll be fine.


正如Dave所说,没有这样的事件,WM_PASTE是一个指令而不是通知和应用程序甚至不必等待用户输入才能粘贴 - 在.NET中有一个Clipboard对象允许应用程序直接操作剪贴板内容,因此无论您如何操作,都将无法检测所有粘贴操作。



您的键盘操作列表也不完整:SHIFT + INSERT将粘贴到大多数应用程序中;但我知道有几个使用CTRL + V进行非粘贴操作的应用程序。
As Dave says, there is no such event, WM_PASTE is an instruction not a notification and applications do not even have to wait for user input in order to paste - there is a Clipboard object in .NET which allows applications to directly manipulate the clipboard content, so you will never be able to detect all paste operations regardless of how you do it.

And your keyboard operation list is incomplete as well: SHIFT+INSERT will paste in most applications; but I know of a couple of apps that use CTRL+V for non-paste operations.


这篇关于如何在Windows中捕获粘贴事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆