Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

[WORKAROUND] Apple tv remote swipes return multiple key values
Started by avlepel Dec 06 2015 02:33 PM

31 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hi,

 

when I implemented the navigation for my level selection screen (5 rows with 5 levels each) I used the swipe controls on the tv remote:

 

With the up / down / left / right swipes you can navigate to the level of your choice.

 

Now when I test on the Apple tv using the real remote I get multiple keys for each swipe gesture.

 

Take this code for testing:

local appPurpose = display.newText( "Apple tv remote key tester", 160, 64, native.systemFontBold, 18 )

local function onKey( event )

	local phase = event.phase
	local keyName = event.keyName

	if phase == "down" then
		print( "keyName: ", keyName )
	end

	return true
end

Runtime:addEventListener( "key", onKey )

Just run the program on the Apple tv and I get the following output in Xcode:

 

When I swipe DOWN:

 
Dec  6 23:19:56 Apple-TV KeyTest[180] <Warning>: keyName: right
Dec  6 23:19:56 Apple-TV KeyTest[180] <Warning>: keyName: down

 

or
 
Dec  6 23:22:28 Apple-TV KeyTest[180] <Warning>: keyName:  left
Dec  6 23:22:28 Apple-TV KeyTest[180] <Warning>: keyName:  down
 

or 

 

Dec  6 23:21:45 Apple-TV KeyTest[180] <Warning>: keyName: right

Dec  6 23:21:45 Apple-TV KeyTest[180] <Warning>: keyName: down
Dec  6 23:21:45 Apple-TV KeyTest[180] <Warning>: keyName: left
 
 
The same happens with the other directions.
 
It looks as if the swipe gesture down creates multiple key events:
 
One event for the direction I was swiping, "down", as show as the second event that happened.
And one event for the second direction the swipe was heading to - you will never swipe exactly down, there always will be some deviation to the left or right, and this is send as another key event.
 
If this would be always the case I could live with it, I would always take the second event.
 
But sometimes even three key events happen, as shown above. 
 
I attached the test project with build and config files.
 
Thanks & best
Andreas

Attached Files



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,535 posts
  • Enterprise

Thanks for the report. I'm not sure if reading the touch pad as an Axis instead of key events would help if you're trying to detect swipes.

 

Rob



[TOPIC: post.html]
#3

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hi Rob, I don't exactly need swipes, I just want to know the correct direction of the user input when I listen for the keys. And I thought that listening for the up, down, left right keys will give me just this direction, the same as giving me the buttonA and buttonX key events. I of course can start to code my own translate-axis-movements-on-the-touch-area-to-keys method, but I was hoping that this would just be corrected SDK side. Or are you implying that it is already implemented the way it should work? That these double or triple key events are intentional? Thanks & best Andreas

[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,535 posts
  • Enterprise

What I was suggesting is that if the key events are too sensitive, you could use the axis events and basically roll your own events that would give you more control.

 

Rob



[TOPIC: post.html]
#5

Michael W.

[GLOBAL: userInfoPane.html]
Michael W.
  • Contributor

  • 276 posts
  • Alumni

This is definitely an issue. Can you send a bug report with the attached project and post the case number back in this topic?



[TOPIC: post.html]
#6

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hi Michael,

 

done:  (Case 44134) Apple tv remote swipes return multiple key values

 

Thanks for looking into it. It's great that Corona continually supports the tvOS Alpha, so we can continue to convert our games!

 

Best

Andreas 

 

@Rob:

Yes, if I would need more control I would implement my own swipe code. But I need these controls only for navigating the menus.

The rotating levels in "Freeze! 2 - Brothers" are now controlled using the accelerometer. And yes, there is some small lag as always with the accelerometer, but that doesn't hurt - it really is fun to play the game this way (otherwise I wouldn't publish it).



[TOPIC: post.html]
#7

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hi Michael,

 

I tested this issue with daily build 2795 (tvOS BETA), and the problem still exists. And it's a bad one, the multiple keys returned per swipe makes navigating e.g. a level menu using directional swipes almost impossible.

 

As you decided to go to BETA, did you check this issue first? Or did you get a different result running the demo code on the device?

 

Thanks & best

Andreas



[TOPIC: post.html]
#8

Michael W.

[GLOBAL: userInfoPane.html]
Michael W.
  • Contributor

  • 276 posts
  • Alumni

Hi Andreas,

 

We definitely do see this issue, and it's one we need to fix. It did not make it to the beta list.

 

I suggest using the raw axis values (listen to "axis" events instead of "key" events) for now.

 

- Michael



[TOPIC: post.html]
#9

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hi Michael,

 

thanks for the lightning fast feedback - on a Sunday night! I now feel bad that you had to answer at the weekend!

 

Good to know that you see this issue. 

 

Thanks & best

Andreas



[TOPIC: post.html]
#10

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,535 posts
  • Enterprise

I can't access my Apple TV at the moment to test, but are you getting multiple "Up" phases during the swipe? Or is it a series of "Down"'s followed by one "Up"?

 

Rob



[TOPIC: post.html]
#11

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hi Rob,

 

I just tested with 2795 after updating my device to tvOS 9.1, and the issue is still the same as described at the top:

 

When I e.g. swipe DOWN:

 
Dec  6 23:19:56 Apple-TV KeyTest[180] <Warning>: keyName: right
Dec  6 23:19:56 Apple-TV KeyTest[180] <Warning>: keyName: down

 

or
 
Dec  6 23:22:28 Apple-TV KeyTest[180] <Warning>: keyName:  left
Dec  6 23:22:28 Apple-TV KeyTest[180] <Warning>: keyName:  down
 

or 

 

Dec  6 23:21:45 Apple-TV KeyTest[180] <Warning>: keyName: right

Dec  6 23:21:45 Apple-TV KeyTest[180] <Warning>: keyName: down
Dec  6 23:21:45 Apple-TV KeyTest[180] <Warning>: keyName: left
 
 
So I get the main direction "down", accompanied by a "left" or "right" or even both - these are the variations of my downswipe, so if I swipe down and slightly to the left I get an additional "left", if i swipe a little bit to the right I get an additional "right". Or even both.
 
It is of course impossible to swipe exactly down. :-)
 
I guess these variations of the main swipe direction should be filtered out.
 
Best
Andreas


[TOPIC: post.html]
#12

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,535 posts
  • Enterprise

What I did was ignore left and right. I'm only paying attention to up and down.

 

Rob



[TOPIC: post.html]
#13

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

What I did was ignore left and right. I'm only paying attention to up and down.

Rob

Hi Rob,

Yes, but that won't work for me or any games that e.g. use a 5x5 grid to select one of 25 levels for a world, like in "Where's my Water" or "Freeze!", to name just two great examples in one sentence. ;-)

The Apple guidelines state that it's not enough to just walk sequentially through all levels in a screen like this, the user must be able to navigate freely up, down, left right.

But for this I will just wait till it is fixed, got enough other things still to do to convert the game for tvOS.

Best
Andreas

[TOPIC: post.html]
#14

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hi Michael,

 

I was quite happy when I saw the daily build notes for .2796:

 

  • tvOS: Removing directional key events. 

 

Well, and then, when I tested it (with .2796 up to .2799) I saw that this was meant literally:

 

Not only the wrong additional directional key events for each swipe were removed, you removed all directional key events, the only events I get reported now are "buttonA", "buttonX" and "menu".

 

Ok, this certainly takes care of the bug in a way, there are no multiple key events anymore. :-)

 

But I was hoping for something more like a fix, so if the user swipes to the right we get back a "right" key event, nothing more, nothing less.

 

But enough said, hope you have a nice christmas vacation and maybe tackle this problem in January. 

 

Best

Andreas



[TOPIC: post.html]
#15

Michael W.

[GLOBAL: userInfoPane.html]
Michael W.
  • Contributor

  • 276 posts
  • Alumni

We removed it until we could come back and implement it correctly.

 

For now, please look at axis events.You can look at these values and write a lua wrapper to synthesize your own up/down/left/right events.



[TOPIC: post.html]
#16

thassman

[GLOBAL: userInfoPane.html]
thassman
  • Enthusiast

  • 63 posts
  • Corona SDK

Damn, now the navigation in my app is broken.

It was a very convenient feature imho.

Any idea when we can expect this to return?

 

Cheers,

Tommy



[TOPIC: post.html]
#17

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,535 posts
  • Enterprise

I don't have an ETA. Perhaps I should do a tutorial on using axis events to make your own key events that lets you adjust the sensitivity of what triggers an event until we can get something more formal from engineering.

 

Or if you're not needing a specific feature of a daily build, don't update yet.

 

Rob



[TOPIC: post.html]
#18

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hey, you removed a key feature! :-D

[Sorry, as a German I couldn't resist the pun.]

Certainly there is the workaround to look for the swipes myself by interpreting the axis events. And I guess I will do that for the next time. And yes, a tutorial would always be welcome, will save me some time.

But in the released game I would like to have support for the original keys returned by tvOS. The users will be used to them and it will not be possible to emulate the exact feeling of the swipes with your own custom implementation.

Thanks and best
Andreas

[EDIT: Strange, whenever I post something using my iPad Air and Safari after posting all line breaks are removed. When I edit the post again all line breaks are still there, they just disappear when the post is published.]

[EDIT 2: Even stranger, after I edited the post and added the first EDIT and published the post now all line breaks show up. Feel free to test.]

[TOPIC: post.html]
#19

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

[EDIT: Strange, whenever I post something using my iPad Air and Safari after posting all line breaks are removed. When I edit the post again all line breaks are still there, they just disappear when the post is published.]

[EDIT 2: Even stranger, after I edited the post and added the first EDIT and published the post now all line breaks show up. Feel free to test.]


Thanks for bringing up the forum line breaks issue. I thought it was just me.

It seems to happen when using the mobile theme, regardless of the browser used.

I'll pass this on to the web guys.

Merry Christmas, and best of luck with Freeze 2 :)

