How to detect mouse clicks on desktop?

Hi All,
I need to detect mouse clicks on the desktop and find out mouse position on the screen. How to listen to mouse events if I don't have any swing components like containers, panels, windows, etc? All things like "addMouseListener" are supposed to be with such components. But my program is running in the background and it doesn't have any graphical interfaces. So, I need to detect if a mouse button is pressed at any position on the screen.
Thanks for any help!

Why? What program feature do you intend to offer, by knowing what a user clicks on (besides the application itself).Hi, well what I have to do is to start the application minimized in the system tray. Then the application must be listening for crtl+shift+left click in any part of the desktop or an opened application, when that happens, I have to show a window asking if the user want to take a screenshot starting in the x,y point he clicked, once done, I have to take an screenshot...so on.
How can I do that? Can anybody give me a hint? Thanks in advance.

Similar Messages

  • How to detect mouse click event?

    Hello,
    I would like to have a vi to detect left, right and no mouse click. I mean that in the vi attached, Button2 should be 0 (no click), 1 (left c.) or 2 (right c.) depending on the event occured in i-1. cycle. My vi is the modyfied version of the one found here:
    http://www.ni.com/example/27663/en/
    Sometimes it works fine, but another time nothing happens when I click.
    I think the main problem is with the execution times at the for loop and event structure.
    Could you help me how to deal with the problem?
    Thanks you!
    Attachments:
    mouse1.vi ‏12 KB

    Hi VampireEmpire,
    Your For loop iterates twice. If an event occures during first iteration everything is fine - Button 2 refreshes during second iteration. But what happens when an event occures during second iteration? Does Button 2 have a possibility to refresh? 
    1. Do you see the problem now?
    2. And if you do - do you really need For loop? I would suggest you trying removing it and connecting shift register to the while loop.
    Bluesheep

  • Detecting mouse clicks in editable cell of JTable

    Hi everyone :)
    I thought that this question might have been asked before, but I have searched the forums extensively and have not been able to find the solution.
    What I want to achieve is to detect single and double mouse clicks on JTable cells (that are editable).
    For example, I have a JTable and there exists within it an editable cell. If the user clicks on it once then that cell goes into edit mode, and the user can type directly into the cell. I have already successfully implemented this.
    However, what I also want to do is detect a double-click so that I can pop up a dilaog that shows a list of default values that the user can select.
    So here is what I want;
    1. User clicks on the cell once.
    2. Cell moves into edit mode.
    3. If the user clicks again within a certain time interval then cancel edit mode and pop up a dialog containing values that the user can select from.
    I think that to do this I need to be able to detect mouse clicks on the cell that is currently being edited. So far I have been unable to discover how this is done. I have even tried extending JTextField to get what I want, but with no luck.
    Any help would be greatly appreciated.
    Kind regards,
    Ben Deany

    Thanks for the reply.
    Unfortunately, it is not possible to call 'AddMouseListener()' on a cell editor. You are only able to call 'addCellEditorListener()' and that only allows two events to the broadcast (edit cancel, and edit stop).
    Ben

  • Detect mouse clicks or keyboard events on desktop or everywhere

    Hi,
    What I have to do is to start the application minimized in the system tray. Then the application must be listening for crtl+shift+left mouse click in any part of the desktop or an opened application, when that happens, I have to show a window asking if the user want to take a screenshot starting in the x,y point he clicked and then take the screenshot.
    What I don't know how to do is to detect the mouse and keyboard events when the application is supposed to be running minimized in the system tray.
    How can I do that? Can anybody give me a hint?
    Thanks in advance.

    It's not possible with plain Java. You will need native code for this. Take a look at JNA.

  • How to show mouse clicks when recording screen with quicktime?

    How can i show the mouse click when i record the screen using quicktime player?

    Why? What program feature do you intend to offer, by knowing what a user clicks on (besides the application itself).Hi, well what I have to do is to start the application minimized in the system tray. Then the application must be listening for crtl+shift+left click in any part of the desktop or an opened application, when that happens, I have to show a window asking if the user want to take a screenshot starting in the x,y point he clicked, once done, I have to take an screenshot...so on.
    How can I do that? Can anybody give me a hint? Thanks in advance.

  • Automator - How do I: Mouse Click, Move Windows, and more

    Hello,
    I am attempting to create my own Automator programs and for a while I had some that worked nicely. I have recently been tweaking my iMac so that it can "think" on its own (by automator of course) and do things for me. However, I've run across a block with Mavericks (I believe it's due to Mavericks).
    1. How can I get Automator to register a mouse click? "Watch me do" does not seem to want to work for me at all. I also would prefer if it would just be a registered mouse click, but not actually use the mouse (I know this is possible) so that if I'm doing something and it runs, it won't disturb my mouse and I can keep working.
    2. How can I register a keyboard stroke? Same as above
    3. How can I have automator move windows? I have two monitors and there are times when I may want it to move a window from one mintor to another
    The following is a list of all the things I'm attempting to accomplish at the moment (with other things when I think of them) with automator (either through applications, folder actions, or ical actions):
    1. Register a mouse click at a given area or on a given element in a safari page
    2. Register a keyboard stroke in a given program (be able to focus on a program and then do the keystroke)
    3. Move windows from one location to another
    4. Full-screen and Un-full-screen iTunes at certain times of day
    5. Download all purchased items on iTunes that aren't on the computer (sometimes iTunes doesn't download stuff if it was downloaded on my MacBook Pro first)
    6. Automatically voice read reminders (that I've set in Reminders) each day at a given time (I can use loop to repeat it to make sure I hear it all)
    I'll think of more of course, but the mouse click, keyboard stroke, and moving windows is the big thing I'm trying to figure out how to do. Can anyone help?
    Also, I am not a computer tech. I am tinkering with this because it's fun and helpful, but an answer of "just use applescript" or "just use java" will likely just give me a headache. I know that it's going to be one of those codes, but I'm hoping someone has a "base" code that can be copied and pasted that's just a standard click that I can adjust for where I need to click and what process I need to click on.
    If there is an Action Pack that includes a "Register Mouse Click" and/or "Register Keyboard Stroke", then that would work great, but the only action packs for automator I've seen that work with Mavericks is for photoshop.

    You're asking for a lot in one post.  It would be better to break your requests down a bit. 
    For example, to deal with mouse clicks, you can use the Automator Action Run Shell Script with this python script:
    import sys
    import time
    from Quartz.CoreGraphics import *
    def mouseEvent(type, posx, posy):
            theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
            CGEventPost(kCGHIDEventTap, theEvent)
    def mousemove(posx,posy):
            mouseEvent(kCGEventMouseMoved, posx,posy);
    def mouseclick(posx,posy):
            mouseEvent(kCGEventLeftMouseDown, posx,posy);
            mouseEvent(kCGEventLeftMouseUp, posx,posy);
    ourEvent = CGEventCreate(None);
    # Save current mouse position
    currentpos=CGEventGetLocation(ourEvent);
    # Click the "Apple"
    mouseclick(25, 5);  
    # 1 second delay       
    time.sleep(1);        
    # Restore mouse position
    mousemove(int(currentpos.x),int(currentpos.y))
    It will look like this in Automator:
    To drag something (i.e. a window, a file icon) from position 40,60 to 60,300:
    import time
    from Quartz.CoreGraphics import *
    def mouseEvent(type, posx, posy):
               theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
               CGEventPost(kCGHIDEventTap, theEvent)
    def mousemove(posx,posy):
               mouseEvent(kCGEventMouseMoved, posx,posy);
    def mouseclickdn(posx,posy):
               mouseEvent(kCGEventLeftMouseDown, posx,posy);
    def mouseclickup(posx,posy):
               mouseEvent(kCGEventLeftMouseUp, posx,posy);
    def mousedrag(posx,posy):
               mouseEvent(kCGEventLeftMouseDragged, posx,posy);
    ourEvent = CGEventCreate(None);
    # Save current mouse position
    currentpos=CGEventGetLocation(ourEvent);
    # move mouse to upper left of screen
    mouseclickdn(40, 60);
    # drag icon to new location
    mousedrag(60, 300);
    # release mouse
    mouseclickup(60, 300);
    # necessary delay
    time.sleep(1);
    # return mouse to start positon
    mouseclickdn(int(currentpos.x),int(currentpos.y));
    For keystokes in AppleScript (which can be added to Automator with the Run Applescript Action) see: http://dougscripts.com/itunes/itinfo/keycodes.php

  • How to handle mouse click event on up-arrow of JSpinner?

    Hi Everybody,
    I have a JSpinner component holding a date field in it (dd/mm/yyyy). I have handeled keyboard up and down arrow key events for the component and that's working as expected. Now I want to make it work for mouse clicks on the up (UP_ARROW_SUBCOMPONENT) and down arrow (DOWN_ARROW_SUBCOMPONENT) buttons of the component.
    Could somebody guide me how to do it? My investigatoin hints me to use JSpinnerMouseEventData but I am not exactly getting how to get it done.
    Thanks in advance!

    if you just want to add a mouseListener to the spinner's buttons, try this
    (only coded it for the up/next button)
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      public void buildGUI()
        JSpinner spinner = new JSpinner(new SpinnerNumberModel(50, 0, 100, 5));
        spinner.setUI(new javax.swing.plaf.basic.BasicSpinnerUI(){
          protected Component createNextButton()
            Component c = super.createNextButton();
            c.addMouseListener(new MouseAdapter(){
              public void mousePressed(MouseEvent me){
                System.out.println("mousie, going up");
            return c;
        JFrame f = new JFrame();
        f.getContentPane().add(spinner);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }

  • Detect mouse click in FlashPlayer ActiveX

    I'm hosting the FlashPlayer ActiveX control (Flash9f.ocx) in
    a VB 6 application. The OCX exposes the following events:
    FlashCall, OnProgress, OnReadyStateChange and FSCommand. It does
    not expose the traditional Click, MouseUp or MouseDown events (for
    example) so is there a way to receive mouse click events in the
    hosted application?
    Also, I am unable to find any documentation on the FlashCall
    event. Any ideas what it is and how it works?
    Thanks to any and all.

    jList1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    jList1_mouseClicked(e);
    public void jList1_mouseClicked(MouseEvent e){
    JOptionPane.showMessageDialog(null,"test"); }
    I got it. Thanks.
    I forgot to add the MouseListener initally

  • Detecting mouse click on a line

    I'm learning making GUI apps in Java.
    Here is my problem. Suppose I draw a line on a JPanel. If I want to find out if the line is clicked or not, what is the best way to do it?
    I did some research, looked at API. If I suppose my line is Line2D, then since its a line it doesn't have an area, so its contains method always returns false (..from API). So i dig around some more and came up with the solution of getting the shape from the stroke and calling its contains method.
    This is a code for what i mean..
    private Line2D.Double testLine;
    //mouse clicked event
    public void mouseClicked(MouseEvent e) {
            int x = e.getX();
            int y = e.getY();
            BasicStroke stroke = new BasicStroke(4);
            Shape testShape = stroke.createStrokedShape(testLine);
            if(testShape.contains(x,y)){
                System.out.println("this will be printed if clicked on line");
        }Well, the above solution works fine.
    Is it the right way of doing it or is there a better way around for this?
    Any help will be appreciated.
    Thanks.

    When trying to test if a line was pressed I usually test if the distance between the mouse coordinates and the line is smaller than some constant (usually 5 pixels).
    For this you have to write your own code to calculate the distance between a point and a line.

  • How to simulate mouse click

    Hello,
    is it possible to simulate and control a mouse click in windows with labview 7.1. I am able to control the mouse coordinates but not right and left mouse click. Is there a available VI that can do that?
    Lukas

    I have answered this in the other thread where you asked this. Please don't post the same questions to multiple threads.
    After looking at the VI there, it uses the PostMessage function to post a mouse down message to a specific window. You can try using MouseEvent or SendInput to simulate a general mouse click (One of them is no longer supported, I can't remember which. You can find the details in the MSDN).
    Try to take over the world!

  • How to disable mouse click ??

    hi ,
    i have a form in which i have a block abc in this there are 5 items say a,b,c,d,e
    suppose my cursor is in item field 'a' there i have entered some value then i go to item field b and entered some value and then i go to field c without any enter or tab but with the help of mouse only. there i want to put a trigger on block level ( on-mouse-click) that whenever anyone tries to move from the current field to another field with the help of mouse then the cursor should be moved to previous item automatically that is item 'b'. in breif i want to disable mouse click from moving one field to another.
    on-mouse-click i can store system.current_item i.e 'a' but not able to store previous field i.e 'b'.
    please help....
    thanks
    Edited by: Hi FRNzzz!! on Feb 23, 2010 7:10 PM

    Hello,
    Try to set the mouse navigation limit form-level property to item when you want to disable the mouse.
    Francois

  • How to unbind mouse click 4&5 on firefox, because I use taht for an other software ?

    I want to unbind mouse click 4 & 5 on firefox.
    Because I use this buttons fort "Mumlble (chatvocal)"
    When I click on my button 4 or 5 of my mouse, firefox goes to the previous or next page. Can you help me please ?
    (I want not change my bind on mumble, it for that I want delete the button 4 & 5 of my mouse on firefox)

    Try http://www.highrez.co.uk/downloads/XMouseButtonControl.htm - X-Mouse Button Control

  • Detect when mouse clicked over desktop

    hello guys,
    i have a graduation project working with networking, the instructor on the server side presents a powerpoint slide show an when he moves to the next slide, i have to send an order to the students (clients) to move to the next slide.
    can it be done???? plz if there is an example for both; the sender and receiver help me with it.
    tahnk you very much.

    http://forums.devshed.com/t311756/s.html
    http://forums.devshed.com/t311567/s.html
    http://forums.devshed.com/t311568/s.html

  • How Convert a mouse click (X,Y) to Java3d virtual World???

    i have a mouse event and i like to convert this to a world (X,Y,Z) coordinate
    i am try using getPixelLocationInImagePlate, getImagePlateToVworld and getCenterEyeInImagePlate methods, but i have only the X axis, the z axis got fixed in the camera position...
    same code example?
    Edited by: luizrd on Feb 12, 2008 12:59 AM

    luizrd wrote:
    you say to use pickcanvas, but in this case, this dont work, the pickcanvas dont return the position of a empt location (i think) and i need to get the position of a click....
    for add a line in the canvas in the mouse position...How are you going to get the postition of some point that not only doesn't exist, but could be returned as an infinte number of postitions along a vector. In other words, you can't do what you're talking about.

  • How to detect mouse move

    Hi Guys and Gals out there,
    Actually I've problem with mouse. I think I better explain a little bit my situation down here.
    I have an Image with a few signatures, and I want user get every signature to apply on my form then I'm going to save that signature with personal data for every signature. Normally what we did is we select the signature (image) with mouse. But the problem is I don't know how... I really hope that some what who did it before could help me in this problem..... I'm sorry because I still new in Java....
    Thanks in advance,
    -Lee-

    Hi Lee
    Look at this program, it have 2 Components on the frame, lai is the 'big Image' and t2 is the Rectangle.
    The mouseListener is added to 'lai' and the location of 't2' is changed when the mouse is dragged. when the mouse is released i create a new bufferedImage and draw a piece of the 'big Image' into it.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    public class Signi extends JFrame
         Image         map;
         TheMap        lai;
         TheSq         t2;
         BufferedImage sigB;
         Graphics      sigG; 
    public Signi() 
         getContentPane().setLayout(null);
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);}});
         setBounds(10,10,700,530);
         t2  = new TheSq();     
         getContentPane().add(t2);
         lai = new TheMap();      
         getContentPane().add(lai);     
         lai.addMouseListener(new MouseAdapter()     
              {     public void mouseReleased(MouseEvent m)
                        sigB = new BufferedImage(t2.getWidth(),t2.getHeight(),BufferedImage.TYPE_3BYTE_BGR);
                        sigG   = sigB.createGraphics();
                       sigG.drawImage(map,0,0,t2.getWidth(),t2.getHeight(), 
                                         t2.getX(),t2.getY(),
                                             t2.getX()+t2.getWidth(),t2.getY()+t2.getHeight(),null);
         lai.addMouseMotionListener(new MouseMotionAdapter()          
              {     public void mouseDragged(MouseEvent m)
                        t2.setLocation(m.getX(),m.getY());
         setVisible(true);
    public class TheMap extends JComponent
    public TheMap()
         map = getToolkit().getImage("map1.gif");
         MediaTracker tracker = new MediaTracker(this);
         tracker.addImage(map,0);
         try   {tracker.waitForID(0);}
         catch (InterruptedException e){}
         setBounds(2,2,map.getWidth(null),map.getHeight(null));
    public void paint(Graphics g)
         g.drawImage(map,0,0,null);
    public class TheSq extends JComponent
    public TheSq()
         setBounds(1,1,120,60);
    public void paint(Graphics g)
         g.setColor(Color.red);
         g.drawRect(0,0,getWidth()-1,getHeight()-1);
    public static void main (String[] args) throws InterruptedException
         Signi fr = new Signi();
          if you like i can email the code to you.

Maybe you are looking for