这个开销比较大吧,要加一个timer,里面放上按键的事件应该就可以了

解决方案 »

  1.   

    还是给你上代码吧,我测试了下,可以的,你自己再详细改下class Tt {    public static void main(String args[]) {
            Timer tim = new Timer();
           tim.schedule(new MyTimer(), 1000,2000);
        }
    }
    class MyTimer extends TimerTask{
        public void run(){
            System.out.println("2秒一次");
            try {
                new Robot().keyPress(KeyEvent.VK_ALT);
                new Robot().keyPress(KeyEvent.VK_TAB);
            } catch (AWTException ex) {
                Logger.getLogger(MyTimer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }