Edit save some time and jump to this comment below for a summary of the actual bug. Come back here if you want repro steps.
I'm experiencing a couple of unexpected behaviors with respect to button input handler events. Consider this trivial example:
function pd.leftButtonDown() print("LEFT DOWN") end
function pd.leftButtonUp() print("LEFT UP") end
function pd.rightButtonDown() print("RIGHT DOWN") end
function pd.rightButtonUp() print("RIGHT UP") end
This works fine for discrete button presses. Pressing either button results in a corresponding down event for that button. One may then hold that button as long as desired (say, a few seconds), then release it resulting in a corresponding up event. Following these steps results in the following console output (actions interleaved as "comments"):
-- press left button
LEFT DOWN
-- wait 3 seconds
-- release left button
LEFT UP
-- press right button
RIGHT DOWN
-- wait 3 seconds
-- release right button
RIGHT UP
Easy. However, consider the case when one presses the right button before releasing the left. That yields the following:
-- press left button
LEFT DOWN
-- wait 1 second
-- press right button
LEFT UP
RIGHT DOWN
-- wait 1 second
-- release left button
-- wait 1 second
-- press left button
LEFT DOWN
RIGHT UP
-- wait 1 second
-- release right button
-- wait 1 second
-- release left button
LEFT UP
Two things about this run counter to my expectation:
- First, the system appears to synthesize up events for the held button when a second button is pressed before the first is released, rather than waiting for the actual release of the first button (which produces no event at at all). Note that what I'm calling a "synthesized" event does not appear to come immediately with the down event for the pressed button, but a very short time thereafter (maybe the "button held" threshold, even though it isn't supported for D-pad?).
- Second, even if this is expected behavior, the relative order of the down event for the newly pressed button and the synthesized up event for the already pressed one are inconsistent. Pressing the right button while holding left produces the synthesized up event for the left button before the down event for the right. Doing the inverse produces the down event for the left before the synthesized up event for the right. Another way of saying this is that the left button reports before the right, regardless.
Is this expected behavior?
Just to be extra explicit, here's the output I expected to get, following the same steps from above:
--press left button
LEFT DOWN
-- wait 1 second
-- press right button
RIGHT DOWN
-- wait 1 second
-- release left button
LEFT UP
-- wait 1 second
-- press left button
LEFT DOWN
-- wait 1 second
-- release right button
RIGHT UP
-- wait 1 second
-- release left button
LEFT UP