Can we fire key press event programmatically????

hi there,
is it possible in java to fire a key press event (of the associated component) programmatically??? like we can fire action event of a button by saying
button.doClick();
thanks in advance.
anshu

You can do so by using awt.Robot.keyPress(), just don't forget to do awt.Robot.keyRelease() afterwards!
Note that it doesn't work for Applets unless you sign them, for security reasons (you don't want to go into a site and have the applet click ctrl+alt+del for you, right?)
Cheers!
Moti

Similar Messages

  • How can i call key press event for dynamically  created texbox

    Hi,
    I create a one texbox using javascript .now i want to call onFocus event that textbox.How is it

    I develop grid application using javascript only.When they press add button dynamically add one row and each cell contain one textbox for enter new data.if they want to edit previous data when cursor goes to that textbox,all textvalue is selected format

  • Raise Key pressed event

    Hello, any know how can I raise a key press event throw code. For example I want to simulate that the user has press the A Key. How can I do that throw code?
    Thanks a lot !!

    Hi there,
    Your question has been discussed previously in the forums. Sounds like you want to programmatically click a button in WPF.
    Please check out this post
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1329603&SiteID=1
    Thanks,
    Jennifer

  • Unable to receive Tab key press event

    Hello,
    I have written a component which extends JComponent.
    For that , when Tab key is pressed I need to process something.
    I have overridden the function processKeyBinding in my class.
    But I am not getting any event for tab key press. For all the other key press events, the function is being called.
    I also tried to create a action and add it to the action map. But that is also not working.
    Can anyone explain me why it is not working and give me the solution.
    Thanks in advance,
    Anu

    public static void removeTabFromFocusTraverval(Component c) {
         int id = KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS;
         Set strokes = c.getFocusTraversalKeys(id);
         Set newStrokes = new HashSet(strokes);
         newStrokes.remove(KeyStroke.getKeyStroke("TAB"));
         c.setFocusTraversalKeys(id, newStrokes);
    }

  • How to binding a key press event of "Esc" to "cancle" button

    I create a class extended JComponent. Than I add a button named "cancle " to it.
    Than I add the class's instance to a JDialog object.
    I try to get the key press event through add a keyListener to the class instance, but no works.
    I try to add a keymap and action map to the dialog 's getRootPane() also no works.
    Who can tell me how can I do?

    Thats the way I did it:
        // map escape key
        ActionListener escapeActionListener = new ActionListener()
          public void actionPerformed(ActionEvent e)
            cancelPressed();
        this.registerKeyboardAction( escapeActionListener,
                                     KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
                                     JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );

  • How to detect space key pressed event

    I am working on a japplet where it is needed to pause the applet on the occurrence of a space bar key pressed event can anybody help
    thanks in advance

    Have a look at the tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html
    http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
    -Puce

  • How to handle form close event or escape key press event for user defined f

    Experts,
    Please let me know how to handle form close event or escape key press event for user defined form...
    Thanks & Regards,
    Pravin.

    Hi
    You can catch the form close event like this
    If ((pVal.FormType = 139 And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_CLOSE)) And (pVal.Before_Action = True)) Then
          Try
                   SBO_Application.SetStatusBarMessage(pVal.EventType.ToString())
          Catch ex As Exception
                    SBO_Application.SetStatusBarMessage(ex.Message)
            End Try
          End If
    Hope this helps
    Regards
    Arun

  • Question about generate key press event to system. help plz.

    I am wondering if it is possible to write a java program to generate key press event(not receiving)to the local system so all the other program in the system receive those key press event also. Thanks.

    Hi,
    :. I don't know what exactly you intend to accomplish. But, I have used the following code in order to simulate keys pressing inside a Java application.
          /* - - - Simulates TAB (java.awt.Event)
          EventQueue evtq = Toolkit.getDefaultToolkit().getSystemEventQueue();
          evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_PRESSED,
                          0, 0, KeyEvent.VK_TAB, KeyEvent.CHAR_UNDEFINED) );
          evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_RELEASED,
                          0, 0, KeyEvent.VK_TAB, KeyEvent.CHAR_UNDEFINED) );
          /* - - - Simulates Shift+TAB (java.awt.Event)
          evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_PRESSED, 0,
                          InputEvent.SHIFT_DOWN_MASK, KeyEvent.VK_TAB,
                          KeyEvent.CHAR_UNDEFINED) );
          evtq.postEvent( new KeyEvent(this, KeyEvent.KEY_RELEASED, 0,
                          InputEvent.SHIFT_DOWN_MASK, KeyEvent.VK_TAB,
                          KeyEvent.CHAR_UNDEFINED) );:. However, as far as I know to send keys to the whole OS you have to create a 'Hook' as described inside Win32API documentation. That's for Microsoft Windows naturaly.
    Cheers.
    Roque

  • How to change a h:outputText value in the current form on key pressed event

    Hello Suners,
    Greetings! I'm developing my first JSF web application and i'm trying to figure a way out to change outputText value when key pressed on another inputText so that when the user is typing his name for example he can see the letters showing respectively in the outputText.
    I managed to do it onchange but the user must focus out of the inputText to see his name in the outputText which is not right and the form must submit onchange event which is annoying.
    <h:inputText value="#{login.username}" title="name" id="name" required="true" onchange="this.form.submit()" >
                                <f:validateLength maximum="10" minimum="1"/>
                                <f:validator validatorId="myValidator"/>
                                <f:valueChangeListener type="classes.MyListener"/>
    </h:inputText>Is there any listener i can associate with the "onkeypress" attribute? Can anyone help me to do that with JSF?
    King Regards,

    hi, with JSF 2 you got the ajax tag, just tried it and it works fine :)
    <h:inputText id="myinput" value="#{back.name}">
        <f:ajax execute="@this" event="keyup" render="outtext"/>
    </h:inputText>
    <h:outputText id="outtext" value="#{back.name}"/>or before JSF 2
    <h:outputScript name="jsf.js" library="javax.faces" target="head"/>
    <h:inputText id="myinput" value="#{back.name}" onkeyup="jsf.ajax.request(this, event, {render: 'outtext'}); return false;"/>
    <h:outputText id="outtext" value="#{back.name}"/>The name property is a simple String in the bean.
    Hope this helps
    Edited by: hereps on Aug 21, 2010 7:18 AM

  • Key Press Event

    I have been pouring through the TLF API docs looking for
    events to handle key presses on a TextFlow and I am not finding
    anything. I'm sure it's simple, can anyone give me a clue? I'm
    looking to detect Ctrl+B, Ctrl+I, etc.. to trigger formatting.

    The events go to the DisplayObjectContainerController. You
    will want to override the processKey event functions to add special
    handling. Those are in the protected methods section and are
    inherited from a base class.

  • Capture key press events with ExtendScript?

    Is it possible to do this?  I can't find an example in the documentation or online anywhere.  I'd really like to know when the user presses the arrow keys while viewing the slideshow in Bridge.
    Thanks!

    Thanks for the example Paul.  I can see how to listen to key down events on Windows and Dialogs that I create.  Do you know of way to listen for global (app-wide) key down events? These are not defined:
    app.addEventListener('keydown',...)
    app.document.addEventListener('keydown',...)
    I'm trying to add to the slideshow mode by having a little palette dialog with the context information shown that I need.  The default caption box doesn't have what our artists want.  If the palette window is in focus, I get the keydown event, but if they're using the arrow keys to flip through the slideshow, I can't capture those.
    Thanks for the help.

  • Key pressed event

    I need message to be displayed when certain key pressed. Why it's not working?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class TestKey extends JPanel implements KeyListener {
         public TestKey(){
              addKeyListener(this);
         public static void main(String arg[]){
               JFrame frame = new JFrame();
                  frame.setTitle("Test my keybord, man!");
                  frame.setSize(300, 200);
                  frame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  Container contentPane = frame.getContentPane();
                  contentPane.add(new TestKey());
                  frame.setVisible(true);
         public void keyPressed(KeyEvent ke){
              System.out.println("key pressed");
         public void keyTyped(KeyEvent ke){
              System.out.println("key typed");
         public void keyReleased(KeyEvent ke){
              System.out.println("key released");
    }

      public TestKey(){
        setFocusable(true);//<----------
        addKeyListener(this);
      }

  • Make Tab Key Press Event

    Hi You all,
    I'm trying to make an automatic Tab Key Press after fill some data to oEditText  , plz guide me how can i do that ?
    I will appreciate your help.
    Peter.
    Edited by: PeterHoang on Oct 12, 2011 12:22 PM

    Hi
    You can use sendkeys method for this
    SBO_APPLN.SendKeys("{TAB}")
    Regards
    Arun

  • Key Press Events

    Hi there,
    Im relatively new to java and need to implement a program which listens for a key press e.g. say the letter "n" and then performs an action, Is there a simple way to do this?
    I've found some stuff on the web about the KeyListener class but i don't understand it very well.
    Im wanting a solution which does this in the simplest way possible, any help you can give me would be greatly appreciated.
    Cheers

    yeh thats probly a good idea lol basically:
    I have this system using a virtual reality suite at my university, on the 3 large screens in the suite i have some background images of different environments. The backgrounds are displayed using media player classic, one media player for each screen, left, mid and right. I have a web page which is connected to the media players which when refreshed changes to the next item in the playlist (in the media players) so all 3 players "change scene" at the same time.
    Now my java program currently sends a refresh to this web page which in turn changes the background on the 3 screens. at the same time the program uploads an image onto the backgrounds at given co-oardinates. What im wanting next and am struggling with is for the image to be uploaded and the backgrounds to change when i press a key an for this to be repeated everytime i press that same key.
    This way i can cycle through all the different backgrounds with a simple keypress.

  • How to invoke a key press event in application that has focus

    Even though I know there are programs out there already that do this similar function, I want to write my own program that converts MIDI events into keypresses. Here is how it would work:
    - my program does not have focus, some other app has focus while my app runs in the backround
    -a midi event happens
    -a mapping is done by my app running in the backround: midi event->keypress
    -my app causes a keystroke event to be sent to whatever application has the focus.
    my problem:
    The part I am having trouble figuring out is how to invoke a keypress to the application that has the focus. Can someone shed some light how this would be done? I have learned a little about the Text Services Manager but this just a component of Carbon. I'd think that I needed to talk to a much lower level part of the operating system to be able to send a keypress to ANY app that is running.
    I would prefer to work in Carbon, c++
    The thing that would make my midi-keystroke program different from others out there is a much more complex mapping algorithm between the MIDI event and the keypress chosen. That's why I want to write my own.
    Thanks much anyone who can help!!
    Jay

    quartz event services contains the calls needed to perform this function

Maybe you are looking for

  • Cubase4.5.2 wont open after latest update?

    After the latest update Cubase 4.5.2 just quits on opening and now 1 of my USB ports will no longer power one of my external hardrives?????? Aaaaaggghhhhhh Can i revert back to 10.6.6?

  • Synchronous video capturing with a simple webcam with DIAdem-DAC/Visual

    Hello, because of DIAdem is not able to synchronise captured video files and MDF-data files measured with Vector Canape with all the skills of and in DIAdem-VIEW, how about even capturing a video additional to the other measured data with DIAdem-DAC

  • Maintaining Global Variables in a Web Service

    HI I want to write some webservices which manages global variables. For example i need to maintain a list of users who use this service (When the users first request comes his name is added to a data structure such as arraylist)s o that when his next

  • Problem with a procedure and an  agent

    Hi Guys, I created a local agent and use it to run a procedure that works Ok When I run the procedure using the agent it still working for a long time I tried to stopped but I can not. So I delete them. After that always I run the procedure despite o

  • Can Lightroom 5.5 'link' with Photoshop CS5?

    I use  Photoshop CS5 in Windows 7 and need to open Sony ARW RAW files. At a talk last night and expert gave a talk on his Mac about Lightroom and how RAW files could be imported. He showed how Lightroom differed from Camera Raw and persuaded me that