Key presses being registered as touch events.

I’m on a windows 10 computer, using build 2020.3635.
With just the below in main.lua, if I hold down the primary button on the touch pad I get the “began” event as expect. If I then press and hold any key I get ended, began, ended. The first ended and began are immediate, with the next ended coming after a moment. With the release of the key there is another began event. I imagine this is an issue with the laptop/windows, but I really have no idea what’s going on. Would appreciate any advice, thanks.

Runtime:addEventListener("touch", function(e) print(e.phase) end)

That listener is insufficient to debug what is happening.

Try this, so you can see exactly what is happening:

local function onTouch(event)
   for k,v in pairs(event) do
      print( "onTouch()", k, " == ", v )
   end
   print ("-------------------\n")
end


Runtime:addEventListener( "touch", onTouch )

Thanks for the reply.
Following the steps above, the print out I get is this:

onTouch()	phase	 == 	began
21:44:25.111  onTouch()	yDelta	 == 	0
21:44:25.111  onTouch()	xDelta	 == 	0
21:44:25.111  onTouch()	y	 == 	314.07406616211
21:44:25.111  onTouch()	yStart	 == 	314.07406616211
21:44:25.111  onTouch()	xStart	 == 	440.09259033203
21:44:25.111  onTouch()	id	 == 	userdata: 00000001
21:44:25.111  onTouch()	x	 == 	440.09259033203
21:44:25.111  onTouch()	time	 == 	10218.9
21:44:25.111  onTouch()	name	 == 	touch
21:44:25.111  -------------------
21:44:25.111  
21:44:30.192  onTouch()	phase	 == 	ended
21:44:30.192  onTouch()	yDelta	 == 	0
21:44:30.192  onTouch()	xDelta	 == 	0
21:44:30.192  onTouch()	y	 == 	314.07406616211
21:44:30.192  onTouch()	yStart	 == 	314.07406616211
21:44:30.192  onTouch()	xStart	 == 	440.09259033203
21:44:30.192  onTouch()	id	 == 	userdata: 00000001
21:44:30.192  onTouch()	x	 == 	440.09259033203
21:44:30.192  onTouch()	time	 == 	15319.4
21:44:30.192  onTouch()	name	 == 	touch
21:44:30.192  -------------------
21:44:30.192  
21:44:30.251  onTouch()	phase	 == 	began
21:44:30.251  onTouch()	yDelta	 == 	0
21:44:30.251  onTouch()	xDelta	 == 	0
21:44:30.251  onTouch()	y	 == 	314.07406616211
21:44:30.251  onTouch()	yStart	 == 	314.07406616211
21:44:30.251  onTouch()	xStart	 == 	440.09259033203
21:44:30.251  onTouch()	id	 == 	userdata: 00000001
21:44:30.251  onTouch()	x	 == 	440.09259033203
21:44:30.251  onTouch()	time	 == 	15370.7
21:44:30.251  onTouch()	name	 == 	touch
21:44:30.251  -------------------
21:44:30.251  
21:44:30.690  onTouch()	phase	 == 	ended
21:44:30.690  onTouch()	yDelta	 == 	0
21:44:30.690  onTouch()	xDelta	 == 	0
21:44:30.690  onTouch()	y	 == 	314.07406616211
21:44:30.690  onTouch()	yStart	 == 	314.07406616211
21:44:30.690  onTouch()	xStart	 == 	440.09259033203
21:44:30.690  onTouch()	id	 == 	userdata: 00000001
21:44:30.690  onTouch()	x	 == 	440.09259033203
21:44:30.690  onTouch()	time	 == 	15819.8
21:44:30.690  onTouch()	name	 == 	touch
21:44:30.690  -------------------
21:44:30.690  
21:44:33.349  onTouch()	phase	 == 	began
21:44:33.349  onTouch()	yDelta	 == 	0
21:44:33.349  onTouch()	xDelta	 == 	0
21:44:33.349  onTouch()	y	 == 	314.07406616211
21:44:33.349  onTouch()	yStart	 == 	314.07406616211
21:44:33.349  onTouch()	xStart	 == 	440.09259033203
21:44:33.349  onTouch()	id	 == 	userdata: 00000001
21:44:33.349  onTouch()	x	 == 	440.09259033203
21:44:33.349  onTouch()	time	 == 	18475.5
21:44:33.349  onTouch()	name	 == 	touch
21:44:33.349  -------------------
21:44:33.349  
21:44:34.552  onTouch()	phase	 == 	ended
21:44:34.552  onTouch()	yDelta	 == 	0
21:44:34.552  onTouch()	xDelta	 == 	0
21:44:34.552  onTouch()	y	 == 	314.07406616211
21:44:34.552  onTouch()	yStart	 == 	314.07406616211
21:44:34.552  onTouch()	xStart	 == 	440.09259033203
21:44:34.552  onTouch()	id	 == 	userdata: 00000001
21:44:34.552  onTouch()	x	 == 	440.09259033203
21:44:34.552  onTouch()	time	 == 	19690.3
21:44:34.552  onTouch()	name	 == 	touch
21:44:34.552  -------------------

