Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Virtual Cursor?

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Virtual Cursor?

    Imagine this: You make a simple game using a contained within a JFrame. The game is played by moving your mouse around and clicking on different things.

    Can you then make a virtual mouse to interact with that game that will not interfere with your normal cursor actions, and only do things within the JFrame. Like you could browse the web while it is running and it wouldn't interfere.

    Note: This has nothing to do with interacting with the game objects in code directly, but simple a virtual mouse overlay to interact with it in a simulated way.

    --- Update ---

    This was also mention in a similar thread here: http://www.javaprogrammingforums.com...awt-robot.html


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Virtual Cursor?

    What is supposed to make the virtual mouse cursor move? You mention that you could be using the real mouse for something else like browsing. Not that it really affects your question, but I was wondering. Will it be following some logic of its own? or responding to other events like keystrokes?

    In any case I don't think you can rely on the OS to help you. What I mean is that the real mouse will be interacting with the web browser or whatever and, as far as the OS is concerned, that is what your mouse is doing. Your game application will simply not receive any mouse event information.

    Your game will, therefore, have to be prepared to interact with events generated by the virtual mouse. So perhaps "this has nothing to do with interacting with the game objects in code directly" needs to be clarified. Surely everything that affects the game's state arises because of interactions with the game objects reflected in the code of the game, those objects and whatever it is that initiates the interactions.

    There may be some way of programatically sending the game application mouse or keyboard input even while some other application has focus. (and without that application permanently losing focus) But that would seem to be some OS specific question and, as such, not one really suited to finding an implementation in Java.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Virtual Cursor?

    Sorry if I was not clear enough. The cursor would be pre-programmed similar to a macro to do a series of events. But the code running that cursor will not be able to interact with, or modify, any of the code of the game. Almost like a overlay the size of the JFrame that can imitate clicks to for objects below it, but it would be virtually controlled with pre determined actions, if that makes sense.

    --- Update ---

    Also I think you might be able to do with MouseEvents that are created with the MouseEvent(), but I don't know how to send them to a component or get the component to act upon that MouseEvent.

    --- Update ---

    In Other word this is a Virtual Robot that will no take control of the mouse. And it would be beneficial if it could run without focus.
    Last edited by cgskook; May 18th, 2013 at 08:41 AM. Reason: grammer

  4. #4
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Virtual Cursor?

    Bump?

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Virtual Cursor?

    There is no need to "bump" a post.
    Every post is read by multiple people.
    When someone has some advice they will post on your thread.
    Have you looked at the robot class?

  6. #6
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Virtual Cursor?

    Quote Originally Posted by jps View Post
    There is no need to "bump" a post.
    Every post is read by multiple people.
    When someone has some advice they will post on your thread.
    Have you looked at the robot class?
    Well either you have never used the robot class or your clearly don't understand what I mean, the whole point is not to take control of the mouse in the OS, but to create a virtual (secondary) one.

  7. #7
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cursor emulation in java

    Simple: I want to be able to have a cursor only controlled by programming that is separate from the cursor controlled by my mouse.

    keywords "SEPARATE FROM THE CURSOR CONTROLLED BY MY MOUSE" so I would appreciate it if you don't mention the Robot class unless it has to do with creating mouse events to send to the "virtual cursor".

    I say this because it never seems like people understand what you are trying to do.

  8. #8
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Cursor emulation in java

    Consider using Robot. Actually, there was a topic on this forum about this.

  9. #9
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Cursor emulation in java

    What?

  10. #10
    Junior Member
    Join Date
    May 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cursor emulation in java

    You have now turned this into a joke...[COLOR="Silver"]

  11. #11
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Cursor emulation in java

    Oh, I'm really sorry, man, haven't read your post patiently. Then most likely you'll have to use JNI. There's some library, take a look. Even if that's only for listening, you can combine it in an appropriate way with Robot, so that each time a user moves mouse the event is intercepted by the lib and the mouse is forced to stay on it's position with Robot.

  12. #12
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Virtual Cursor?

    Please do not double post your question.
    Threads merged

    Try explaining what you have tried, and why said attempt was not satisfactory.

Similar Threads

  1. Replies: 2
    Last Post: May 2nd, 2013, 03:35 AM
  2. help creating a virtual Object
    By mickey2012 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2012, 12:38 AM
  3. Virtual Developer Day
    By newbie in forum The Cafe
    Replies: 2
    Last Post: March 6th, 2012, 04:13 AM
  4. Virtual Keyboard in Java
    By Brian in forum Java Theory & Questions
    Replies: 2
    Last Post: June 2nd, 2010, 11:35 PM
  5. changing the splitpane's cursor
    By chronoz13 in forum AWT / Java Swing
    Replies: 2
    Last Post: February 8th, 2010, 12:11 PM

Tags for this Thread