1、我想做个跟“按键精灵”一样的java程序,我如何把一个字符串的内容输出到屏幕上网页中的文本框中?也就是,根据鼠标的位置,把内容输出到鼠标指定的文本框中或者其他地方???
2、我把菜单项的某项设置了快捷键,只有当前窗口为焦点的时候,快捷键才响应,我如何在后台响应该菜单项????谢谢

解决方案 »

  1.   

    1用JS设置一个鼠标事件。
    这两个用到JS的话是不难的。
      

  2.   

    我从下面的帖子中获得了如何响应全局快捷键的功能
    http://topic.csdn.net/u/20080620/10/b7db8687-8dca-488f-9e38-c923c507c53e.html我是用eclipse编写的程序,在工作空间workspace中,把jintellitype文件夹放在workspace目录下,jintellitype文件夹存放了jintellitype-1.3.1.jar和JIntellitype.dll两个文件,然后我的程序在workspace目录下的Automatism\src文件夹内,在eclipse中,点击项目右键——属性——Java构建路径——库——添加外部jar——添加jintellitype-1.3.1.jar后,稍作整理,开始编译Automatism项目,可为什么出错啊????Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at com.melloware.jintellitype.JIntellitype.<clinit>(JIntellitype.java:57)
    at Auto.initHotkey(Auto.java:105)
    at Auto.main(Auto.java:119)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 3 more
    错误点就在:
     void initHotkey() {   
            //参数KEY_1表示改组热键组合的标识,第二个参数表示组合键,如果没有则为0,该热键对应ctrl+alt+I   
            JIntellitype.getInstance().registerHotKey(KEY_1, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'I');   
            JIntellitype.getInstance().registerHotKey(KEY_2, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'O');   
            JIntellitype.getInstance().registerHotKey(KEY_3, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'X');   
      
            JIntellitype.getInstance().addHotKeyListener(this);   
        }   
    哪位高手能帮我解决下啊,另外,JIntellitype.dll文件我放哪儿,是放在jintellitype文件夹,还是放在Automatism\src,还是放在Automatism\bin内?????????????
      

  3.   

    请帮我把代码添加一个全局快捷键功能,不受焦点限制,程序最小化也能后响应,类似QQ的CTRL+ALT+Z一样,当我按下CTRL+ALT+Q的时候,调用stopPlay()方法,谢谢
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    import com.melloware.jintellitype.HotkeyListener;   
    import com.melloware.jintellitype.JIntellitype; 
    public class Auto extends JFrame implements HotkeyListener {
    private static final long serialVersionUID = 1268832569328261240L;
    static final int KEY_1 = 88;   
        static final int KEY_2 = 89;   
        static final int KEY_3 = 90;  
    private Thread thread;
    private static boolean play=false; private JMenuBar bar = new JMenuBar();
    private JMenu mC=new JMenu(" 控制 ");
    private JMenuItem mPrint = new JMenuItem("输出"),
               mStop=new JMenuItem("停止");
        Auto(){
       
         setSize(300,200);
         setMinimumSize(new Dimension(300,200));
         bar.add(mC);
    setJMenuBar(bar);
    mC.add(mPrint);
    mC.add(mStop);
    setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - getSize().width) / 2,
                   (Toolkit.getDefaultToolkit().getScreenSize().height - getSize().height) / 2);
    mPrint.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){ }
    }); mStop.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    stopPlay();
    }
    });
    addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent we) {
             System.exit(0);
             }
            });

    mStop.setAccelerator(KeyStroke.getKeyStroke(
                    KeyEvent.VK_Q,KeyEvent.CTRL_MASK));

    setResizable(false);
    setVisible(true);
    }
        public static boolean isPlay(){
         return play;
        }
        public void stopPlay(){
         System.out.println("按下了CTRL+Q");
         play=false;
    if(thread!=null)
    while(!thread.isInterrupted())
    thread.interrupt();
        }
        
        
        
        
        public void onHotKey(int key){   
            switch (key) {   
                case KEY_1:   
                    System.out.println("ctrl+alt+I 按下.........");   
                    break;   
                case KEY_2:   
                    System.out.println("ctrl+alt+O 按下.........");   
                    break;   
                case KEY_3:   
                    System.out.println("系统退出..........");   
                    destroy();   
            }   
      
        }  
        /** *//**  
         * 解除注册并退出  
         */  
        void destroy(){   
            JIntellitype.getInstance().unregisterHotKey(KEY_1);   
            JIntellitype.getInstance().unregisterHotKey(KEY_2);   
            JIntellitype.getInstance().unregisterHotKey(KEY_3);   
            System.exit(0);   
        }   
      
        /** *//**  
         * 初始化热键并注册监听事件  
         */  
        void initHotkey() {   
            //参数KEY_1表示改组热键组合的标识,第二个参数表示组合键,如果没有则为0,该热键对应ctrl+alt+I   
            JIntellitype.getInstance().registerHotKey(KEY_1, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'I');   
            JIntellitype.getInstance().registerHotKey(KEY_2, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'O');   
            JIntellitype.getInstance().registerHotKey(KEY_3, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'X');   
      
            JIntellitype.getInstance().addHotKeyListener(this);   
        }   
      
     
        
      public static void main(String[] args) {
           Auto auto=new Auto();  
           auto.initHotkey();
          while (true) {   
                try {   
                    Thread.sleep(10000);   
                } catch (Exception ex) {   
                    break;   
                }   
            }   
        }   
    }
      

  4.   

    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    import com.melloware.jintellitype.HotkeyListener;   
    import com.melloware.jintellitype.JIntellitype; 
    public class Auto extends JFrame implements HotkeyListener {
        private static final long serialVersionUID = 1268832569328261240L;
        static final int KEY_1 = 88;   
        static final int KEY_2 = 89;   
        static final int KEY_3 = 90;  
        private Thread thread;
        private static boolean play=false;    private JMenuBar bar = new JMenuBar();
        private JMenu mC=new JMenu(" 控制 ");
        private JMenuItem mPrint = new JMenuItem("输出"),
                           mStop=new JMenuItem("停止");
        Auto(){
       
            setSize(300,200);
            setMinimumSize(new Dimension(300,200));
            bar.add(mC);
            setJMenuBar(bar);
            mC.add(mPrint);
            mC.add(mStop);
            setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - getSize().width) / 2,
                       (Toolkit.getDefaultToolkit().getScreenSize().height - getSize().height) / 2);
            mPrint.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){            }
            });        mStop.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    stopPlay();
                }
            });
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    System.exit(0);
                }
            });    
            
            mStop.setAccelerator(KeyStroke.getKeyStroke(
                    KeyEvent.VK_Q,KeyEvent.CTRL_MASK));
            
            setResizable(false);
            setVisible(true);
        }
        public static boolean isPlay(){
            return play;
        }
        public void stopPlay(){
            System.out.println("按下了CTRL+Q");
            play=false;
            if(thread!=null)
                while(!thread.isInterrupted())
                    thread.interrupt();
        }
        
        
        
        
        public void onHotKey(int key){   
            switch (key) {   
                case KEY_1:   
                    System.out.println("ctrl+alt+I 按下.........");   
                    break;   
                case KEY_2:   
                    System.out.println("ctrl+alt+O 按下.........");   
                    break;   
                case KEY_3:   
                    System.out.println("系统退出..........");   
                    destroy();   
            }   
      
        }  
        /** *//**  
         * 解除注册并退出  
         */  
        void destroy(){   
            JIntellitype.getInstance().unregisterHotKey(KEY_1);   
            JIntellitype.getInstance().unregisterHotKey(KEY_2);   
            JIntellitype.getInstance().unregisterHotKey(KEY_3);   
            System.exit(0);   
        }   
      
        /** *//**  
         * 初始化热键并注册监听事件  
         */  
        void initHotkey() {   
            //参数KEY_1表示改组热键组合的标识,第二个参数表示组合键,如果没有则为0,该热键对应ctrl+alt+I   
            JIntellitype.getInstance().registerHotKey(KEY_1, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'I');   
            JIntellitype.getInstance().registerHotKey(KEY_2, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'O');   
            JIntellitype.getInstance().registerHotKey(KEY_3, JIntellitype.MOD_CONTROL + JIntellitype.MOD_ALT,   
                    (int) 'X');   
      
            JIntellitype.getInstance().addHotKeyListener(this);   
        }   
      
     
        
         public static void main(String[] args) {
              Auto auto=new Auto();  
              auto.initHotkey();
             while (true) {   
                try {   
                    Thread.sleep(10000);   
                } catch (Exception ex) {   
                    break;   
                }   
            }   
        }   
    }
      

  5.   

    http://topic.csdn.net/u/20090329/18/55ac3b31-85ef-40ee-a1d9-f9b0c6613c96.html
      

  6.   

    Copy the following files into your classpath 
            -> jintellitype.jar
            -> JIntellitype.dll (or put in Windows/System32)
      

  7.   

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    这个是因为apache的commons-logging的jar没导入
    你可以去apache官方网站下载,如果你用的ide是eclipse的话,它的plugins目录里也有这个包
      

  8.   

    我用的是eclipse,应该导入成功了,我在没有导入之前,全都是错误,无法解析,包导入错误,导入包之后,全部正确,就是在编译的时候,发生了错误,也把JIntellitype.dll 放到Windows/System32了
      

  9.   

    1、我想做个跟“按键精灵”一样的java程序,我如何把一个字符串的内容输出到屏幕上网页中的文本框中?也就是,根据鼠标的位置,把内容输出到鼠标指定的文本框中或者其他地方??? 
    输出到屏幕上网页中的文本框中。 这个网页是自己写的吗?   自己写的比较简单, 就写个文件就OK了, 你不会是想在别的的网页里输出内容吧。 那你好好请教一下SUN了。
      

  10.   

    JAVA做类似按键精灵?这玩意可能有点难...   至少调用sendmessage  或把模拟按键  不太好整吧....jni??