Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想让我的程序在单击鼠标按钮后工作,但不一定在某种 Jframe 上。例如,我希望我的程序在 Windows 媒体播放器上单击 PLAY 按钮后开始工作。
有没有办法做到这一点?
是的,但不是在标准 Java 中。您想在操作系统中而不是在 Java GUI 中侦听 Java 无法自行完成的事件。这可以工作,但为了让 Java 与操作系统紧密交互,您需要使用 Java Native Interface (JNI) 和 C/C++ 代码或 Java Native Access (JNA)(在我的观点)。我还在 Windows 中使用 AutoIt 等 Windows 脚本语言完成了类似的工作,然后通过套接字或通过标准输入和输出将其连接到 Java 应用程序。
Java 本机接口 Java 本机访问 AutoIt Windows 脚本语言