LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: Mickelukas on May 21, 2009, 10:07:28

Title: [FIXED] Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 21, 2009, 10:07:28
Hi there,

If I hold down a mouse button while moving the mouse outside my applet Mouse.isbuttondown still returns true even if I release the mouse. If I after that move the mouse back inside the applet it still says that the mouse button is down even though it isn't.

I could make a workaround for it if there was a function to check whether or not the mouse is inside the applet but the Mouse class doesn't have that functionality.

Any ideas?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Ciardhubh on May 21, 2009, 13:16:06
It's probably an OS/driver restriction you have to handle yourself. If the mouse is outside the window, the OS most likely doesn't send events to the application. Lots of game engines have trouble with input when loosing focus.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 21, 2009, 15:01:00
Standard windows driver and windows xp. Probably the most common combination there is.

I could fix it if I were able to add the standard java mouselistener to the applet but when I do it doesn't get any events at all.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 23, 2009, 11:58:49
No workaround/solution for this? What about the possibility to catch the mouseevents from java seeing as they have mouse entered and mouse exited?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: kappa on May 23, 2009, 14:40:03
as with the above mentioned post this behaviour only happens with windows, what most games do to get round this is they grab the mouse Mouse.setGrabbed(true) or Mouse.setCursorPosition(middleOfScreenX, middleOfScreenY), so it can't leave the window, an example of this behaviour can be seen at http://www.minecraft.net
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 23, 2009, 17:15:08
Well, half or so of my game is played outside the applet and half inside meaning that you will need to be able to move the mouse outside of the applet.

Is there no workaround to access the java mouse listener?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: kappa on May 23, 2009, 17:27:22
you can't really use the java mouse listener since LWJGL's Display is not an AWT/Swing component. You could use LWJGL's AWTGLCanvas container but then you would loose significant performance.

You could also use the AWT Robot but then this would require signed permissions.

one thing that comes to mind is that you could use javascript to detect if the mouse is outside the applet, that way you can alert the applet using using liveconnect.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on May 23, 2009, 17:54:32
It still sounds like something that lwjgl may be able to handle - but is it a windows only issue ?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: kappa on May 23, 2009, 18:24:22
can't speak for mac or solaris, but linux correctly detects mouse button release when outside the applet Display, while on windows it does not.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 23, 2009, 20:07:05
one thing that comes to mind is that you could use javascript to detect if the mouse is outside the applet, that way you can alert the applet using using liveconnect.

This was how I was going to solve it if it wasn't possible for you guys to see what causes it. I don't like that kind of workaround though seeing as it brings alot of combinations of webbrowsers/OS' that might cause problems.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 25, 2009, 07:55:45
It still sounds like something that lwjgl may be able to handle - but is it a windows only issue ?

Did you get an epiphany regarding this issue? :) If it would be possible to get it fixed in 2.2 then I don't have any more open issues after my merge from JOGL to LWJGL.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 27, 2009, 09:33:19
Still no clue about this one?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on May 27, 2009, 09:36:30
I comitted a fix yesterday. Nightly failed (missing import) but hopefully it should all be good tonight - pending tests.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 27, 2009, 11:27:25
Cool :) If you get rid of the security alert and release 2.2 I'll definately donate some money as thanks for all the bug fixing :)
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on May 27, 2009, 13:12:52
well, it seems that there are some issues still - so need to look at bit on that - not sure if I have time tonight tho...
lwjgl 2.2 will happen eventually - but the certificate stuff is out of my hands, and moving at an invisible snails pace.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on May 27, 2009, 13:31:53
well, it seems that there are some issues still - so need to look at bit on that - not sure if I have time tonight tho...
lwjgl 2.2 will happen eventually - but the certificate stuff is out of my hands, and moving at an invisible snails pace.

So it might be moving quite quick as it is invisible eh? :P

Well, I'm fine with the certificate question while developing the game but it would be cool to have it fixed once I launch a beta :)
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on June 07, 2009, 13:00:54
Had the time to look into the windows issue?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: kappa on June 07, 2009, 13:16:02
Matzon has found and fixed the mouse issue on windows, patch is in svn.

You can find a working example of it in action here (http://bossattack.com/games/gearsapplet/GearsApplet.html)
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on June 07, 2009, 17:32:54
It's working wonderfully :) Thanks a bunch!
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on September 07, 2009, 12:44:35
I had to download the nightly build for another problem so ended up testing this on my own application.

I have a problem that might not be easily fixed. When I hold down the mouse and move it to a negative X or Y (outside the applet below or to the left of it), the Mouse.getX() and Mouse.getY() never goes below 0 so I don't know if it is just outside the corner or a kilometer outside.

Any ideas?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on September 09, 2009, 12:26:25
I tried to work around it myself but I guess it needs to be changed within LWJGL (preferably before 2.2.0 :)). Is something difficult to fix or can you easily pass negative numbers?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on September 22, 2009, 09:03:05
No ideas about this?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on September 22, 2009, 09:37:58
fixed in nightly I think
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on September 25, 2009, 08:29:03
fixed in nightly I think

You're my hero Matzon! I'll download the nightly later today or on Monday to check it out :)
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on October 12, 2009, 09:29:30
Work got in-between... I tried it out now and I get the same behavior as before. When moving the mouse to where I'd expect a negative x or y value it just returns 0.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on October 12, 2009, 13:51:53
oh, forgot this:
/doc/lwjgl_hidden_switches.text - added a new allowNegativeMouseCoords

otherwise we might risk breaking things that rely on non-negative value

http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/doc/lwjgl_hidden_switches.text?r1=3241&r2=3240&pathrev=3241
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on October 12, 2009, 14:38:46
Works like a charm in Eclipse but not in the browser.

I get following error during startup:
Code: [Select]
Fatal error occured (8): access denied (java.util.PropertyPermission org.lwjgl.input.Mouse.allowNegativeMouseCoords write)
java.security.AccessControlException: access denied (java.util.PropertyPermission org.lwjgl.input.Mouse.allowNegativeMouseCoords write)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at dreamlandz.Main.init(Main.java:83)
at org.lwjgl.util.applet.AppletLoader.switchApplet(AppletLoader.java:765)
at org.lwjgl.util.applet.AppletLoader.run(AppletLoader.java:643)
at java.lang.Thread.run(Unknown Source)

Do I need to sign the whole package with the same certificate to make it work as that would not be very appreciated. Would it not be possible to make a setter and getter for the value within the Mouse.java file instead of reading the "secret" value.

I had to figure out how to set it but if someone wants to do it and reads this just edit the initiation part of your program and add this:

Code: [Select]
System.setProperty("org.lwjgl.input.Mouse.allowNegativeMouseCoords", "true");
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on October 13, 2009, 07:58:55
I first wrote that it worked because I had only tested it in Eclipse and then I updated the post. You were online at the time Matzon so I'm no sure you saw the update. Therefore this post.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: kappa on October 13, 2009, 08:14:28
you could try using -Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true as a java vm argument.

for an applet that'd be <param name="java_arguments" value="-Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true">

not tried it but it might work.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on October 13, 2009, 11:30:39
I added it to my arguments list making it look like this:

Code: [Select]
<param name="java_arguments" value="-Dsun.awt.noerasebackground=true -Dsun.java2d.noddraw=true -Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true -Dsun.java2d.opengl=false -Dsun.java2d.pmoffscreen=false -Dsun.java2d.d3d=false">
Then the applet does load but I don't get any negative mouse coords.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on October 13, 2009, 12:07:52
you could add some debugging to see whats going on...
could be applets that behave differently
Title: Re: Mouse.isbuttondown not updating correctly
Post by: kappa on October 13, 2009, 12:42:52
I think but not entirely sure that the Applet SecurityManager does not allow you to change System Properties (System.setProperty) unless its explicitly one of the exceptions. That could explain the current behaviour.

A possible solution (other than signing your applet) would be to have a publically exposed API in LWJGL e.g. Mouse.enableNegativeCoords(boolean). Technically its not just unlocking negative coords but any coords outside the Display, so could also be something like Mouse.clipCoords(boolean), Display.clipMouseCoords(boolean), etc.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on October 13, 2009, 13:01:29
A possible solution (other than signing your applet) would be to have a publically exposed API in LWJGL e.g. Mouse.enableNegativeCoords(boolean). Technically its not just unlocking negative coords but any coords outside the Display, so could also be something like Mouse.clipCoords(boolean), Display.clipMouseCoords(boolean), etc.

*wink* *wink* Matzon? *wink* *wink*
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on October 27, 2009, 16:12:27
Need more winks? ;) *wink* *wink*
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on August 20, 2010, 20:50:10
I'll go on with winking at you Matzon :) *wink* *wink*
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on August 21, 2010, 08:33:32
I'll go on with winking at you Matzon :) *wink* *wink*
;) I had forgotten all about this thread. I will look into it soon - but I'll be drunk tonight, so I think I'll wait till tomorrow.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on August 21, 2010, 16:38:02
;) I had forgotten all about this thread. I will look into it soon - but I'll be drunk tonight, so I think I'll wait till tomorrow.

Lol, have a nice evening :)

I put the programming on hold for a year and just started up again three or so weeks ago with motivation again so no rush :)
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on August 23, 2010, 18:45:27
several of the flags are initialized statically. So setter methods may or may not have any effect, depending on how stuff is initialized :/
not sure how to handle this ...
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on August 24, 2010, 05:42:37
several of the flags are initialized statically. So setter methods may or may not have any effect, depending on how stuff is initialized :/
not sure how to handle this ...

It doesn't matter that they are static as long as they aren't final, right? But I barely know any Java, how I managed to make this much of a game is just because I'm stubborn and spent more than a thousand hours :P
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Matzon on August 24, 2010, 07:46:35
several of the flags are initialized statically. So setter methods may or may not have any effect, depending on how stuff is initialized :/
not sure how to handle this ...

It doesn't matter that they are static as long as they aren't final, right? But I barely know any Java, how I managed to make this much of a game is just because I'm stubborn and spent more than a thousand hours :P
The problem is that the flags are set in static initializers - and passed down to native code. So if you change then after, then differnet parts of the code will not be told about the value change.
I'll look into how and if we can change that behavior.
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on August 24, 2010, 21:38:56
Ah, right, thanks for the explanation. Maybe give the option to set such things before creating the OpenGL context and not allow them to be changed afterwards?
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on September 29, 2010, 20:12:39
It wasn't as easy as I'd have hoped eh?

Oh, and as thanks for you all answering my weird questions and bugs without snapping at me I made my first donation :-)

Mike
Title: Re: Mouse.isbuttondown not updating correctly
Post by: Mickelukas on November 07, 2010, 15:58:12
More than 6.000 views :) Was the conclusion that it wasn't possible so you need to sign applets if you want to use it a non gripping mouse?

Mike
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Mickelukas on January 09, 2011, 21:17:15
Getting close to 7.000 views :), Matzon?
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Matzon on January 10, 2011, 06:18:56
Getting close to 7.000 views :), Matzon?

heh, honestly, haven't looked at it. However the main problem still remains. The options are really meant the be static, which it is passed as VM parameters.

Since this is an applet specific issues, I am thinking about being able to set lwjgl specific (or at least generally specific) parameters through out applet loader, since that is signed. kappa, does that make sense?
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: kappa on January 10, 2011, 10:18:22
Since this is an applet specific issues, I am thinking about being able to set lwjgl specific (or at least generally specific) parameters through out applet loader, since that is signed. kappa, does that make sense?

