Kodi Community Forum

Full Version: Remote mapping to special functions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Not sure if this is possible, but thought I'd ask, I have searched for an answer, but not found anything....


I am using Raspbmc, and have set up the remote control I have to work as required with it (it sends keyboard presses, so I have made a keyboard.xml file in 'userdata').

I am now wanting to add a feature, but can't find how to do it. As the Raspberry is designed to be left on, I thought it would be nice to have the screen go blank when the power button is pressed on the remote. I have set the screensaver as 'blank', and have added the following to the keyboard.xml file:

<f4 mod="ctrl,alt">screensaver</f4>

I saw that 'screensaver' was an action available from ButtonTranslator.cpp, but it is not activating the screensaver.

So, the question is, is there a way of triggering the screensaver via a 'hotkey'? effectively this would be activating the 'preview' function found under Appearance.
The "screensaver" reference in ButtonTranslator.cpp is likely referring to it as a window rather than an action (like "fullscreenvideo" or "videolibrary"), so I would try
Code:
XBMC.ActivateWindow(screensaver)
Might not want to do that after all. I just tried it, and while it does work, it won't back out of it. As in, if you keep pressing buttons the screen will still stay black. You'll even hear navigation sounds in the background and can trigger things, but you can't see anything.
Interesting....

It does, as you say not revert back when another key is pressed, but I have a workaround - I can set one button to do
PHP Code:
XBMC.ActivateWindow(screensaver

then have another do
PHP Code:
XBMC.ActivateWindow(home

Its not ideal, but it will do unless anyone else has a suggestion??

Thanks for pointing me in the right direction.
Ah, I just had a thought. Since "screensaver" is a window then we can do a specific keymap for when the screensaver is active.

So you can do something like

Code:
<global>
      <keyboard>
          <power.button.here>XBMC.ActivateWindow(screensaver) </power.button.here>
      </keyboard>
  </global>
  <screensaver>
      <keyboard>
          <power.button.here>XBMC.ActivateWindow(home)</power.button.here>
      </keyboard>
  </screensaver>

That way you only have to use one button.
Genius!

Thanks for the tip. That will do the job.

Now I'm thinking more adventurous... how about the first press does two things - stops anything currently playing, then activates the screensaver? With the current system if someone presses the power button while a video is playing the video will continue in the background (sound and all), so stopping it first would also solve this.

Not sure if one button can have two actions, or if RunScript(script[,args]*) might do it, or am I just getting too adventurous!!
I think you can run a script, but I don't know much about scripts myself. Others here do, so maybe they'll give us some hints.
You can use a simple Python script with the following contents:
Code:
import xbmc
xbmc.executebuiltin( "PlayerControl(Stop)" )
xbmc.executebuiltin( "ActivateWindow(Screensaver)" )

Save your script with a .py extension. Since you're running Linux, you need to make the script executable with the following command (you may already know this):
Code:
chmod a+x /path/to/your/script.py

In the <FullscreenVideo> section of your keyboard.xml, assign your same remote control button to execute your script:
Code:
<keymap>
  :
  <FullscreenVideo>
    <keyboard>
      <power.button.here>RunScript(path/to/your/script.py)</power.button.here>
    </keyboard>
  </FullscreenVideo>
  :
</keymap>

You still need the key mappings provided by Ned above for the <global> and <screensaver> sections of keyboard.xml.

Your remote control button will now behave as follows:
  • When you press your button anywhere in XBMC, it will display the screensaver. Press the button again and the XBMC homepage is displayed.
  • However, when playing a video, pressing the button will first stop the video and then display the screensaver. Press the button again and the XBMC homepage is displayed.
Spot on!

It took a while to figure out what path to use (I know nothing about Linux), but have got it working perfectly.

Thanks to Ned Scott & artrafael, this is going to make the setup very slick - possibly even slick enough to get the wife & kids using it!

Thanks again guys.
(2012-11-05, 23:49)salawinder Wrote: [ -> ]Thanks to Ned Scott & artrafael, this is going to make the setup very slick - possibly even slick enough to get the wife & kids using it!

Ah, yes... attaining the all-important Family Acceptance Factor (FAF) that allows the marvelous geek-grotto tech toy to matriculate to the family room. Big Grin