lwjgl double-click mouse events - java

I'm currently teaching myself LWJGL's mouse class, but there is something I still don't know how to do. I want to be able to handle double-click mouse events, but I don't know how.

It is not (AFAIK) natively supported. You have to do it yourself.
One way to do that : memorize the event date (System.curentTimeMS() or equivalent).
If the previous clic event was recent (~200 ms), it's a double-clic. else, simple clic.
Hope it helps...

Related

Simulating a Mouse Event on A Minimized Window Java

So I want to be able to simulate mouse clicks on my window/frame, but in the background. This means I cant use the Robot class because it takes control of the OSes mouse which is not what I want (please guys, I know of and use the Robot class, it's not what I need).
I want the program to think I clicked on part of it (x,y on the frame) even when minimized (doesnt have to minimized but at least out of focus). I dont want it to take over my computer since it should ideally be a background task.
I did a little bit of research before posting and I read that I could make an Applet and then use the "reflection class"(?) and mouselisteners to invoke mouse events on the frame itself rather than through the OS. Not sure if itll work cause the explanation was pretty meh and the guy said they could communicate individually if he had problems :/.
Kind of wondering if it's possible at this point. If it cant be done in java, I know a little python, so if there's a solution for it in python, that could work to.
TLDR: Need to simulate mouseclicks on my frame, but it cant use the os mouse and should ideally work when the application is out of focus/in the background.
Thanks in advance :D

Hear text (screenreader) when mouse hovers over a JMenu object in Java / Windows

When using a screenreader, like NVDA, I want to be able to hear the text of the menu when I hover my mouse over it. I am able to hear the text when I push the buttons in the menubar, but not when I hover over them (the screenreader does reads the menu's of other programs when only hovering over the buttons).
I have set the AccessibleContext like below:
JMenu.getAccessibleContext().setAccessibleName("text");
JMenu.getAccessibleContext().setAccessibleDescription("more text");
I can set listeners to the objects that detects when a mouse hovers over them, but I do not know if/how I can cast a text to the screenreader to read. I tried ToolTipText, but that text is not read by the screenreader either. RequestFocus on the JMenu works, but setting the focus to an object just by hovering over it with the mouse provides other problems.
Does anyone knows how I can let a screenreader reads the JMenu-text when hovering with the mouse over the menubar?
I am using Java6 EE and the Java AccesBridge (version 2.02) on a Windows machine (XP and w7).
Swing is the weaker of the GUI technologies relating to accessibility in Java, compared to SWT at any rate. There's a few things you can try.
First is to make sure any accessibility fields are set (which you've started on). I can't remember if Java has an AccessibleRole field, but you can try setting that to menu and menuitem for your menu items.
Another thing you can try is the AccessibleMenu JMenu.AccessibleJMenu component. This one's the product of further reading, so I can't verify it from experience. But it and its surrounding classes may suit your needs.
If those don't work, you could try the option of talking to people's screen readers directly. Quentin C has a good library to do this, Universal Speech. I'm new to this library myself, but it does have a Java implementation in there that should show you how to use it in a Java program. Normally I wouldn't recommend this approach unless making the UI accessible really isn't working.
The last option would be to use the SWT components instead of the Swing ones, even if just for your menu bar. I wasn't sure how keen you'd be on this one, but it is an option and should resolve it.
I hope one of these suggestions helps you solve your problem.

Java: I'd like a JLabel to respond to mouse events only sometimes. Is there a way to hide a mouse listener until wanted?

I see there are methods already built for adding and removing mouse listeners, I suppose I could add them and remove them as needed. I just wasn't sure if there was a better way.
Having my JLabel respond to all mouse events over it but sometimes do nothing isn't quite what I'm looking for, it would be nice if my Labels had the mouse listener only when I needed it to. Maybe this whole idea is just a weird approach.
You register the Listener once and for all; you don't turn it off and on.
You can code logic inside to only take action under certain conditions of your choosing. As long as you make the information available that's needed for a decision your implementation should be fine.

Mouse press and release outside of window

I have two booleans: leftPressed and rightPressed. I need them to be set true when their respective mouse buttons are pressed and false when they are not. The location of the mouse and whether or not the program has focus should not matter. This program will not have a GUI. Is this even possible?
Definitely possible, very time consuming though. Use JNA to create a global mousehook. You would have to provide implementations for each platform you planned for it to run on, etc.. For example, here's someone who did it with windows.
I was looking for something similar at one point but found a better way to go about it in my code. However, I did run into this library. It may work out for you.

Play beep sound or any customized sound on all mouse click event in java

I have an application which i am going to install on Linux touch system. The touch system is not giving me the touch sound so i decided to have that feature on my application. What is the best way to do it ? I dont want to go through each and every buttons and other components and write the codes there. Is there any global way to handle that so that the sound works throughout the application when ever the screen is touched or mouse is clicked ??
Try this
Toolkit.getDefaultToolkit().beep();
To play it in all MouseEvent make your MouseEvent listener single and everytime when you need use that listener and write above code in that mouse listener.
Take this answer:
How can I play sound in Java?
... and trigger the playback in the mouse click event.
Assuming that you are using the JFC/Swing toolkit, you might want to read a bit about using the Multiplexing Look & Feel. Even though I don't know of any ready-to-use auxiliary look and feel(s) that might fit your needs, it should be possible to write your own auxiliary look and feel which behaves as you describe above ...
... after you have created your own auxiliary look and feel make sure to start your java interpreter with the "-Dswing.auxiliarylaf=your.auxiliary.look.and.feel.Classname" parameter.

Categories