Java Setting the java.library.path property for LWJGL (Java)

  • Thread starter Thread starter 0rthodontist
  • Start date Start date
  • Tags Tags
    Java
AI Thread Summary
Detecting clicks outside a Java program's window is not feasible due to limitations in the Windows event system, which does not send events from other applications. While the java.awt.Toolkit.addAWTEventListener method is available for global event listening, it does not register clicks outside the Java application. The LWJGL library offers a Mouse class that can detect mouse button states, but users are encountering issues with configuring the java.library.path correctly to include necessary native libraries. Properly setting the library path is crucial for resolving UnsatisfiedLinkError, and users are advised to ensure the correct directory is specified when launching the application. Ultimately, achieving this functionality may require non-Java solutions or additional platform-specific code.
0rthodontist
Science Advisor
Messages
1,229
Reaction score
0
I would like to be able to detect a click anywhere on the screen, not associated with any particular screen component, and in fact inside another program's window. I don't know if I can use the listener framework to do that--if I can, I don't understand how. Can I get a whole screen object to which I can attach a listener?
 
Technology news on Phys.org
What OS are you using?
 
Windows XP
 
AFAIK, there is no way to detect clicks anywhere on the screen, outside your Java program's windows. The Windows event system won't even send your program events which occur outside its windows.

- Warren
 
Some hunting turns up java.awt.Toolkit.addAWTEventListener(AWTEventListener listener, long eventMask) which says it operates globally. However, Toolkit is an abstract class and it doesn't have any subclasses listed. Do I have to extend it? It has what looks like 20 or 30 abstract methods. How could it possibly be used for anything if it has no listed subclasses? Not that I object to writing 20 blank method definitions, but it seems strange that what looks like a critical class is abstract and never subclassed in the Java API.
 
Use Toolkit.getDefaultToolkit() to get the system's Toolkit. You cannot create your own Toolkit, as its subclasses are private (and platform-dependent, I believe).

I remain skeptical that you'll be able to see events which are not in your own programs' windows, but I have not done any experiments to the effect.

- Warren
 
I don't know. Earlier I found that it IS possible when using .NET framework in Java or Visual Basic (there are some example programs). The procedure in that case is to repeatedly poll the state of the mouse buttons. This program however does not work:

Code:
import java.applet.Applet;
import java.awt.AWTEvent;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;

public class MouseKnow  extends Applet implements AWTEventListener
{
	static int clicknum = 0;
	
	public void init()
	{
		Toolkit t = Toolkit.getDefaultToolkit();
		MouseKnow m = new MouseKnow();
		t.addAWTEventListener(m, Long.MAX_VALUE);
	}
	
	 public void eventDispatched(AWTEvent e) {
		 System.out.println("click " + ++clicknum);
	 }
}

This should register all events because of the 111...111 mask, and it does register many events, but it does not register external clicks. In fact it does not register any event, i.e. key presses, that occur when the applet window is de-focused, although it does register them inside it.


Maybe there is a way in non-.NET Java to poll the mouse buttons?
 
Last edited:
Like I keep saying, there's no way to do this from within Java itself. Java is platform-independent, and does not include any ability to gather events outside of its own windows. Gathering such events would be different on Windows, Mac, and X.

If you want to get events from outside your own windows, your Java program is no longer platform-independent, and is no longer going to be pure Java.

- Warren
 
Well, it apparently can be done in .NET framework. I just don't have .NET.

I don't care whether it's "pure" java or not. I just want to get the job done. In fact, I would not object to using an entirely different language, so long as it is not too complicated and the language is free for download.

Any kludge would work. If I could somehow (using some plugin) get the pointer to change color briefly when I click, that would be an acceptable solution. If worst comes to worst I could use the highlight-pointer option in Windows that draws a converging circle when I press ctrl--hard to manage and not exactly a click, but close enough.
 
Last edited:
  • #10
Well, if it's not pure Java, it will only run on one kind of operating system. If you use .NET, it will only be usable on Windows. I don't know whether or not this matters to you, but most people would not choose to develop in Java unless platform independence is important.

- Warren
 
  • #11
Platform independence doesn't matter to me. I'm only making this for myself.
 
  • #12
I found something that looks promising for use within Java (though it does use native Windows code, not that that matters to me):
http://www.lwjgl.org/download.php

This has a Mouse class that has a static method that it says should directly detect the state of the mouse buttons. Unfortunately I can't get this stuff to work--I can't seem to configure my library path appropriately.

After I extract their 1.0beta release, I followed the instructions they say at the command line to test it:

java -cp .;res;jar\lwjgl.jar;jar\lwjgl_test.jar;jar\lwjgl_util.jar;jar\lwjgl_fmod3.jar;jar\lwjgl_devil.jar;jar\jinput.jar; -Djava.library.path=native org.lwjgl.test.WindowCreationTest

It starts to run but then gives me the error
Code:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr
ary.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at org.lwjgl.Sys$1.run(Sys.java:62)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.lwjgl.Sys.loadLibrary(Sys.java:60)
        at org.lwjgl.Sys.<clinit>(Sys.java:74)
        at org.lwjgl.opengl.Display.<clinit>(Display.java:103)
        at org.lwjgl.test.WindowCreationTest.initialize(WindowCreationTest.java:
80)
        at org.lwjgl.test.WindowCreationTest.main(WindowCreationTest.java:284)
Also when I try to use their Mouse class in my own class in Eclipse, it will recognize the project path and compile but it gives me a similar error during runtime. In Eclipse, I did "add external archives" to my project and selected the four jars in their jars directory, but this doesn't make it work. What is likely to be the problem?
 
Last edited by a moderator:
  • #13
I know you can do this under C or VB.
Don't remember the exact code, but one of the functions in Kernal or User Dll will allow you to register a global event handler.

Note: If your code has a bug then its instant blue screen when activated.
 
  • #14
Regarding that error about java.library.path I'm getting when I try to test the lwjgl libraries, I wrote a program consisting of
Code:
System.out.println(System.getProperty("java.library.path"));
and ran it in my lwjgl directory. It turned up some stuff--directories containing .dll files that various programs I have apparently use--but sure enough the lwjgl\native\win32 directory which appears to contain the .dll files for lwjgl was not one of them. I tried to set the property on the command line using
Code:
java -D java.library.path=native\win32
and various variations on that theme, but no luck--every time I tried that it turned up a NoClassDefFoundError and spit back whatever I had put after the -D, and turning all periods into forward slashes for some reason. For example, in response to the previous attempt, it said
Code:
Exception in thread "main" java.lang.NoClassDefFoundError: java/library/path=native\win32

Also, a website I read said that the -D command will only temporarily set properties, not permanently.

So how do I get the java.library.path property to include the lwjgl\native\win32 directory?
 
Last edited:

Similar threads

Replies
0
Views
367
Replies
0
Views
377
Replies
0
Views
846
Replies
5
Views
2K
Replies
10
Views
2K
Replies
4
Views
5K
Replies
3
Views
3K
Back
Top