Source Code : Use Robot to send combo key event

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Use Robot to send combo key event

        
//package uk.ac.lkl.common.util;



import java.lang.reflect.*;
import java.awt.Robot;
import java.awt.event.KeyEvent;


public class RobotUtilities {

    public static void sendKeysCombo(String keys[]) {
        try {

            Robot robot = new Robot();

            Class<?> cl = KeyEvent.class;

            int [] intKeys = new int [keys.length];

            for (int i = 0; i < keys.length; i++) {
                Field field = cl.getDeclaredField(keys[i]);
                intKeys[i] = field.getInt(field);
                robot.keyPress(intKeys[i]);
            }

            for (int i = keys.length - 1; i >= 0; i--)
                robot.keyRelease(intKeys[i]);
        }
        catch (Throwable e) {
            System.err.println(e);
        }
    }


    // main for testing purposes
    public static void main(String args[]) {
        String [] keys = {
                "VK_CONTROL", "VK_SHIFT", "VK_F11"
        };
        sendKeysCombo(keys);
    }

}

   
    
    
    
    
    
    
    
  

Thank with us