简体   繁体   English

将选定的文本复制到Swing Java应用程序?

[英]Copying selected text to a Swing Java app?

My goal is assign a global hotkey (JIntellitype, JXGrabKey) that would pass an arbitrary selected text to a java app. 我的目标是分配一个全局热键(JIntellitype,JXGrabKey),该键会将任意选定的文本传递给Java应用程序。

The initial plan is to utilize the java.awt.Robot to emulate Ctrl-C keypress and then get the value from clipboard. 最初的计划是利用java.awt.Robot模拟Ctrl-C按键,然后从剪贴板获取值。

Probably there's a more elegant solution? 也许有一个更优雅的解决方案?

EXAMPLE: Open Notepad, type in some text, select that text. 示例:打开记事本,键入一些文本,然后选择该文本。 Now, that text needs to be copied into a Java app. 现在,该文本需要复制到Java应用程序中。

I guess you want to implement a global input monitor, Java is not so straightforward to do the job. 我想您想实现一个全局输入监视器,Java并不是那么简单。 You may have to write an API hook and pack it in a DLL, then invoke it via JNI. 您可能必须编写一个API挂钩并将其打包在DLL中,然后通过JNI调用它。

我已经使用了机器人,并且效果很好。

The Robot only sends events inside your JVM. 机械手仅在JVM内部发送事件。 I don't know of anything to send events out to the operating system. 我不知道将事件发送到操作系统的任何信息。 Though there is plenty of examples out there of making JNI calls to the windows API, it would then be platform specific. 尽管有很多示例可以对Windows API进行JNI调用,但这将是特定于平台的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM