CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Talking Detecting Changes in Cursor

    Hi everybody!
    I am using the robot class to move the cursor across the screen. Is it possible for my java program to detect a change in cursor shape or color as the cursor moves across an open window where the non-java program controlling that window is the source of the change to the cursor?

    If it is possible...how do you do it? My research so far tells me that it cannot be done.

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: Detecting Changes in Cursor

    Well, if the Java program has focus then you could always have a thread running in the background that gets the cursor position every so often, say once a second, and performs some action when it sees a change in position. You can use the following at any time in order to determine the cursors position.

    Code:
    PointerInfo a = MouseInfo.getPointerInfo();
    Point b  = a.getLocation();
    int x = (int)b.getX();
    int y = (int)b.getY();
    This thread running in the background could have some class variables that hold the current position and then you could compare the X and Y values to see if it has moved.

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Detecting Changes in Cursor

    AFAIK You can't detect changes in the cursor shape or colour once it is outside of a Java Window, unless you query the OS.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  4. #4
    Join Date
    Feb 2010
    Posts
    2

    Re: Detecting Changes in Cursor

    Thank you very much for the replies to my question. I guess I just have one final question: Is it possible for a java program to query the OS regarding the cursor color or shape? If so, how is it done?

  5. #5
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Detecting Changes in Cursor

    Yes you can query the OS but it's not straightforward. You need to find out what system calls are available to you and then you can call them via a wrapper using JNI.

    There are plenty of tutorials on using JNI, but if your really lucky someone may have already had and solved your problem and posted the code so I'd advise a good search before writing it yourself.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured