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

  • Context: Java 
  • Thread starter Thread starter 0rthodontist
  • Start date Start date
  • Tags Tags
    Java
Click For Summary

Discussion Overview

The discussion revolves around detecting mouse clicks globally on the screen using Java, particularly in the context of the LWJGL (Lightweight Java Game Library). Participants explore the limitations of Java's event handling capabilities, especially regarding clicks outside the application's window, and address issues related to configuring the java.library.path property for LWJGL.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant expresses a desire to detect clicks anywhere on the screen, questioning if the listener framework can be used for this purpose.
  • Another participant states that, to their knowledge, Java cannot detect clicks outside its own windows due to limitations in the Windows event system.
  • A suggestion is made to use java.awt.Toolkit.addAWTEventListener to potentially capture global events, but concerns are raised about the abstract nature of the Toolkit class and its lack of subclasses.
  • Participants discuss the possibility of using .NET or other languages to achieve the desired functionality, with one noting that polling mouse button states could work in those environments.
  • There is skepticism about achieving global event detection in Java without sacrificing platform independence, with some participants emphasizing that this would limit the application's usability to a specific OS.
  • One participant shares a code snippet attempting to use LWJGL's Mouse class but encounters issues with the java.library.path configuration, leading to runtime errors.
  • Another participant mentions that global event handling is possible in languages like C or VB, but warns of potential system crashes if bugs are present in the code.
  • Concerns are raised about properly setting the java.library.path to include the necessary LWJGL native libraries, with attempts to set this property via the command line resulting in errors.

Areas of Agreement / Disagreement

Participants generally disagree on the feasibility of detecting global mouse clicks using Java, with some asserting it is not possible while others suggest alternative methods or languages. The discussion remains unresolved regarding the correct configuration of the java.library.path property for LWJGL.

Contextual Notes

Participants note limitations related to platform independence and the abstract nature of certain Java classes. There are unresolved issues regarding the correct setup of the java.library.path property and the implications of using native code.

Who May Find This Useful

Java developers interested in global event handling, LWJGL users, and those exploring cross-platform application development may find this discussion relevant.

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 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 14 ·
Replies
14
Views
6K
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 3 ·
Replies
3
Views
4K