java当我按下F1键时怎么让它自动执行robot类的模拟按键操作,不是在控制台。像按键精灵启动键,求代码!
importjava.awt.Robot;importjava.awt.event.KeyEvent;importjava.awt.event.KeyListener;i...
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JTextField;
public class jf {
static JTextField a = new JTextField();
public static <keypoint> void main(String arg[]) throws Exception {
// ts.addKeyListener(new KeyAdapter() {
a.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
while (true) {
if (e.getKeyCode() == KeyEvent.VK_F1) {
break;
//当我在桌面任何一个地方按下F1键之后自动执行下面robot类代码的模拟按键操作,按一次就执行一次,再按再执行一次。
}
}
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
});
Robot r = new Robot();
r.delay(3000);
for (int i = 1; i <= 6; i++) {
r.keyPress(KeyEvent.VK_UP);
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_C);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_V);
r.keyPress(KeyEvent.VK_RIGHT);
}
r.keyPress(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_HOME);
}
}
能详细,有具体代码实现,还能提高悬赏! 展开
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JTextField;
public class jf {
static JTextField a = new JTextField();
public static <keypoint> void main(String arg[]) throws Exception {
// ts.addKeyListener(new KeyAdapter() {
a.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
while (true) {
if (e.getKeyCode() == KeyEvent.VK_F1) {
break;
//当我在桌面任何一个地方按下F1键之后自动执行下面robot类代码的模拟按键操作,按一次就执行一次,再按再执行一次。
}
}
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
});
Robot r = new Robot();
r.delay(3000);
for (int i = 1; i <= 6; i++) {
r.keyPress(KeyEvent.VK_UP);
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_C);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_V);
r.keyPress(KeyEvent.VK_RIGHT);
}
r.keyPress(KeyEvent.VK_DOWN);
r.keyPress(KeyEvent.VK_HOME);
}
}
能详细,有具体代码实现,还能提高悬赏! 展开
3个回答
展开全部
你这个功能我做过,需要让java在windows中注册一个全局的热键监听,默认的java热键只有在打开java主界面时才生效,需要引入第三方的叫jintellitype的东西,同时将一个dll文件复制到你的system32下,然后自己注册热键定义,才能捕获非焦点状态下的热键,http://www.cnblogs.com/jebysun/p/3969363.html,具体的jintellitype的使用你自己搜吧,有挺多的,也挺简单
追问
我私信聊你了!求代码。新手
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询