[java] how do I ask permission to use the robot?

Started by
3 comments, last by SimonForsman 17 years, 4 months ago
I need to use the robot for my game applet, to keep the mouse cursor inside of the applet. I absolutely have to use the mouse. What can I do to get/ask permission from the user to use the robot? Right now, the applet crashes because it can't get permission to use it. SOMEONE here's got to know how to do this... thanks in advance, Eric
Advertisement
umm . . . what?

you need to be a lot more specific . . .

what is this robot? Why do you have to keep the mouse inside the applet? Why not just make the user do that?

Ill try to offer some help from what I think your saying . . .

For permissions, are you sure your variables are at the right level of privacy? public/protected/private?

Or are you saying that you need permission to take over the mouse? In that case, you could just get control, then make the mouse cursor invisible, then have an image of a mouse cursor & just move that yourself.

I dont know if thats what you need, but you need to be more specific in your problem . . .
I never had that need before, but here goes nothing: there's a doPriviledged() method somewhere that you can override. Whatever you put into that code won't be checked for security permissions, but I'm sure there are exceptions. Browser google with that as a keywork beside java applet, and you're sure to get more insights on that.

Hope it helps,
Rodrigo
a.k.a javabeats at yahoo.ca
I'll look into that when I get the chance Son of Cain.

Quote:what is this robot?

java.awt.robot. It does other things, but its the only way of controlling the cursor's position.
Quote:Why do you have to keep the mouse inside the applet? Why not just make the user do that?

Say you're playing an FPS game. (Not what I'm making, but its a good example). You move your (invisible) cursor to the left or right to turn. Everything seems hunky-dory until your cursor leaves the applet. The applet can no longer receive mouse-move envents because of this. So you put your cursor back into the applet space. Problem is, you didn't finish turning. You want to keep turning in the same direction you started, but you can't, because your cursor keeps leaving the applet. Trying to keep the cursor inside the applet yourself won't do any good, because every movement you make with the cursor causes you to move in the game. Say you were moving left, and your cursor leaves the applet. So you try to move the cursor back to the center of the applet, but all that does is turn your dude rightwards, undoing the left-wards movement you were trying to do. Is this making sense now?

Quote:make the mouse cursor invisible

already doing that. Its visibility is not a problem.

Quote:I dont know if thats what you need, but you need to be more specific in your problem . . .

My bad, I'll try to be more specific. I had a problem much like the example I gave above. I solved it with the robot. At least, it worked when I used the "emulator" that Eclipse comes with. But when I tried it using a browser, the applet failed to initialize. Why? Well, I looked at the console, and it said this:
Quote:
java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.awt.Robot.checkRobotAllowed(Unknown Source)
at java.awt.Robot.init(Unknown Source)
at java.awt.Robot.<init>(Unknown Source)
at SpaceSoccer.init(SpaceSoccer.java:127)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-SpaceSoccer.class" java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

some security problems can be solved by using a signed applet.

The java.awt.Robot object allows code to generate native-level mouse and keyboard events as well as read the screen. It could allow malicious code to control the system, run other programs, read the display, and deny mouse and keyboard access to the user.

http://forum.java.sun.com/thread.jspa?forumID=63&threadID=524815

(info on how to sign your applet)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement