Java粘贴到当前光标位置 [英] Java paste to current cursor position

查看:106
本文介绍了Java粘贴到当前光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个简单的Java程序,它将一些文本插入当前光标位置。该光标位置可以在任何文本编辑器中,例如记事本。

解决方案

这是一个hack,但请查看java.awt.Robot。它使您可以编程方式进行鼠标单击和按键操作,以及其他许多有用的操作。因此,一种方法是:


  1. 使用Atmocreations的文章将文本放在剪贴板中

  2. 要粘贴时,请使用Robot单击当前位置(如果需要使该字段成为焦点)

  3. 使用Robot按下Ctrl-V(或任何系统)

就像我说的那样,它根本不是一个干净的解决方案,但会在一定程度上起作用。 p>

I want to make simple java program that will insert some text into current cursor position. That cursor position can be in any text editor, for example notepad. Is this possible?

解决方案

It's a hack, but look into java.awt.Robot. It lets you programmatically make mouse clicks and key presses, among lots of other useful things. So one way to do it would be:

  1. Use Atmocreations' article to put text in the clipboard
  2. When you want to paste it, use Robot to click at the current position (if you need to give that field focus)
  3. Use Robot to press Ctrl-V (or whatever your system expects for a paste)

Like I said, it's not at all a clean solution, but it will work in a pinch.

这篇关于Java粘贴到当前光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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