JIntellitype + Robot

Feature Requests, Comments, Bugs, and Suggestions on the JIntellitype Java API.

JIntellitype + Robot

Postby DaneelOlivaw » Thu Jun 23, 2011 7:12 am

Hello!

I would like to write a simple application that simulates KEY pressing,
when a key is pressed.

For example i want to simulate A key pressed and released, when B key is typed.
I've tried to do this with Robot class.

Code: Select all
     void initHotkey() {

        JIntellitype.getInstance().registerHotKey(KEY_W, JIntellitype.MOD_ALT,
                (int) 'W');
         JIntellitype.getInstance().registerHotKey(KEY_A, JIntellitype.MOD_ALT,
                (int) 'A');
         JIntellitype.getInstance().registerHotKey(KEY_S, JIntellitype.MOD_ALT,
                (int) 'S');
         JIntellitype.getInstance().registerHotKey(KEY_D, JIntellitype.MOD_ALT,
                (int) 'D');
         JIntellitype.getInstance().registerHotKey(KEY_O, JIntellitype.MOD_ALT,
                 (int) 'O');
         JIntellitype.getInstance().addHotKeyListener(this);
     }

     void init(){
        try {
         robot = new Robot();
      } catch (AWTException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
        initHotkey();
     }

Code: Select all
     public void onHotKey(int key) {
         switch (key) {
         case KEY_A:
            robot.keyPress(KeyEvent.VK_N);
            robot.keyRelease(KeyEvent.VK_N);
            robot.keyPress(KeyEvent.VK_N);
            robot.keyRelease(KeyEvent.VK_N);
             break;
         case KEY_W:

            robot.keyPress(KeyEvent.VK_W);
            robot.keyRelease(KeyEvent.VK_W);
            robot.keyPress(KeyEvent.VK_W);
            robot.keyRelease(KeyEvent.VK_W);
             break;
         case KEY_S:

            robot.keyPress(KeyEvent.VK_S);
            robot.keyRelease(KeyEvent.VK_S);
            robot.keyPress(KeyEvent.VK_S);
            robot.keyRelease(KeyEvent.VK_S);

             break;
           case KEY_D:

              robot.keyPress(KeyEvent.VK_D);
            robot.keyRelease(KeyEvent.VK_D);
            robot.keyPress(KeyEvent.VK_D);
            robot.keyRelease(KeyEvent.VK_D);

           case KEY_O:
     JIntellitype.getInstance().unregisterHotKey(KEY_W);
     JIntellitype.getInstance().unregisterHotKey(KEY_A);
     JIntellitype.getInstance().unregisterHotKey(KEY_S);
     JIntellitype.getInstance().unregisterHotKey(KEY_D);
     JIntellitype.getInstance().unregisterHotKey(KEY_O);
        System.exit(0);
       
        }
     }

I want the 'W' typed twice, anytime 'W' is typed. Unfortunately this causes a loop, so somehow i must check whether
'W' is really typed or just simulated.
I've tried to simulete a differnt key instead, as you can see in CASE 'A' i try to simulate typing 'N' twice, but this also doesn't work.
(N doesnt get typed)

Does anyone know what i do wrong?
Thank you!
Daneel
DaneelOlivaw
 
Posts: 1
Joined: Thu Jun 23, 2011 6:50 am

Re: JIntellitype + Robot

Postby Melloware » Thu Jun 23, 2011 9:19 am

Hmmm I might not be the best person to ask since JINtellitype is just meant to receiving events when your registered hotkey is pushed.

Simulating Key events is not my expertise!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11037
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA


Return to JIntellitype

Who is online

Users browsing this forum: No registered users and 2 guests

cron