I have no idea what to make of it.

Well, the good news is that this doesn’t happen when I use the mouse. Perhaps an issue with the touchpad, which has always been troublesome ( jumping around when you tap, for example).

Hi. Sorry if I’m a bit slow here, but what do you mean exactly by

“Primary button on touch pad”.

Are you using a laptop that has buttons below/above the track pad?

If I’m close to right, can you tell us the model of laptop you’re using?

What you’re saying is quite confusing because the buttons should not produce touch events.

When I hear the word button, I think “keys on your keyboard, buttons on a controller, and buttons on a mouse”. The prior two produce key events, not touch events.

Try adding this code too and see what it prints:

local function onKey(event)
for k,v in pairs(event) do
      print( "onKey()", k, " == ", v )
   end
   print ("-------------------\n")
end
Runtime:addEventListener( "key", onKey )

local function onMouseEvent( event )
    if event.type == "down" then
        if event.isPrimaryButtonDown then
            print( "Left mouse button clicked." )
        elseif event.isSecondaryButtonDown then
            print( "Right mouse button clicked." )        
        end
    end
end
                             

Runtime:addEventListener( "mouse", onMouseEvent )

Now, you should have listeners for:

  • touch
  • mouse buttons
  • key

This one has both

If you’re talking about the equivalent of the left-mouse button, then clicking that while running the simulator and while your pointer is over the simulator window is the same as touching the screen.

Apologies if I’m confused, but that sounds like what you’re saying.

It will also produce a mouse event.

If there’s any slowness, it’s probably me. It usually is. :grinning:

I have a HP pavilion 15-aw002na, the track pad of which is just one flat surface (like the one below), with left- and right-click concealed underneath. By “primary button”, I meant left-click.

Using that code, I get:

13:15:30.310  Left mouse button clicked.
13:15:32.565  onKey()	keyName	 == 	f
13:15:32.565  onKey()	isCtrlDown	 == 	false
13:15:32.565  onKey()	phase	 == 	down
13:15:32.565  onKey()	nativeKeyCode	 == 	70
13:15:32.565  onKey()	descriptor	 == 	f
13:15:32.565  onKey()	isShiftDown	 == 	false
13:15:32.565  onKey()	isCommandDown	 == 	false
13:15:32.565  onKey()	name	 == 	key
13:15:32.565  onKey()	isAltDown	 == 	false
13:15:32.565  -------------------
13:15:32.565  
13:15:32.633  Left mouse button clicked.
13:15:34.648  onKey()	keyName	 == 	f
13:15:34.648  onKey()	isCtrlDown	 == 	false
13:15:34.648  onKey()	phase	 == 	up
13:15:34.648  onKey()	nativeKeyCode	 == 	70
13:15:34.648  onKey()	descriptor	 == 	f
13:15:34.648  onKey()	isShiftDown	 == 	false
13:15:34.648  onKey()	isCommandDown	 == 	false
13:15:34.648  onKey()	name	 == 	key
13:15:34.648  onKey()	isAltDown	 == 	false
13:15:34.648  -------------------
13:15:34.648  
13:15:34.710  Left mouse button clicked.

It seems that keys are triggering mouse events, but only when the click is held down.

Bummer. That looks like a mapping error. It could be hardware, drivers, software or a combo.

The good thing is, you found you can avoid this with a standard mouse (which I suggest using over a trackpad anyways).

Cheers,
Ed

Mouse it is then. Thanks for the help.