Here you can find the source of simulateKeyPressed(Component component, int key)
Parameter | Description |
---|---|
key | KeyEvent.VK_... |
public static void simulateKeyPressed(Component component, int key)
//package com.java2s; //License from project: Apache License import java.awt.Component; import java.awt.event.KeyEvent; public class Main { /**//ww w . j a va 2 s . c o m * Simulate a key press/release event on the component. * * @param key * KeyEvent.VK_... */ public static void simulateKeyPressed(Component component, int key) { component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_PRESSED, 0, 1, key, KeyEvent.CHAR_UNDEFINED)); component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_RELEASED, 0, 2, key, KeyEvent.CHAR_UNDEFINED)); } }