How to open up another remote
I've searched for an hour and found nothing. How can I open up another remote on my phone programatically? So I want to define a shortcut button to another remote.
I guess I have to execute this on my phone:
I just dont know the way to do this.
Ok, I figured you meant open a remote from a custom remote? Took me a while to find this too.
This goes in your remote.lua:
local dev = require("device"); actions.open_chrome_remote = function() dev.switch("Unified.Chrome"); end
And this in your layout.xml:
<button text="open chrome remote" ontap="open_chrome_remote" />
@nathan323 Could you also tell me an elegant way to incorporate an action / button from another remote into my remote without copying the complete source code.
Sure :) There is a community thread here that shows the custom remote I use. I have printed the full remote.lua file. But an excerpt relevant to borrowing other remotes codes would be for example Netflix:
local keyboard = libs.keyboard; --@help Toggle playback state actions.play_pause = function() keyboard.stroke("return"); end
That is lifted from Netflix remote code, and is about as simple as it gets. The only library it calls is keyboard, the keyboard press is just the enter key. So you just need to copy the button code, then whatever library it using. Code for loading libraries are usually at top of remote.lua file.
Sometimes the remote button will do a bit more behind the scenes, and I'll want that too, for example VLC:
local kb = libs.keyboard; local win = libs.win; --@help Focus VLC application actions.switch_vlc = function () local hwnd = win.window("vlc.exe"); win.switchtowait("vlc.exe"); end --@help vlc play toggle actions.vlc_play_toggle = function() actions.switch_vlc(); keyboard.stroke("space"); end
So the cool thing about that is, when VLC doesn't have the focus, eg. you're on the desktop, you finish what you're doing - you can just push the VLC play button and it will check if VLC is active, switch to it, then play it.
So you have to make sure you copy:
- the code for whatever library is being called
local kb = libs.keyboard; local win = libs.win;
- The code for the action of the button:
--@help vlc play toggle actions.vlc_play_toggle = function() actions.switch_vlc(); keyboard.stroke("space"); end
- Any code relevant to any other actions that are being called from the button, in the this case actions.switch_vlc();
--@help Focus VLC application actions.switch_vlc = function () local hwnd = win.window("vlc.exe"); win.switchtowait("vlc.exe"); end
In this case the layout would be:
<button text="vlc play toggle" ontap="vlc_play_toggle" />
There is no need to call the action.switch in your layout, it just gets executed because its nested under the "action.vlc_play_toggle".
I good source for help is https://github.com/unifiedremote/Docs. You'll find the libraries under "Libs". Its good to look through them (and all the other docs in that link) to get a some good ideas about what's possible for custom stuff, but if all you need are buttons that have already been implemented in existing remotes, then sweet :)
I'm always happy to help anyway, I love this shit.
Its great to have someone you can ask! So thanks!
I was thinking about including another another lua file entirely the same way as loading a library. Then just calling the actions from there. But if thats not the way to do it ok.
Could you tell me what you do with the variable hwnd? I guess thats a handle to the window? Could you do win.switchtowait(hwnd); ?
I have a whole lot of questions and for most of these I dont know where to start searching for answers. Should I just start a mixed questions thread?
I know Matlab programing fairly well. At least I've been able to handle everything thats been thrown at me. I've just never been able to get into this object oriented windows stuff. It seems all foreign.