NEWT & Windows, MouseEvent Press & Hold

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

NEWT & Windows, MouseEvent Press & Hold

Andre
This post was updated on .
Hello again,

i suddenly saw a windows behavior in Newt that i did not spot yet in AWT or SWING.

if i long press and hold my finger on a touchscreen
i get a primary press event via button 1
and a secondary button 3 event
on touchable devices, mainly because of the windows behaviour of long presses for right clicks.

Is there any way around that? It looks correct but i never had a chance to confront myself with it in AWT/Swing.
Any ideas? It comes into my way when creating a drawing program and i am bending my head to find a hack.
I know it can be turned off in the windows settings ("disable press and hold for right click") but that seams
to be a too intrusive user act.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

EXAMPLE NEWT CODE:

import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.util.FPSAnimator;

public class Example_NEWT_Long_Press_Test {
        public static void main(String[] args) {
                GLWindow window = GLWindow.create(new GLCapabilities(GLProfile.getDefault()));
                final FPSAnimator animator = new FPSAnimator(window, 60, true);
                window.addWindowListener(new WindowAdapter() {
                        @Override
                        public void windowDestroyNotify(WindowEvent arg0) {
                                new Thread() {
                                        public void run() {
                                                if (animator.isStarted())
                                                        animator.stop();
                                                System.exit(0);
                                        }
                                }.start();
                        }
                });
                window.addMouseListener(new MouseAdapter() {
                        public void mousePressed(MouseEvent e) {
                                System.out.println("Example_NEWT_Jogl_Long_Press_Test.mousePressed()");
                                System.out.println(e);
                        }
                });
                window.setSize(400, 400);
                window.setVisible(true);
                animator.start();
        }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

EXAMPLE SWING CODE:

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;

public class Example_Swing_Long_Press {
        public static void main(String[] args) {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.addMouseListener(new MouseAdapter() {
                        public void mousePressed(MouseEvent e) {
                                System.out.println("Example_Swing_Long_Press.mousePressed()");
                        }
                });
                frame.setSize(400, 400);
                frame.setVisible(true);
        }
}
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: NEWT & Windows, MouseEvent Press & Hold

gouessej
Administrator
Hello

Call either MouseEvent.getAllPointerTypes() or MouseEvent.getPointerType​(int index) and treat the event related to the button 3 differently when the pointer type isn't MouseEvent.PointerType.Mouse.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NEWT & Windows, MouseEvent Press & Hold

Andre
Hi

Good idea, i saw Pointertype.mouse and Pointertype.touch too as solution.
I stumbled over it while thinking of using long press like in Procreate for color picker.
I guess that will do. Or must. Feels dirty thou. :)

I was wondering if there is any Java Native stuff to interfere with the touch behaviour of Windows in general,
since for example they block 3-5 finger taps as well for me.
Nevermind?!

Tthx
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: NEWT & Windows, MouseEvent Press & Hold

gouessej
Administrator
You can use java.lang.foreign in Java >= 19 to call native APIs easily without using JNI if you find something in Win32 APIs to do what you want but maybe it's doable only by modifying the registry and you would take the risk to affect the behavior of the system, not only the behavior of your software. My suggestion seems to be a lot easier and less risky.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: NEWT & Windows, MouseEvent Press & Hold

Andre
Thaaaanks.

I'll consider that. But i'll try that too. But indeed ... user risk no good.




From before - Registry :

presshold for right click  OFF

[HKEY_CURRENT_USER\Software\Microsoft\Wisp\Touch]
"TouchMode_hold"=dword:00000000


presshold for right click ON

[HKEY_CURRENT_USER\Software\Microsoft\Wisp\Touch]
"TouchMode_hold"=dword:00000001
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: NEWT & Windows, MouseEvent Press & Hold

Sven Gothel
Administrator
ah, so its a Windows machine :)

Yeah, was my 1st thought as well, i.e. a build-in touch-gesture.
As Julien hinted, then the detailed pointer info might help.