Here you can find the source of sendKeys(JComponent component, int modifiers, int key)
Parameter | Description |
---|---|
component | component to send event |
modifiers | e.g. Ctrl/Shift |
key | key code to send |
public static void sendKeys(JComponent component, int modifiers, int key)
//package com.java2s; /*// w ww . j a v a 2 s . co m * This file is part of the VVIDE project. * * Copyright (C) 2011 Pavel Fischer rubbiroid@gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import java.awt.event.KeyEvent; import javax.swing.JComponent; public class Main { /** * Send a keys with robot * * @param component * component to send event * @param modifiers * e.g. Ctrl/Shift * @param key * key code to send */ public static void sendKeys(JComponent component, int modifiers, int key) { KeyEvent event = new KeyEvent(component, KeyEvent.KEY_PRESSED, 0, modifiers, key, KeyEvent.CHAR_UNDEFINED, KeyEvent.KEY_LOCATION_STANDARD); component.requestFocusInWindow(); component.dispatchEvent(event); } }