Keyboard simulation in Java

Hello
How can I simulate a keystroke like Alt+Shift through java code?
Thanks,
Tomer

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

Similar Messages

  • Need help in designing an  ATM simulation in java

    Hi,
    I've got to design a simulation of an ATM in java(client/server) and if anyone can help me with some coding, it would be nice :)
    I've got to design the interface on the client side and connect it to a database on a remote server. Any codings of an ATM program will be of great help to me. so please give me a little help.. I'm really stuck and it's the first time I'm doing programming in Java.
    Regards
    Roubin.

    go to google.com and type in "ATM simulation in java." There are a number of example of this type of project.

  • JAXB 1: is it possible to go from enum simulation in Java to XML Schema?

    I know how to get an enum simulation in java from XML schema, but can it be done in the other direction, in the context of a web service implementation?
    The thing is from schema to java a customization file is used. But there's no specification for such a customization file usability when going from java to schema. So far, i'm getting a string for enum wrapper.

    Well, i got it to work in JAXB 1, w/o xfire, schema-to-java. Marshall and unmarshall.
    But w/ xfire, it doesn't appear to be possible. Would probably require implementing it for them myself...

  • How to create a discrete event Simulator in java

    I want to create a discrete event simulator in java to communicate between 1000 hots on the same machine.Can anyone help me with that???

    So I figured out how to create one, but when I try to do personProfile.save(), its always coming back as false. Any ideas why this might be?

  • Keyboard Simulation tutorial and snippets

    There are were several developers on the forums who asked various questions about keyboard simulation in Flash.
    While waiting for Godot I have posted a quick tutorial with a working example and code for both timeline and class-based app. Just pasted the code on timeline or make class a document class.
    http://as3-blog.net/snippets/keyboard.html

    What source link? All the code is on the page below demo:
    http://as3-blog.net/snippets/keyboard.html

  • Loss of keyboard focus in Java appl running under linux

    I have a small sample program that replicates my problem. When this program is run a window is created. If you select File->New another instance of the program window is created. Now if you try to go back and bring to front the first window, keyboard focus is not
    transferred when run under linux. You can only type in the second window. The expected behavior does happen in Windows.
    > uname -a
    Linux watson 2.6.20-1.2933.fc6 #1 SMP Mon Mar 19 11:38:26 EDT 2007 i686 i686 i386 GNU/Linux
    java -versionjava version "1.5.0_11"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
    javac -versionjavac 1.5.0_11
    import java.awt.event.*;
    import javax.swing.*;
    class SwingWindow extends JFrame {
        SwingWindow() {
         super("SwingWindow");
         JMenuBar menuBar = new JMenuBar();     
            JMenu fileMenu = new JMenu("File");
            JMenuItem newItem = new JMenuItem("New");
            newItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
              SwingWindow.createAndShowGUI();
         fileMenu.add(newItem);
            menuBar.add(fileMenu);
            setJMenuBar(menuBar);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);       
         JTextField text = new JTextField(200);
         getContentPane().add(text);
         pack();
         setSize(700, 275);
        public static void createAndShowGUI() {
            JFrame frame = new SwingWindow();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    You can implement the FocusListener interface. When
    the first JFrame gains focus, call
    text.requestFocusInWindow(). I hope this helps.The call requestFocusInWindow is not helping, perhaps even making it worse.
    The problem seems to be that I am in the situation where the call
    KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner()
    is returning the expected Component. The problem is that the KeyListener class that is registered with the Component is not being called when a key is being pressed.
    The issue is that I have a component that has the keyboard focus, but the KeyListener class
    is not responding.
    This seems to be a linux only problem which makes it only mysterious.

  • Keyboard settings problem Java Studio Enterprise 8.1 on OpenSUSE 10.2

    I have of Sun Java Studio Enterprise 8.1 installed on OpenSUSE 10.2 x86-64 using KDE. I use Finnish keyboard, the same keyboard is used in Swedish, too.
    For some reason I haven't been able to use the FI/SE keyboard layout with the IDE. The keyboard behaves like an US keyboard.
    I have tried to use private properties of my project nbproject/private/private_fi_FI_EURO.properties but this doesn't help. I have tried to edit jstudio.conf with --locale fi:FI . It didn't help.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    - Do the demo programs that come with jdk run fine with the keyboard layout? For instance: <jdkdir>//demo/jfc/Stylepad
    - Setting the locale within ide would probably only work for the localization of strings within the ide itself.
    For instance, from the following the FAQ on encoding:
    http://wiki.netbeans.org/wiki/view/FaqI18nFileEnc
    If you use the UNIX/Linux platform, you can start the IDE with the UTF-8 locale.
    Most modern UNIX/Linux platforms support UTF-8 locales.
    For example, if you use Japanese,
    % export LANG=ja_JP.UTF-8
    % netbeans
    ... There is no way in Windows to change the locale at IDE startup.In other words, the locale should perhaps be set at the OS , JVM level and cannot be configured in netbeans.
    - http://java.sun.com/javase/6/docs/technotes/guides/intl/locale.doc.html#input

  • Small tennis simulation in Java

    Hello, I am a new programmer and I have Several questions about how to implement object oriented features in my tennis simulation being written in Java. http://telis.edugraf.ufsc.br/apliques/2007/2/ProjetoTenis/src
    (Just cut and paste it to see the source code for my simulator)
    First I will tell how my simulation works so that you all can understand better what I need to do, how to do it and especially how to do it in an object oriented way (can have some generic programming too)
    This is how the program works
    I am doing a little tennis program in which I implement the simulation of a game of a tennis match based on random number generation and probabilities. For example, it chooses a number between 1 to 2, and if the result is 1, the player hits the first serve. If not, then the second one.
    Then, when he hits any of the two serves, it sorts a number between 1 to 10. In the first serve case, if the number is anything between 1 to 8, the server wins the point. In the second serve case, the server wins the point if the value choosed is anything between 1 to 5.
    I have three big classes, one that has the main method and creates an object that represents a tennis match.
    This object calls for a method of the class "Game", the class responsible for 'managing' a game from a tennis match.
    For now the only thing this "Game" class is doing, is holding the method responsable for controlling the serves, that as was said in the above paragrapher, are the responsables for deciding who is going to win a point. The method "saque" (serve in english) chooses a serve and then send it to a certain method of the "Pontos" (points) class to select who winned the point.This class contains three methods, each one for one of the three possibilities: first serve in, second serve in and double fault. When the winner of the point is choosed, I would like it to return the two variables that represent the points that each player will have after the point is finished,
    back to method "saque" (serve) of the Game class.
    This brings me to the first problem: methods cannot return two values. So, can I create an object composed of two fields and return it? If I can, can you guys show how to do it?. If not, what you suggest?. I need to return them because I intend to create in the "Game" class, another method, one that will control the game, or in another words, finish the program when a player collects enough points to win the game.
    Then in the "game" class, I would like to send these two values, whether they will be in an object or in another form to the "control" method that I intend to create in the same class. This brings to the second question which is: when these points will be returned, should I create this "control method" in the same class and send the values to it, or should I do something completely different to allow bigger modularization?.
    And the last question comes to the surface due to the fact that the point count changes during the game. The way it is now. at each new point 15points will be given to the variable that represents the score of one of the players.
    How should I change this value according to occasion? Should I create an object of the type "Point" to do this?
    Thanks for all the suggestions and recomendations.
    Edited by: ratzenberguer on Dec 1, 2007 4:06 PM
    Edited by: ratzenberguer on Dec 1, 2007 4:07 PM

    This brings me to the first problem: methods cannot return two values. So, can I create an object composed of two fields and return it?
    Yes. Exactly... If you really must!
    But a method should return one and only value and have no (or limited and predictable) side effects.
    So for instance a getter (ie getAttribute() method) should NOT update the attribute in the GUI (for instance) as a side effect. But a getAverage() method might reasonably cache (store) the calculated average.
    The usual approach is:
    * perform some operation which stores values in class attributes
    * retrieve those class attributes via getters.
    for example:
    studentGrades.calculateAverage();
    studentGrades.getAverage();
    studentGrades.getSum();
    studentGrades.getCount();
    If a method really must return several values, and it is only used internally (within one class) then it's best to return an "inner class" (google that). I do this fairly routinely in swing apps... for inter-thread communication. I recommend making the attributes public and final.
    If a method is used externally (between classes) then I personally will create a package level class to return the value... but only if I must.
    If the method is public then I personally won't create a public class just to return multiple values from a method... coz this is a poor public API, coz it's difficult to figure out how to use it properly.
    Obviously, If the method returns a class which is allready part of the public API then that's ok... For example: TennisPlayerBuilder.getPlayer() might return a configured TennisPlayer... coz TennisPlayer is part of the public API.
    Clear as mud right?
    Jeez I hope someone else can explain this properly... On rereading this, I'm a mess.

  • Keyboard settings in Java Studio Creator

    I am using Solaris 10, Swedish installation. All programs exept Java Studio Creator 2 Update 1 is Swedish. The Creator is in English. Every program so far, exept Java Studio Creator, uses the Swedish keyboard settings.
    When using Java Studio Creator, I am missing brackets "[" and "]" which turns into "8" and "9",
    How do I configure Java Studio Creator to use my Swedish keyboard settings?
    Thanks in advance!

    I have not tried it, but perhaps this article might help.
    http://developers.sun.com/jscreator/learning/tutorials/2/internationalizingapps.html

  • Change keyboard language by java program

    I have done internationalization successfully in my java web application.
    but for insert input i always need to select language of keyboard manualy by
    control panel's .
    have any one java program to select keyboard language programatically.

    to_anilkumar82 wrote:
    Actualy when you select application in perticuler language (suppose in japanies) than
    message dispalying and value insertion will be done in that language(japanies).
    this is the case when user is not aware about language,user only select a lnguage type
    initialy when user open the application.So what? This is a feature of youyr application, whereas the keyboard layout is not.

  • Simulation in java

    hello:
    i am working on a project which deliver a signal from sensor and send it to computer by serial port.
    actually i need to make simulation to this system using Java, i mean that i want to exchange the hardware part (sensor) and simulate it in java, so can java do that? and how?
    note: my sysetm should count people who cut the sensor beam.

    If I were doing this I would make my communication with the hardware as an implementation of some interface so that I would then have two implementations of that interface. An implementation that talks to the hardware and one that is a simulator.
    For example
    import java.util.*;
    interface HardwareCommunicationsIF
        void addEventListener(HardwareEventListener eventListener);
    interface HardwareEventListener
        void notifyEvent(HardwareEvent hardwareEvent);
    class HardwareEvent
        // place in here stuff to identify the event type and parameters associated with the event
        public Date getEventTime()
            return eventTime;
        private Date eventTime = new Date();
    abstract class AbstractCommunications implements HardwareCommunicationsIF
        public void addEventListener(HardwareEventListener eventListener)
            if (eventListener != null)
                listeners.add(eventListener);
        protected void notifyListeners(HardwareEvent event)
            for (HardwareEventListener listener : listeners)
                listener.notifyEvent(event);
        private List<HardwareEventListener> listeners = new ArrayList<HardwareEventListener>();
    class RealHardwareCommunications extends AbstractCommunications
        // In here you talk to the hardware and then notify the listeners using
        // the notifyListeners() method.
        RealHardwareCommunications()
            // Setup the communications with the hardware
            // and start a thread that processes the information from
            // the real hardware.
    class DummyHardwareCommunications extends AbstractCommunications
        // In here you run a thread which generates dummy events
        // then you notify the listeners using
        // the notifyListeners() method. For example
        public DummyHardwareCommunications()
            new Thread(new Runnable()
                public void run()
                    Random random = new Random();
                    while (true)
                        // a random delay before generating the next event
                        int delta = random.nextInt(1900) + 100;
                        synchronized (this)
                            try
                                wait(delta);
                            catch(Exception e)
                                // Nothing to do
                        HardwareEvent event = new HardwareEvent();
                        notifyListeners(event);
            }).start();
    public class Fred114
        public static void main(String[] args) throws Exception
            // You could use Class.forName() to define whether or not
            // you use the real or dummy comms.
            //HardwareCommunicationsIF comms = new RealHardwareCommunications();
            HardwareCommunicationsIF comms = new DummyHardwareCommunications();
            comms.addEventListener(new HardwareEventListener()
                public void notifyEvent(HardwareEvent hardwareEvent)
                    System.out.println("Event received at " + hardwareEvent.getEventTime());
    }

  • Simulator for java card

    hi
    i am new to java card technology...i am writing the applets in netbeans using java card plugin....the problem is i m not able to simulate the applet..it is showing build successfully, but wen i run the app it is showing nothing.....so can anyone suggest me a suitable simulator for the same....

    Hi,
    I assume you are after details on how to use the simulators? There are examples and documentation with the JC specifications and developer kit. Both of these are available from the Sun website [http://java.sun.com/javacard/].
    If you are after details on how to develop your own, the JC specifications outline the requirements for the JCRE and JCVM that you can use to implement a simulator.
    Cheers,
    Shane

  • Creating a keyboard output with java

    can I use java to "fake" keyboard outputs?
    ex:
    if (x) {
    make another program think that the key "b" has been pressed on the keyboard
    Edited by: michael_TM on Jun 23, 2008 5:20 AM

    michael_TM wrote:
    I'm using java as a bridge appl. (I think it's called) between a labview program and a flash appl. and the flash appl. runs on keyboard inputs. so I need java to fake keyboard inputs, so flash thinks that certain keys has been press, and it's different keys, based on the output from labview.Ok, my answer still stands, did you check if the Robot class is good for you? Sounds as if it can help you solve your problem.

  • Need suggestion regarding simulation of Java Card using a floppy

    Hi All,
    I am working on a project wherein I have to simulate a Java Card application using a floppy. I am writing my own Card Terminal and CardTerminalFactory. Thats what I have started working on. Will that serve the purpose or do I have to think about some other approach like just overriding the cardInserted method of CTListener class? I want to achieve communication between the host application and the floppy(which is my java card) Please advise.
    I would like to thank DurangoVa and Nilesh for helping me out sorting out the error in running the converter.
    Thanks in advance

    Are you referring to a Floppy diskette drive ?

  • Google map simulation in java

    Hi guys, i want to simulate my own version of google map but would like to design it in such a way that the geographical data is kept separate from the actual implementation functionality e.g use the data for different areas instead of me rewriting the code. Now, i have been searching the web and have noticed that java has a Class GeoData (http://flickrj.sourceforge.net/api/com/aetrion/flickr/photos/GeoData.html) which can be used to create the long/latitude but what i would like to know is are there any tutorials available that one could recommend me to show how to use this class? As again, i idealy would like to keep these components separate.
    Your input would be so greatful guys.
    Thanks

    Oh i see cool. I've been browsing the net have found this link http://geotools.codehaus.org/ which seems to be what looks like some sort of IDE for map creation. Has anybody here ever used this before and what are you thought about this?
    Edited by: nvidia1 on May 20, 2008 12:31 PM

Maybe you are looking for

  • Error ,while trying to keep position in hold

    Hi i am getting eror while tying to keep position 50001 in hold , its saying EE123 is not in employee data base, i checked the relationship of the EE123 to the position 50001 found this Position 50001 position was reporting to EE123 few years back fo

  • Issue with UIX Editable Table

    Hi, I have created a Master-Detail-Detail page using UIX. I want to make the last detail table editable. I have tried the tip mentioned in the following page to make the table editable. http://www.oracle.com/technology/products/jdev/tips/jacobi/editt

  • FI-MM integrations(GR/IR Clearing a/c)

    Hi All, I face one interview question from the one of the interview. I.e. What is GR/IR clearing a/c? what is the purpose to use GR/IR Clearing a/c? for these questions i have answered but Immediately the interviewer ask  me ask me. If i Receipt Good

  • Fetch problem

    We have two instance (SIDs) in our DB . We have a stored procedure , which fetchs cursor into variables. In first DB it works( fetchs data) and in another - it doesn't work ( the data are the same as they are in the first one). Server is NTServer,Ora

  • RAW 8.4 für Lightroom 5.3

    Hi Ich habe die Nikon D4s und kann keine Bilder (RAW8.4) im Lightroom 5.3 bearbeiten. Im Photoshop ist das Raw 8.4 erhätlich. Wann ist Lightroom wieder auf dem neuesten Stand? MFG Roger