JustTouched works on windows? - java

I'm using justTouched for manipulate easly touches and released in android, cause isTouched method acumulates many touches; but it works as the same in windows? Meaning, one event even when keep pressed? Or do I need another method/invoker/listener?

On desktop builds, Libgdx treats mouse button presses as touches. justTouched acts exactly the same, except that it polls mouse buttons instead of screen taps. And just like how on mobile you can't tell which finger just touched the screen, you can't tell which mouse button was just pressed. If you need to know which mouse button or finger touched down, you need to use an InputProcessor, which gives you far more information than using the Gdx.input convenience methods.
If you don't care which mouse button was just pressed, all you need is:
if (Gdx.input.justTouched()){
//...
}
Based on your comments under your question, you seem to be trying to distinguish which button just touched with || Gdx.input.isButtonPressed(Input.Buttons.LEFT)) which will return true on every frame as long as the left button is held down. And if instead you did && Gdx.input.isButtonPressed(Input.Buttons.LEFT)), then you wouldn't be sure that it's the left button that was just pressed. (Maybe you're holding down the left button and just pressed the right button.) There is no easy way to distinguish which button was pressed unless you are using an InputProcessor.

Related

what is this: while ACTION_MOVE allow for a new ACTION_DOWN?

How do I allow for new ACTION_DOWN touches while I am still holding my finger on the screen after having triggered a previous ACTION_DOWN event?
It's probably easiest to show a gif of what I would like to achieve:
G is touched, the finger moves to A without releasing, and A gets appended to G above in the textview. The finger moves to S, which again is appended, and then the finger releases, triggering ACTION_UP.
Basically, I have a number of buttons, all of which have an onTouch Listener. When a button is pressed, the text-value of that button gets appended to a textview (just like the animation shows).
But I can't figure out how to re-enable onTouch ACTION_DOWN for any button once the first one is pressed, and I am holding the finger down. Note: I am not interested in the drawing of the line that follows the finger
It's not that I need code; I can't even find anything on the basic logic. I have seen dozens of threads on here asking for something similar and none really help me. What is this feature called? It's not a multitouch gesture since I am only touching with one finger, one thing at a time- but in sequence without ACTION_UP. Some motion event? Do I work with focus? Do I need a canvas?
I think you should set a touch listener on your layout's view and try to get X and Y and detect if X and Y of the touch point are on your Views.
But the post is no case of greater than 2 views. You can refer the post.
Detect touch event on a view when dragged over from other view

How to "Unclick" a JButton without releasing the left mouse button?

I have set up a mouse dragged listener. I trying to set it up where you can click one button then drag your mouse over others to click the other ones. The problem I am having is when you click the first button it turns grey like its waiting for you to release the mouse button. When you move your mouse off the button (still holding the left mouse button) it returns back to its normal color but you cant highlight anything until you let go. Is there anyway to simulated letting the mouse go and "unclicking" the button so you can highlight other things?
What you observe is the typical behavior of the ButtonModel used by Swing buttons. A complete example is examined here, but note how the effect depends on the chosen Look & Feel's ButtonUI delegate.
To get the effect you want, you would have to create buttons using your own variation of BasicButtonUI and a custom ButtonModel that uses isRollover() to add buttons to your program's notion of a selection model.
As an alternative, consider JList, which contains a ListSelectionModel that allows MULTIPLE_INTERVAL_SELECTION. A compete example is shown here.

Difference between isArmed,isPressed and isSelected

What is the difference between the following methods :
jButton.getModel().isArmed()
jButton.getModel().isSelected()
jButton.getModel().isPressed()
I do not understand what the documentation says for isArmed and the rest two have an obvious documentation. But I do not how do they behave differently.
isArmed means:
When the user presses the mouse button down on the JButton , but hasn't yet released it, the JButton is armed. However the armed state does'nt mean that action is going to be triggered for sure , because The user may release the button while the cursor is over the JButton, or the user may move the cursor elsewhere and release.Hence isArmed returns true if the JButton is armed, else it return false.
The documentation for ButtonModel explains the difference:
Pressing the mouse on top of a button makes the model both armed and pressed. As long as the mouse remains down, the model remains pressed, even if the mouse moves outside the button. On the contrary, the model is only armed while the mouse remains pressed within the bounds of the button (it can move in or out of the button, but the model is only armed during the portion of time spent within the button).
As for isSelected:
isSelected() - Indicates if the button has been selected. Only needed for certain types of buttons - such as radio buttons and check boxes.

Cant use capacitive buttons while touching the screen

I'm having issues while coding for my Evo. While touching the screen, the Evo interprets me touching the buttons as another press on the screen instead of a onKeyDown, onBackPressed, etc. (It actually sets the MotionEvent pointer count to 2, and I can get the co-ords that I'm touching that are off the main screen, for example, 830*190 when touching the back button.)
Short of coding in the locations of the buttons (which would be different for every phone with capacitive buttons, if they all have the same issue), is there any way to get around this? Does anyone else have this issue with a different capacitive buttoned device?
On the Evo, the area where the buttons are uses the same capacitive touch sensor as the screen. You can test this by loading up a webpage and scrolling until your finger is in the buttons region. Instead of pressing those buttons, you just continue to scroll around on the webpage, because as far as the phone is concerned you're still touching the "screen".

How do I lock the mouse inside a JFrame

I would like to lock the mouse inside a JFrame. That is, the mouse can not leave the contents of the JFrame (unless the user hits escape, alt-tab, or the window otherwise looses focus). Ideas?
Thanks!
I'm not sure if there's a more automatic way of doing that, but you could use the Robot class to set the mouse position. So in the event handler for when the JFrame gains focus you can start watching the mouse move event, and when the mouse moves just make sure it stays within the JFrame. If it leaves the JFrame you can use the Robot class to set the mouse's position to go back.
Then when the window loses focus, you can unregister from the mouse move event.
The Robot class is ideal for this type of thing, but I would suggest another approach.
Perhaps making the game full screen (maximizing the window pane) would achieve what you want instead. The mouse would be unable to exit the window and no ugly Robot-esque hack needs to be used to force the user to stay within the borders.
Another workaround I just thought of - lock the cursor to the centre of the Frame, and make it invisible.Then render a software cursor where the real cursor should be.
You can then lock the cursor to whatever area you want.
Here's a sneaky one could work if you don't use mouse button 2 in your game.
Use a Robot to press down BUTTON2.
The idea is so the mouse gets dragged, not moved. Whenever you get a mouse moved event, it's because the user has released button2, so press it down again.
Whenever you get a mouse dragged event, if the mouse is outside the window, put it back in.

Categories