标题:按下F1键之后自动执行下面robot类代码的模拟按键操作,按一次就执行一次,再 ...
只看楼主
MyHuier
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-10-24
 问题点数:0 回复次数:0 
按下F1键之后自动执行下面robot类代码的模拟按键操作,按一次就执行一次,再按再执行一次。
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);
    }
}
搜索更多相关主题的帖子: public import robot 
2016-10-24 17:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-470205-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044406 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved