Detect back button event from LG Magic remote#127
Conversation
| ArrowUp: SupportedKeys.Up, | ||
| ArrowDown: SupportedKeys.Down, | ||
| Enter: SupportedKeys.Enter, | ||
| Backspace: SupportedKeys.Back, |
There was a problem hiding this comment.
I think this simple change would be enough, wouldn't it? 😁 No need for the rest below. Or maybe I'm missing something?
| Backspace: SupportedKeys.Back, | |
| Backspace: SupportedKeys.Back, | |
| GoBack: SupportedKeys.Back, |
There was a problem hiding this comment.
I wish not to use that ugly hack in my code 🤪. What is happening when I pressed the back button on the Lg Magic Remote is that an event is raised with
event.code empty and event.key === 'GoBack'
The mappedKey is mapped on event.code so it doesn't trigger the desired key.
Any idea about how to fix this in a proper way?
🙏
There was a problem hiding this comment.
Hahaha alright, that's the thing I missed indeed!
Then this will work. It's just the example app anyway.
My suggestion though would be to make the if branch more explicit as an exit condition (following this). What do you think? 😁
//For LG WebOs Magic Remote
if (event.key === 'GoBack') {
this.eventEmitter.emit('keyDown', SupportedKeys.Back);
return
}
if (!mappedKey) {
return;
}
this.eventEmitter.emit('keyDown', mappedKey);There was a problem hiding this comment.
Oh yes! Far better!
It's a sample app, but it's my favorite TV app around! There are some options for the future we can discuss like:
- Promoting this sample as a boilerplate for TV!
I have a private repo of this app I use for studying/experimenting/presenting.
There was a problem hiding this comment.
Do you have a reference for using .key on the event? webOS docs suggest using keyCode === 461
There was a problem hiding this comment.
I've tested on an LG C2 and experienced they key is code was empty and key is GoBack
There was a problem hiding this comment.
Did you find that keyCode was empty as well? If that's the case then their docs are wrong (not the first time) 😅
I don't have a smart remote available, but testing on simulator (v24) and with LG 32LQ630BPUA keyCode behaves as documented
There was a problem hiding this comment.
Yes keycode was empty using this app. @matthewcaminiti Can you test the app in this repos with your TV/Emulator and check what code is returned?
There was a problem hiding this comment.
Ah good to know! I gotta test on a newer device. May need to use both key/keyCode to cover old+new WebOS.
On my TV device (LG 32LQ630BPUA ... old model with latest software) I've yet to figure out how to get logs from it, but when using key === 'GoBack' it doesn't work, suggesting key is empty.
On simulator it's as follows:
This to detect the "Back" button of an LG Magic Remote for Web OS.
Tested with the web build of the project.
The appinfo.json of the WebOS project needs to include
"disableBackHistoryAPI": trueMore info for LG WebOS here