Ah yes (pretty genius), that would work since it'll be done before any LWJGL classes start running and not require the user to sign their own jars to do it. It would be almost on par with setting VM parameters. Would need to make sure which parameters are allowed though if its going to be a general solution. Does sound good though and likely to work well.
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Matzon on January 10, 2011, 14:13:30
so, all properties beginning with org.lwjgl should be allowed.
What else?
some of the directdraw / opengl com.sun variants?
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: kappa on January 10, 2011, 14:29:12
so, all properties beginning with org.lwjgl should be allowed.
What else?
some of the directdraw / opengl com.sun variants?

org.lwjgl should be fine, don't think we need any other properties. Plugin2 pretty much covers most the stuff that might have been useful like setting vm memory size, etc. The java2d directdraw and opengl issues don't apply any more to LWJGL since the move to Display.setParent() which completely bypasses the issues, besides there are already applet parameters available to handle those. Can't think of anything else that might be useful, so yeh, org.lwjgl should be fine.
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Mickelukas on January 10, 2011, 19:27:59
Wuhuuu, I see a fix on the horizon :)

Almost getting ready to starting blogging/discussing my game, just need another month or so and it'll actually be a game and not a simulator of sorts so this would be great.

Mike
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Matzon on January 10, 2011, 21:56:11
I have added parsing of java_arguments for org.lwjgl* properties in the applet loader.
Please try the next nightly (> 1011)

usage:
  <param name="java_arguments" value="-Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true -Dorg.lwjgl.util.Debug=true -Dorg.lwjgl.opengl.Display.allowSoftwareOpenGL=true">
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Mickelukas on January 11, 2011, 14:51:56
Matzon,

I downloaded the newest nightly (1012) and tried it both in my own applet and in the gears applet that comes with the lwjgl_applet but neither allows negative mouse coordinates when that parameter is added.

Kind regards,
Mike
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: kappa on January 11, 2011, 15:43:25
are you able to get any value from inside your applet for the value System.getProperty("org.lwjgl.input.Mouse.allowNegativeMouseCoords") ? or does it return null?

haven't got time to test atm but would make life easier if you can confirm from an already working setup.
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Mickelukas on January 11, 2011, 18:01:42
Running in the applet viewer it returns true (as expected as it always used to work)

Running in a normal applet with or without the argument gives the following:
Code: [Select]
access denied (java.util.PropertyPermission org.lwjgl.input.Mouse.allowNegativeMouseCoords read)
access denied (java.util.PropertyPermission org.lwjgl.input.Mouse.allowNegativeMouseCoords read)
java.security.AccessControlException: access denied (java.util.PropertyPermission org.lwjgl.input.Mouse.allowNegativeMouseCoords read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at client.Main.init(Main.java:294)
at org.lwjgl.util.applet.AppletLoader.switchApplet(AppletLoader.java:1011)
at org.lwjgl.util.applet.AppletLoader.run(AppletLoader.java:767)
at java.lang.Thread.run(Unknown Source)

But I guess that's to expect as well seeing as it isn't my applet that should be allowed to read the values but the applet loader, right?

Mike
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: kappa on January 11, 2011, 19:06:02
But I guess that's to expect as well seeing as it isn't my applet that should be allowed to read the values but the applet loader, right?

yes, mean't from a signed jar, so you'd have to sign your jars to test it, thought you might already have such a setup.
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Matzon on January 11, 2011, 20:55:34
apparently, using java_arguments was a bad idea since the JRE strips arguments from it :/
so, fixed it by using lwjgl_arguments instead. Tested locally and works as expected :)

Please get the next nightly build (> 1012)
Title: Re: [RFE] Mouse.isbuttondown not updating correctly
Post by: Mickelukas on January 12, 2011, 21:23:37
Yay, you're the best Matzon, I'll test it tomorrow :)

Mike
Title: Re: [FIXED] Mouse.isbuttondown not updating correctly
Post by: Mickelukas on January 13, 2011, 12:31:01
Yay, it is fixed, thanks :-D