[TOPIC: post.html]
#20

thassman

[GLOBAL: userInfoPane.html]
thassman
  • Enthusiast

  • 63 posts
  • Corona SDK

I don't have an ETA. Perhaps I should do a tutorial on using axis events to make your own key events that lets you adjust the sensitivity of what triggers an event until we can get something more formal from engineering.

 

Or if you're not needing a specific feature of a daily build, don't update yet.

 

Rob

 

 

Such a tutorial would be much appreciated, thanks

 

Cheers



[TOPIC: post.html]
#21

JonPM

[GLOBAL: userInfoPane.html]
JonPM
  • Corona Geek

  • 1,077 posts
  • Corona SDK

Such a tutorial would be much appreciated, thanks

 

Cheers

 

Agreed.



[TOPIC: post.html]
#22

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,535 posts
  • Enterprise

local resetAt0 = true
local function onAxis(event)
	if #objects < 1 or not event.axis or event.axis.type~='y' then
		return
	end
	
	if resetAt0 and event.normalizedValue ~= 0 then
		return
	end
	resetAt0 = false
	
	if not rect then
		focusedObject = 1
		createFocusedRect(objects[focusedObject])
	end

	local dy = event.normalizedValue
	rect.y = objects[focusedObject].y + dy*rect.height*0.3

	if math.abs(dy) > 0.5 then
		if dy > 0 and focusedObject < #objects then
			shiftedThisEvent = true
			focusedObject = focusedObject + 1
			createFocusedRect(objects[focusedObject])
		end
		if dy < 0 and focusedObject > 1 then
			shiftedThisEvent = true
			focusedObject = focusedObject - 1
			createFocusedRect(objects[focusedObject])
		end
		resetAt0 = true
	end

end

This code was taken from an internal test app, so it's not production code. "objects" is an array of the items to toggle between. createFocusedRect() is a function that simply creates a hollow rectangle around the object that's selected. You would show your selected buttons in whatever makes sense for your app. "focusedObject" is just the index of the currently selected item. This sample only does the Y axis. But you could style X axis processing off of this.

 

In the mean time, I'll try to put this into some self-contained function, but this is pretty easy to implement.

 

Rob



[TOPIC: post.html]
#23

JonPM

[GLOBAL: userInfoPane.html]
JonPM
  • Corona Geek

  • 1,077 posts
  • Corona SDK


In the mean time, I'll try to put this into some self-contained function, but this is pretty easy to implement.

 

Rob

 

 

Looking forward to this Rob.  I'm currently in the middle of a project, which is on hold until this key event thing can get sorted out.  



[TOPIC: post.html]
#24

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,535 posts
  • Enterprise

I'm not sure how successful a stand alone function will be actually. The above works pretty good. I dropped it into my app and adjusted it for my table of objects and how I track them and it manage the previous button state.

 

Rob



[TOPIC: post.html]
#25

avlepel

[GLOBAL: userInfoPane.html]
avlepel
  • Contributor

  • 132 posts
  • Corona SDK

Hi all,

 

right now (daily build 2016.2818) there are no key events for directions "up", "down", "left", "right" dispatched if you listen for the Apple TV remote keys using:

 

Runtime:addEventListener( "key", onRemoteKeyEvents )

 
If you still would like to have the direction keys when the user swipes on the little touchpad just drop the code below into your project. It detects swipes and dispatches the missing key events.
 
Many thanks to Rob for his code snippet from above! 
 

Best

Andreas

local resetAt0 = true


local function onAxisEvent( event )

	local mappedEvent = { name = "key", phase = "down", keyName = "" }
	local delta = event.normalizedValue

	if not event.axis or (event.axis.type ~= 'y' and event.axis.type ~= 'x') then
		return
	end
	
	if resetAt0 and delta ~= 0 then
		return
	end
	resetAt0 = false

	if math.abs(delta) > 0.5 then
		if event.axis.type == "x" then
			if delta < 0 then
				mappedEvent.keyName = "left"
			elseif delta > 0 then
				mappedEvent.keyName = "right"
			end
		elseif event.axis.type == "y" then
			if delta < 0 then
				mappedEvent.keyName = "up"
			elseif delta > 0 then
				mappedEvent.keyName = "down"
			end
		end

		resetAt0 = true
	end

    if mappedEvent.keyName ~= "" then
		Runtime:dispatchEvent( mappedEvent )
		print( "DISPATCHED: " .. mappedEvent.keyName )
	end
end

Runtime:addEventListener( "axis", onAxisEvent )




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]