java - Sending keypresses to JTextField -


I am trying to simulate text input in a JTextField I have a 1 letter long string in which I want to add letters and I run:

  receiver.dispatchEvent (new keyEvent (this, KeyEvent.KEY_TYPED, 0, this.shifted? KeyEvent. SHIFT_DOWN_MASK: 0, Key Event. VK_UNDEFINED, text.charAt (0)));  

But this does not seem to change the content at all. What am I missing here?

I look like a virtual keyboard: -)

almost the exact same Code works for me I give the following suggestions:

  1. target JTextField (in your case, receiver ) to < Code> pass as source keyEvent parameter for constructor, i.e.:

      receiver. DisketAvent (New keyEvent (Receiver, KeyWorld.ktttd, system.contentime milliseconds), Modifier,  
  2. Ensure that your target is JTextField

    Edit:

    To verify the above suggestions, Tested this snippet for:

      frame frame = new frame (); textfield text = new textfield (); frame.ed (text); Ram.pack (); frame.Seasible (true) text; dislike event (new key event (frame, key event, keiPED, 0, 0, key events, this does not work, however The last line has been modified as follows (if the target component is the parameter of the  source , then it is not working;  
    code> KeyEvent Con Structureer), it works fine:

      text.dispatchEvent (new keyEvent (text, keyEvent.KEY_TYPED, 0, 0, keyEvent.VK_UNDEFINED, 'H'));  

Comments