进程间通信
我想知道我用 java 编写的应用程序是否可以监视其他第三方应用程序(例如编辑器、办公应用程序等)中的事件(例如单击文件菜单或编辑菜单)...
我的应用程序应该在它应该能够捕获和更改当前关注的应用程序的事件,这些应用程序可能不一定是 java 应用程序。
例如:如果用户单击文件 -->在 Microsoft Word 中另存为选项,那么我的应用程序应该能够接收这两个事件,并且还能够在任何时候自动执行这些事件 必要..
请帮忙
提前致谢
I wanted to know whether it is possible for my application written in java to monitor events(like click of file menu, or edit menu) in other third party applications such as in editors, office applications etc...
My application should run in the background and it should be able to capture and alter events of currently focused applications which may not be necessarily java applications.
For example: if a user clicks the file --> save as option in microsoft word then my application should be able to receive these two events and also be able to automate these events whenever
necessary..
Please help
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从来没有在 Java 中这样做过,但既然你正在处理 Win32,我至少可以建议本机部分。您正在寻找的是挂钩系统上的其他进程。为此,您必须编写一个本机 DLL。这是一种常见的技术,您可以轻松找到很多有关它的信息。一个好的起点是使用 Hooks 来自 MSDN。
一旦将 DLL 注入到系统中的所有其他进程中,您就必须弄清楚如何识别您真正感兴趣的进程。您将如何做到这一点取决于您实际想要执行的操作。要更好地了解不同操作发送的消息,您可以使用 Spy++。
最后,您必须在本机 DLL 和 Java 程序之间设置一些通信。这是我不熟悉的部分:您必须使用 JNI 。幸运的是,JNI 是一个涵盖广泛的主题,您可以在这个站点中找到很多建议。
I've never done this in Java, but since you're dealing with Win32, I can at least suggest the native part. What you're looking for is hooking other processes on your system. For that, you'll have to write a native DLL. It's a common technique, and you'll easily find a lot of information about it. A good starting point would be Using Hooks from MSDN.
Once you inject the DLL into all other processes in the system, you'll have to figure out how to identify the ones you're actually interested in. How would you do that depends on what you're actually trying to do. To get a better understanding of what messages are sent on different actions, you can use Spy++ that comes with VS.
Lastly, you have to setup some communication between your native DLL and your Java program. This is the part I'm not familiar with: you will have to use JNI. Luckily, JNI is a well covered topic, and you can find a lot of suggestions in this very site.