Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

random mouse pointer movement  RSS feed

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, is there anyway to write a program that will move the mouse

cursor around on the screen?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats awesome man, i appreciate it, but i was asking if it could randomly move it on the desktop.... without having to open a window...

see what i mean? and randomly click on the desktop??


thanks,

Justin
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's a non-gui version (if that's what you're after?)

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i tried to modify the code to click everytime it moved, im getting

a IllegalArgumentException, about the buttons...



i dont understand why im getting this exception...

C:\Documents and Settings\Owner\Desktop>java COB
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Inval
id combination of button flags
at java.awt.Robot.checkButtonsArgument(Unknown Source)
at java.awt.Robot.mousePress(Unknown Source)
at Testing$1.actionPerformed(COB.java:28)
at javax.swing.Timer.fireActionPerformed(Unknown Source)
at javax.swing.Timer$DoPostEvent.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)



please help,



Justin
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
worked OK for me, after changing
public static void main(String[] args){new Testing();}
to
public static void main(String[] args){new COB();}

I added a panel to the contentPane, and a mouseListener to the panel.
all worked - the mouseListener received the mousePressed events.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol i forgot about the Testing -> COB...

ill fix it and see if it does what i want...

thanks,


Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok I have it moving randomly and clicking within a 800x600 space..

ok, now say the mouse moves over a icon or object, and the cursor changes(either icon or shape).

is there a way to detect that in java??

and capture that event and do an event in return to any other "changing"

of cursor's.


in other words... the cursor has a stantard look and shape,

have some method to set the current shape.

and then another method to detect when that "set" cursor changes?

Thanks,

Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or better yet, say you move your mouse on to some object, and

a name pops up over the object, can you capture that? preferably the name?


Justin
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the Toolkit class? There might be something in there that will work.

If not, you might have to call the underlying OS API's yourself, but it will break platform independance.
[ August 28, 2006: Message edited by: Rusty Shackleford ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does that mean windows API?

i need the Java GUI to do the work though..

umm... because i click on the "start bot" button, and it starts

randomly clicking, every 6 secs...

i would rather it find a "monster" then click on it, so there would

be no chance that you'll never click on one lol..

because when it clicks, it will be in the current game window...

so it will move the character around..

I'm just curious to know if there is a method to pick up the name of the

monsters... becaue when you put your cursor over the monster, the name

pops up..

thanks,


Justin
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are the monsters, are they images in JLabels?

can you add a mouseListener to them?

forgetting the robot part for the moment, can you get what you want to happen
if you manually move the mouse pointer across a monster?
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
umm, yeah, I personally, can move my mouse over a monster and it's name and

level will display...

like for instance "RedDevilL117" without quotes tho.

i looked in the toolkit, but i was thinking maybe using a cursor object

to store the original cursor, which is a straight sword, and when you move i

over a creature, it turns into a curved blade.

is there a way to tell whether or not the cursor icon changes??

thanks dunn,


Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhh, see this is a separate game, i just have the applet minimized, and

the cursor still moves and clicks randomly, but in the actual game window,

so it's almost like a player simulation...a.k.a "Bot"..

see what i mean?


Justin
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am curious, why are you calling it an Applet?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
might be the time to post a sample working program.

just a single monster showing what happens when the
mouse is over her (him?).

then describe how it is to differ if the robot moves
the mouse to that same position.

for your cursor query,
getCursor().getName();
should do what you want
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol i dont know, I just call it that, cause it pops up lol,

I mean the JFrame, or JPanel... but i'm curious too, can you view an

"APPLET" in a JFrame, instead of using a JPanel?

and if so, can you still do the....




because if that's the case, i would rather do that, cause I

can draw and add buttons and miscellaneous things like that..

Thanks,

Justin

and for you're question about the "time to show some sample code"

well, the code where the "JFrame" pops up and has the two JButtons..

"Start bot" and "Stop bot" is as far as i've gotten..

you see in that application the mouse moves and clicks randomly ever

6 seconds... but when i minimize the JFrame, the mouse still clicks on the

actual game window ( I did'nt program the game, it's called conquer online.)

but the thing is, if i'm just randomly clicking and moving in the game,

there is a chance that i'll never hit a monster, so I will in fact, not

level up.

now, in the game, the cursor is a little sword.

and if you drag the cursor over a monster, it's name and level will

pop up above its head.

so the main question was, is there any way to get that name and lvl text,

with some java tool/class?

the name a level of the monster is almost like a "tooltiptext", actually

almost exactly like it, except it pops up above the "monster".



because if i could just scan the whole window for a monster before i click

that would be much more efficient...

thanks,



Justin
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're trying to interact with your browser, to automate the playing of an online game?

if so, perhaps the Applets forum might be a better place to find a solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!