LibGDX Input from previous screen registering - libgdx

I am using isTouched to setScreen from my menu screen to my main game screen. (Tap to continue).
In the constructor of the main game screen, I set the input processor. The input processor then immediately fires from the touch on the previous screen.
What is the proper way to handle this?
EDIT: If I tap my finger on an Android device, the tap triggers the isTouched/justTouched. Then the next screen loads faster than I lift my finger and the finger up event triggers my input processor.

I don't think there is any built-in way to prevent this sort of event leakage. One way to avoid the problem is to trigger your transition on release, not press.
Switch your main menu to use an InputProcessor. Use the end-of-touch event to trigger your transition, so that event won't be around to pollute your new InputProcessor. This will avoid mixing polling and event-based input, which seems cleaner, too.
Set a flag when isTouched is true, then in later a render iteration when isTouched is false, and the flag is true, you know it is safe to proceed (this is a hacky polling version of waiting for the touch-up event).
In many UIs button events trigger on the touch-up (or its equivalent). E.g., in this stackoverflow UI, click down on the "Post Your Answer" button, then drag the mouse off the button and release. The button doesn't "click". (Similarly if you click outside the button, drag into it, and then release, it still doesn't "click".)

Related

React state based on mouse/keyboard press/release

i'm creating a custom button with React.
The appearance based on the press/release of the mouse/keyboard.
Sometimes it cannot be done by css using :active pseudo, so i need the javascript solution.
So i created a state that listen the onMouseDown/Up & onKeyDown/Up.
The problem is, if the user click the button then drag the mouse out of the button then release the mouse,
i miss the onMouseUp event thus causing the activeState locked up forever.
Do you have a solution for the equivalent of the :active & :not(:active) pair in javascript way?
note:
watching event window.addEventListener('mouseup',...) is still not satisfying me. When the mouse click hold & move out from the browser's window, i still missing the mouseup event.

Reliably detect if a user is using a mouse on a webpage?

On our page we have some iframes in a long horizontally-scrolling <div>. If the user is using a mouse they can scroll with the scrollbars and we would like them to be able to select text within the iframes. If they are using touch only however, the scrollbars are a hassle and I would like to overlay a transparent element over the whole thing to give them the ability to scroll easily by dragging, this of course sacrifices the select-text feature but makes sense in that scenario.
Which gets me to my question, is there a way to reliably detect if a user is interacting with a webpage via a mouse?
Everything I've seen on detecting touch or mouse is that touch will broadcast mouse events so it is very difficult to detect touch OR mouse (not to mention that you can have both). My problem is simpler - it is whether the user has interacted with the page via a mouse.
Can anyone think of a way to check this reliably?
A mouse can do one single thing a touch device can never do - move without having any buttons pressed. So I'd just install an onMouseMove event on page load, and if it triggers without buttons pressed mark the user as a mouse user. You could then persist this through a cookie or LocalStorage since the flag will not change within the same environment, and remove the event right away. The precise way of implementing the single-fire event depends on which library you use (if any at all), but it should be easy with Mootools/JQuery docs in hand.
In general I'd recommend the easier route of just checking for a touch interface in most cases :
if('ontouchstart'in window)
{
/* it's a touch device */
}

Apple Safari Buttons onclick takes to long

i have a simple system to register who is present at a party.
I created an easy numkeypad with buttons, and that works. But when I try it in Safari (or any other mobile browser), it takes about a second before I can press the next button. It has to be quick, so this is too long.
Is there any way to shorten this "waiting" time between button presses.
click events are delayed in mobile browsers due to the fact the browser has to ensure the user isn't double-tapping or tap-holding an element.
I have written a jQuery plugin that can handle touch and mouse events in a convenient way, and allows you to bind one event to trigger without a delay (tap). You can check it out here:
https://github.com/benmajor/jQuery-Mobile-Events

Actionscript 3 - Synchronous Click Event

I am trying to build a custom modal dialog in flash. The way I chose to go about it is create a movie clip class with the UI for the dialog with a function to add buttons to it. I then size the ui after all the buttons are added and display it on the screen.
It works up to this point. Now I want whatever called this dialog to wait until a button is picked before the user can do anything else. Something along the lines of:
var dialog:MyDialog = new MyDialog();
dialog.addButton(new MyButton("Foo"));
dialog.addButton(new MyButton("Bar"));
var result:String = dialog.show(); // we will wait here
In the dialog.show I wish to show the movie clip and then wait for the user to click and of the buttons on the dialog before returning. The MouseEvent.CLICK event is asynchronous though so I don't know how to wait for it.
An alternative is creating a whole custom complete event for the dialog that is added to the screen that is calling the dialog which I can continue the logic in and have a boolean that disables other input, but that is a pretty big hassle and I've never done anything like it.
What your describing is a misconception of what synchronous and asynchronous is.
When the dialog comes up, you still want the user to be able to hit the dialog button. If the procedure was synchronous then the entire program would freeze as the routines for the mouse clicking actions would never arrive. Remember, flash is single threaded.
The thread that has the popup is sharing the same thread as the underlying app.
The easiest thing is just to have an event on the buttons that dispatch some close event that you can listen for in your application. No custom event classes are needed.
dispatchEvent(new Event("close"))
as an example.
If your worried about the user interacting with parts outside of the application, then you can simply draw a rectangle behind the popup with mouseEnabled true, or check out using Flex's model dialog classes.

How can I press a swing JButton using mouse events?

I Have a JButton (or any Component, really) that I would like to trick into thinking that it has been clicked on and therefore firing its action performed event. I don't want to call the action performed or doClick directly because I am trying to make a solution that generalizes beyond buttons, and I am constrained to posting events.
I would have thought that posting a MousePressed event to the system event queue would have done it, but no. ( with appropriate location, click count etc.)
Then I thought a mouse entered followed by a mouse move, a mouse pressed, a mouse released, and a mouse clicked, but no.
None of this causes the JButton to fire its action performed like it does when I actually click on it.
Has anyone caused a JButton to spit out its action performed event by driving it with mouse events? Moved a JSlider with mouse events? Expanded a tree node?
Thanks for any help.
Have you tried the fireActionPerformed method? I can't off the top of my head now remember if all components have it but if i remember right, all buttons and menu items should deifnately have it. Just a thought