在Windows / Google Chrome /等中按Ctrl + C时如何触发事件 [英] How Do I Fire An Event When I Press Ctrl + C In Windows/Google Chrome/Etc

查看:159
本文介绍了在Windows / Google Chrome /等中按Ctrl + C时如何触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我已经尝试了几个小时来解决这个问题,但我似乎无法做到这一点......



我要开发一个在后台/系统托盘中使用最多的程序。



我需要在Windows中使用快捷方式/ CTRL-C时进行注册,即使在WPF程序中也是如此系统托盘而不是焦点。



我尝试使用全局快捷方式,但它似乎覆盖了Windows快捷方式,因此ctrl-c不再在程序之外工作: P $ / $


非常感谢你的时间。

Hello. I have been trying for a couple of hours to sort out this problem, but i am not capable of doing so it seems...

I am going to develop a program which is used most in the background / systemtray.

I need to register when a shortcut / CTRL-C is used in windows, even with the WPF program in the system tray and not in focus.

I have tried with Global Shortcuts but it seems to override the windows shortcut, so ctrl-c no longer works outside of the program :P

Thank you so much for your time.

推荐答案

不,你不需要使用Global Hooks;问题要简单得多,但解决方案可能需要使用P / Invoke。

这是您需要的Windows原始API: RegisterHotKey UnregisterHotKey

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx [ ^ ],

http:/ /msdn.microsoft.com/en-us/library/windows/desktop/ms646327(v=vs.85).aspx [ ^ ]。



顺便说一下,你不需要写P / Invoke部分;这已经在这里为您完成了:

http://www.pinvoke.net/ default.aspx / user32.registerhotkey [ ^ ],

http://www.pinvoke.net/default.aspx/ user32.unregisterhotkey [ ^ ]。







但是,起初,我没注意你提到的Ctrl + C,剪贴板复制事件。那么,您想要什么,捕获全局关键事件,或获得粘贴通知?在第二种情况下,为什么?







感谢您的澄清。



可能你需要剪贴板应用程序。 Windows曾经与ClipBook Viewer捆绑在一起,后者首次针对Windows for Workgroups推出,并在Windows Vista中停止使用( http:// en .wikipedia.org / wiki / ClipBook_Viewer [ ^ ] )。 [结束编辑]现在您可以将它作为第三方产品,即使使用源代码(因此您可以看到它是如何工作的)。例如,Google代码中的on: https://code.google.com/p/multiple-clipboards [ ^ ]。



另请参阅: http://bit.ly/1zOyHrj [ ^ ]。



-SA
No, you don't need to use the Global Hooks; the problem is much, much simpler, but solution may require using P/Invoke.
This is the Windows raw API you need: RegisterHotKey and UnregisterHotKey:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646327(v=vs.85).aspx[^].

By the way, you don't need to write P/Invoke part; this is already done for you here:
http://www.pinvoke.net/default.aspx/user32.registerhotkey[^],
http://www.pinvoke.net/default.aspx/user32.unregisterhotkey[^].



But, at first, I did not pay attention that you mentioned Ctrl+C, the clipboard copy event. So, what do you want, to capture global key event, or to get notified on paste? In second case, why?



Thank you for your clarification.

Probably you need the clipboard application. Windows used to be bundled with ClipBook Viewer which was first introduced for Windows for Workgroups and discontinued in Windows Vista (http://en.wikipedia.org/wiki/ClipBook_Viewer[^]). [END EDIT] Now you can have it as a 3rd-party product, even with source code (so you can see how it works). For example, the on on Google Code: https://code.google.com/p/multiple-clipboards[^].

See also: http://bit.ly/1zOyHrj[^].

—SA


据我所知,除了监视剪贴板和检测任何更改之外,无法在Windows中检测复制操作。 (并且要记住CTRL + INS也会导致复制到剪贴板)。



你可以通过全局钩子来完成它,但这并不容易:C#是一个糟糕的选择 - 你会发现它比C ++这样的母语更容易。



但是......有很多关于主题: Google:global keyboard hook site:codeproject.com [ ^ ]



祝你好运!
As far as I know there is no way to detect the copy operation in windows, other than to monitor the Clipboard and detect any changes. (and do remember that CTRL+INS will also cause a copy to clipboard).

You can probably do it via a global hook, but it won't be easy: C# is a poor choice - you would find it a lot easier in a native language such as C++.

But...there are a lot of articles on the subject: Google: "global keyboard hook site:codeproject.com"[^]

Good luck!


这篇关于在Windows / Google Chrome /等中按Ctrl + C时如何触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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