Capture desktop key event to control my screen capture app

I want to write a screen capture program to capture screen when I am playing fullscreen game or other desktop window application. But the java screen capture program can only receive key or mouse event when it is focused. So how do I capture key event when I am focusing other app or fullscreen app?
Do I have to use JNI and call some OS specific API. My target OS is WinXP. Help or suggestions are appreciated!!

Hi All,
I was wondering if there is a way to capture the top-most
window or dialog box. This is something that will
generally be running outside of the JVM....We,
as programmers, need a Rectangle instance that describes the area
of interest to be captured (i.e., location and size).
Thus, a routine that interfaces to the Native windowing system (Toolkit?)
might look something like:
Rectangle rect = tk.getRectangleForTopMostComponent();
Does anything like this exist?
Thanks!
- DocJava

Similar Messages

  • Lag on key press (key event)

    Hello, I am currently working on a simple game in Java. I've used Java's Key_Pressed in Key Event to control a ship moving back and forth with the up and down keys. I've noticed that when a key is pressed there is a short pause before the ship actually moves. What can I do to avoid this pause?

    The "repeat rate" for holding a key down is controlled by the OS.
    You should not be relying on multiple KeyEvents to move your component as the repeat rate will vary from machine to machine. Actually you should not be using KeyEvents anyway you should be using [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]Key Bindings
    On keyPressed binding you would start a Timer and then on keyReleased you stop the Timer. You can then control the interval at which the Timer fires so you game will be consistent on all machines.

  • Capture Key events

    I am trying to create a program to capture key events, regardless of where the focus is. For example, any time the user presses ctrl-t, I would like to call a particular method, if the user is in Microsoft Word, Internet Explorer, Halo, or any other application. However, a glass pane would not work, because all other key events will be needed by the current application. This would be identical to Microsoft' s ctrl-alt-del and Microsoft's alt-tab. Any ideas would be greatly appriciated. Post here or E-mail be at [email protected]

    This is not true, think of all the keylogger programs out there that allow you to do this.
    It's not a security issue.
    I also am wondering how to capture a key on a java application without it having focus. An example is a timer in a game. I should be able to be in a full screen game and hit F1 or Home or whatever I choose and have a timer start that will ding at me in 1 minute to let me know that my time is up.
    It is in a way similar to CTRL ALT DEL in that you don't ahve to be focused on anything in particular to use it but that isn't really the best analogy.
    If anyone can point me in the right direction to figure out how I would go about this, please tell me. Or if it is not possible for a program written in java to capture keypress without focus I would like to know that as well.
    You can do this in C and C++ but I would like to just add it in to an existing java program, thanks.

  • 2nd JFrame at Full Screen not registering key events

    I've written an application that launches other applications distributed as JARs with a particular method (replacing the main method). These other applications run at full screen.
    Whilst I have got these other applications to work in that they display correctly and do everything else, I require them to register key events. If I run these applications on their own (i.e. having not been launched by the primary application) then the key events are processed correctly. However when they are launched from the primary application the key events are not registered.
    I have tried requesting focus from the full screen JFrame but it doesn't seem to be able to.
    Any ideas?

    Possible that the keystrokes are really being trapped by the other gui, which stops registering them when it's not visible.
    IF that's the case, you'll need to re-design your keyboard trap as part of the second JFrame, wholly independent of the original JFrame or originating app. Also, it may be thread-starved i.e. operating off the originating program, which thread may be stopping when it has no focus.
    That's all the ideas I have.

  • Adobe reader control kills key events

    I am using visual studio express 2013 on Win7 professional (x64) to write a private c# form application.
    Adobe reader is installed and added to my project.
    The control shows a pdf, wounderful.
    But at the moment, my form has the adobe reader control, no key events where triggered.
    Without the control: all works fine.
    I record a video to show my problem: https://www.youtube.com/watch?v=V0Vo2p2jz9M
    Is there a solution or workaround to give the key events to my form?
    Are more information needed?
    Thanks a lot.

    Check if you have full access to
    HKEY_CLASSES_ROOT\AcroExch.FDFDoc and sub keys,
    Disable any antivirus or backup applications while installing Reader.

  • Capturing Enter key event from text box

    In my application, there are a number of text boxes. I want to create a feature where an enter key even is seen and specific function executed depending on which text box was in focus when the enter key was pressed. Currently I am able to capture an enter key event on the whole page. How do I do that specifically for a text box?
    This application is done in HTML, javascript and Adobe AIR.
    Thanks
    Binu
    www.verseview.info

    Hi
    That's true that Flex4.5 SDK under Flash builder Burito doesn't listen Enter key in Text Area for KeyUp or KeyDown event.
    Here I found a work around you can use.
    Add an eventlistener to the component in actionscript and set the useCapture=true next to eventlistener function. Now you can listen enter key for KeyUp or KeyDown Event
    Hope this helps
    Rush-me

  • KeyListener does not capture Arrow key Events in textField

    Love................
    I added a key listener to TextField it does not detect
    Arrow Keys events in keyTyped, KeyPressed,KeyReleased methods
    why?????
    I want to shift focus from a textfield to other component
    on capturing Arrow key Pressed How

    Here is a Java demo where it works since it is not a printable character you must get the keyCode:
    http://java.sun.com/docs/books/tutorial/uiswing/events/example-swing/index.html#KeyEventDemo
    public class KeyEventDemo ... implements KeyListener ... {
    ...//where initialization occurs:
         typingArea = new JTextField(20);
         typingArea.addKeyListener(this);
    /** Handle the key typed event from the text field. */
    public void keyTyped(KeyEvent e) {
         displayInfo(e, "KEY TYPED: ");
    /** Handle the key pressed event from the text field. */
    public void keyPressed(KeyEvent e) {
         displayInfo(e, "KEY PRESSED: ");
    /** Handle the key released event from the text field. */
    public void keyReleased(KeyEvent e) {
         displayInfo(e, "KEY RELEASED: ");
    protected void displayInfo(KeyEvent e, String s){
         char c = e.getKeyChar();
         int keyCode = e.getKeyCode();
         int modifiers = e.getModifiers();
         tmpString = KeyEvent.getKeyModifiersText(modifiers);
         ...//display information about the KeyEvent...
    }

  • Can't capture key event in applet

    Hi,
    Currently i'm developing an applet. However, i fail to capture the key event in the applet. The key that i fail to capture is VK_TAB. Any idea to handle this?
    Thanks in advance!

    to capture key event, u need to
    1. addKeyListener
    2. focus on that component (yourApplet must focusable)

  • How to capture backspave and delete key events

    Hi ,
    i would like perform some javascript code on pressing backspace or delete key.
    initially i thought of adf clientlsitener keypress event.but this is not capturing backsapce key event
    what is the alternate way capture backspace or delete key event?
    please help

    Hi
    the following script cancels the input event when the back key is pressed
           function keyTrap(inputEvent){
             var keycode = inputEvent.getKeyCode();
             if(keycode ==8){
               inputEvent.cancel();
           }Use a clientListener
            <af:inputText label="Label 4" id="it7">
              <af:clientListener method="keyTrap" type="keyDown"/>
            </af:inputText>Frank

  • Capturing the TAB key event.

    How can I capture the TAB key event?
    I am trying to use it within a JTextField to do a normal text tab operation.
    Thanks,
    D

    I want to map the Tab key to a jTextField so that when the user is editing inside the jTextField they can press the TAB key to tab over a predefined number of characters.
    Thanks,
    D

  • Key event capture

    I can't find a way to capture the key events of the special key on multimedia keyboards, just like play/pause, browser or music..
    Any ideas?

    You probably can't. They have their own drivers to handle those specialties and Java (as far as I know) doesn't have support for those.

  • On Key Event change sprite and sound

    I can't sort this out for the life of me.
    I have this at the moment....They are cast member scripts.
    There are four movies that switch on mouse clicks along with
    their associated sound.
    Trouble is that they are different sizes and the largest
    stays on the screen behind the new clip.
    I tried an unload
    _movie.unLoadMember(member("movieTwo"))
    but wherever I put it it did not work.
    I am new to Director and using ver11
    I have put the first clip on channel 1 and its sound on sound
    channel 1. Then that has a cast memeber script to swap the sound
    and image from the cast.. Each clip has a cast member script to
    move to the next clip.
    I did post earlier in the 'basics' a similar problem but have
    as yet found no solution.
    I really do need to have the changing of clips and of sound
    driven by key events. But I cannot get any key
    event to be recognised by director when the projector runs..
    Where does one put key.up and key.down in director?
    I really am stuck here and truly any help would be great
    Cheers

    You can place 'on keyUp' or 'on keyDown' event handlers on
    any sprites
    that would normally get keyboard input (i.e. editable #text
    or #field
    sprites as well as certain #flashComponents). You can also
    make a
    "movie-wide" control by putting an 'on MouseUp'handler in a
    MOVIE
    script. This event will happen if there is no editable text
    item on the
    stage.
    If you want to use a global keyDown handler, you need to set
    up 'the
    keyDownScript' (refer to the help file for explanation and
    syntax)

  • Sleutel Bind, fancy key events handler for standalone window managers

    I began using Openbox in my laptop a while ago, and I was amazed by the speed, customization and simplicity it provides. After I started customizing my desktop I noticed that some of the special keys (TouchpadToggle, Volume, PrintScreen, etc) didn't worked at all. There are some applications for the Volume keys to work, but not for keys like touchpad-toggle and print-screen. Of course, there's a workaround for each case using simple scripts, but I wanted something a little more fancy, so I made:
    Sleutel Bind
    It's made in C and provides key events handling for:
    XF86TouchpadToggle
    Print (prtsc key)
    It makes use of libnotify to display states ( touchpad enabled/disabled, screenshot taken, etc) and imlib2 (a very popular library, probably already installed in your system) to grab the screenshots. Almost all other keys are covered already by another application, but if needed, more key events will be added in the future.
    Feel free to post your thoughts about Sleutel Bind, it's my first contribution to the community.
    How to use
    Once installed just run the command as a normal user.
    If using openbox, place the following command in the "~/.config/openbox/autostart" file:
    sleutelb &
    Links
    AUR
    github
    Last edited by DanielRS (2013-03-01 21:58:35)

    mgmillani wrote:
    I believe it must have been a bug and it was fixed, since print screen now works as expected. I'm using xmonad version 0.11-9, with ghc version 7.8.3.
    davama wrote:
    Note: for my print key to be recognized by xev i had to hold the ctrl key. that way it was not registered by xmonad. Also for xev command i use
    xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'
    Nice, that seems to be useful. Thanks!
    @LQYMGT
    Do you still have issues with the latest version? Otherwise I will mark this thread as solved.
    well, still do not work... But I do not want to try it any more...So you can mark.

  • Getting Key Events during animation loop

    I'm having a problem recieving Key events during my animation loop. Here is my example program
    import java.awt.*;
    import java.awt.image.BufferStrategy;
    import javax.swing.JPanel;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import java.util.ArrayList;
    import java.awt.event.*;
    import java.util.Iterator;
    import GAME.graphics.Animation;
    import GAME.sprites.MainPlayer;
    import GAME.util.MapData;
    import GAME.input.*;
    public class ImageTest extends JFrame {
        private static final long DEMO_TIME = 20000;
        private Animation      anim;
        private MainPlayer     mPlayer;
        private MapData               mapData;
        private InputManager      inputManager;
        private GameAction moveLeft;
        private GameAction moveRight;
        private GameAction exit;
        public ImageTest()
         requestFocus();
         initInput();
         setSize(1024, 768);
         setUndecorated(true);
         setIgnoreRepaint(true);
         setResizable(false);
         loadImages();
         anim = new Animation();
            mPlayer = new MainPlayer(anim);
            setVisible(true);
            createBufferStrategy(2);
            animationLoop();
         // load the player images
         private void loadImages()
              // code that loads images...
         // Initialize input controls
         private void initInput() {
            moveLeft = new GameAction("moveLeft");
            moveRight = new GameAction("moveRight");
            exit = new GameAction("exit",
                GameAction.DETECT_INITAL_PRESS_ONLY);
            inputManager = new InputManager(this);
            inputManager.setCursor(InputManager.INVISIBLE_CURSOR);
            inputManager.mapToKey(moveLeft, KeyEvent.VK_LEFT);
            inputManager.mapToKey(moveRight, KeyEvent.VK_RIGHT);
            inputManager.mapToKey(exit, KeyEvent.VK_ESCAPE);
        // Check player input
        private void checkInput(long elapsedTime) {
            if (exit.isPressed()) {
                System.exit(0);
            if (mPlayer.isAlive()) {
                float velocityX = 0;
                if (moveLeft.isPressed()) {
                    velocityX-=mPlayer.getMaxSpeed();
                if (moveRight.isPressed()) {
                    velocityX+=mPlayer.getMaxSpeed();
                mPlayer.setVelocityX(velocityX);
        // main animation loop
        public void animationLoop() {
            long startTime = System.currentTimeMillis();
            long currTime = startTime;
            while (currTime - startTime < DEMO_TIME) {
                long elapsedTime =
                    System.currentTimeMillis() - currTime;
                currTime += elapsedTime;
                checkInput(elapsedTime);
                mPlayer.update(elapsedTime);
                // draw and update screen
                BufferStrategy strategy = this.getBufferStrategy();
                Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
                if (!(bgImage == null))
                     draw(g);
                     g.dispose();
                     if (!strategy.contentsLost()) {
                         strategy.show();
                // take a nap
                try {
                    Thread.sleep(20);
                catch (InterruptedException ex) { }
        public void draw(Graphics g) {
            // draw background
            if (bgImage != null)
                         // draw image
                 g.drawImage(mPlayer.getImage(), (int)mPlayer.getX(), (int)mPlayer.getY(), null);
    }My InputManager implements KeyListener. When running print statements on my Key events, they are not being called until after the animation demo is done running. Can someone help me with getting the Key events to update during the animation loop? Thank you!

    I've used the post from Abuse on the following thread with success. Maybe it will clue you in to what you might be doing wrong:
    http://forum.java.sun.com/thread.jsp?forum=406&thread=498527

  • Screen Sharing.app fails through ssh tunnel with "You cannot control your own screen"

    I need to control a remote Mac mini running 10.7 through an ssh tunnel.  I've set up ssh with -L for the appropriate ports, and bound my local ports 5900 and 5800 through this.
    When I connect to 127.0.0.1 with Screen Sharing.app on my macbook pro which runs 10.8.4, it says "You cannot control your own screen" however, screen sharing is not enabled locally on my machine, I'm trying to access a remote machine.
    I tried something else.  I created an alias IP of 127.0.0.2 on lo0, and tried again, and got the same thing, so it's doing an ifconfig and looking through all the IPs to see if the IP address of what I'm trying to connect to is bound locally, which defeats the purpose of tunneling through SSH.  I don't wish to setup a VPN.
    How do I let the Screen Sharing.app know that I'm not trying to connect to my own machine and it should skip this check.
    I've also tried with another app, Chicken of the VNC, and that almost works.  It connects and shows a login screen desktop to the target machine, but I'm unable to click on any of the account icons displayed in order to login, and all key presses such as tab, space, and enter are ignored.
    When at the location (on the same vlan as the target machine) I'm able to remote into it just fine with screen sharing.app, but Chicken of the VNC has the same issue of showing a login screen, but not allowing logins to it.

    Your ssh command should look something like:
    ssh -L 22590:localhost:5900 remove.mac.system.address
    Then you connect using
    Finder -> Go -> Connect to server -> vnc://localhost:22590
    Have you been doing anything close to that?

Maybe you are looking for