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

  • Java
  • Thread starter 0rthodontist
  • Start date
  • Tags
    Java
In summary: WarrenI followed the instructions at the link, and it doesn't seem to be working. It says to use -Djava.library.path=native, but I can't seem to get that to work. It may be a problem with my system, but I don't know for sure.
  • #1
0rthodontist
Science Advisor
1,231
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
  • #2
What OS are you using?
 
  • #3
Windows XP
 
  • #4
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
 
  • #5
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.
 
  • #6
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
 
  • #7
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:
  • #8
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
 
  • #9
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:

1. How do you detect clicks in Java?

To detect clicks in Java, you can use the MouseListener interface which has methods for detecting mouse events such as clicks, presses, and releases. You can also use the addActionListener method to add an action listener to a button or other clickable component.

2. Can you detect right-clicks in Java?

Yes, you can detect right-clicks in Java by using the MouseEvent class and checking for the MouseEvent.BUTTON3 constant in the getButton() method. This will return true if the right mouse button was clicked.

3. What is the difference between a click and a press in Java?

In Java, a click is a combination of a mouse press and a release event, while a press is just a single event where the mouse button is pressed down. Clicks are typically used for triggering actions, while presses can be used for other purposes such as dragging or selecting text.

4. How can I detect double clicks in Java?

To detect double clicks in Java, you can use the getClickCount() method of the MouseEvent class. This will return the number of clicks that have occurred, so you can check if it is equal to 2 to detect a double click.

5. Is there a way to prevent multiple clicks in Java?

Yes, you can prevent multiple clicks in Java by using a flag variable to keep track of whether a click has already been processed. You can set this flag to true when a click is detected, and then reset it to false after the action has been performed. Alternatively, you can disable the clickable component after it has been clicked.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
14
Views
3K
  • Programming and Computer Science
Replies
24
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
Back
Top