Kodi Community Forum
Solved Adding custom CEC binding - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: OS independent / Other (https://forum.kodi.tv/forumdisplay.php?fid=228)
+---- Thread: Solved Adding custom CEC binding (/showthread.php?tid=359237)

Pages: 1 2


Adding custom CEC binding - pingaan1 - 2020-12-19

Hi,

I'm all new without any experience on the subject. 

I'd like to run a custom batch file at the press of a button on the remote control. Is this possible? 

I'm normally a guy who can figure most things out, if I'm pointed in the right direction. Someone who has any experience and is feeling the urge to help out?

Cheers!


RE: Adding custom CEC binding - pingaan1 - 2020-12-23

Nobody?


RE: Adding custom CEC binding - pingaan1 - 2020-12-24

I can Google myself to finding out that it's possible to add custom python scripts bindings to the CEC remote...? Would it be possible to add a python script, which executes a batch?


RE: Adding custom CEC binding - cvdgenugten - 2021-01-08

(2020-12-24, 12:37)pingaan1 Wrote: I can Google myself to finding out that it's possible to add custom python scripts bindings to the CEC remote...? Would it be possible to add a python script, which executes a batch?
Hi Pingaan,

should be possible using the custom keymap:
https://kodi.wiki/view/Keymap under Section system:
System.Exec(exec)Execute shell commands. The full path to the script has to be placed inside the parentheses.
System.ExecWait(exec)Execute shell commands and freezes Kodi until shell is closed. As well as for "System.Exec(exec)", the full path to the script has to be placed inside the parentheses.


for example: Edit the config file (if it doesn't exist, create it) ~/.kodi/userdata/keymaps/remote.xml

add something like this to run script /storage/on.sh:
<keymap>
    <MyVideoLibrary>
        <remote>
        <left><start>System.Exec("/storage/on.sh")</start></left>
        </remote>
    </MyVideoLibrary>
    <MyVideoFiles>
    <remote>
        <left>ContextMenu</left>
    </remote>
    </MyVideoFiles>>
</keymap>

I did not check the syntax, so there could be some errors there, but most likely will get you in the right direction.
Let me know if this works for you.


RE: Adding custom CEC binding - cvdgenugten - 2021-01-08

(2021-01-08, 23:50)cvdgenugten Wrote:
(2020-12-24, 12:37)pingaan1 Wrote: I can Google myself to finding out that it's possible to add custom python scripts bindings to the CEC remote...? Would it be possible to add a python script, which executes a batch?
Hi Pingaan,

should be possible using the custom keymap:
https://kodi.wiki/view/Keymap under Section system:
System.Exec(exec)Execute shell commands. The full path to the script has to be placed inside the parentheses.
System.ExecWait(exec)Execute shell commands and freezes Kodi until shell is closed. As well as for "System.Exec(exec)", the full path to the script has to be placed inside the parentheses.


for example: Edit the config file (if it doesn't exist, create it) ~/.kodi/userdata/keymaps/remote.xml

add something like this to run script /storage/on.sh:
<keymap>
    <MyVideoLibrary>
        <remote>
        <left><start>System.Exec("/storage/on.sh")</start></left>
        </remote>
    </MyVideoLibrary>
    <MyVideoFiles>
    <remote>
        <left>ContextMenu</left>
    </remote>
    </MyVideoFiles>>
</keymap>

I did not check the syntax, so there could be some errors there, but most likely will get you in the right direction.
Let me know if this works for you.

Just FYI, the above should map the key <left> on the remote control to the script. If you wish to have another key, e.g. the blue button, use tags <blue>...</blue>


RE: Adding custom CEC binding - pingaan1 - 2021-01-20

Hey!

I tried it out, but I can't get it to run. 
It's probably because I'm a Windows user. 

This is the code I used. Should probably be altered, like I said. Not sure how though.

remote.xml in "C:\Users\pingaan\AppData\Roaming\Kodi\Userdata\Keymaps\

<keymap>
    <MyVideoLibrary>
        <remote>
        <red><start>System.Exec("D:\Roms\killall2.lnk")</start></red>
        </remote>
    </MyVideoLibrary>
    <MyVideoFiles>
    <remote>
        <red>ContextMenu</red>
    </remote>
    </MyVideoFiles>
</keymap>


RE: Adding custom CEC binding - cvdgenugten - 2021-01-20

(2021-01-20, 22:16)pingaan1 Wrote: Hey!

I tried it out, but I can't get it to run. 
It's probably because I'm a Windows user. 

This is the code I used. Should probably be altered, like I said. Not sure how though.

remote.xml in "C:\Users\pingaan\AppData\Roaming\Kodi\Userdata\Keymaps\

<keymap>
    <MyVideoLibrary>
        <remote>
        <red><start>System.Exec("D:\Roms\killall2.lnk")</start></red>
        </remote>
    </MyVideoLibrary>
    <MyVideoFiles>
    <remote>
        <red>ContextMenu</red>
    </remote>
    </MyVideoFiles>
</keymap>
Hi,

I see you're trying to EXECUTE a .lnk file, I don't think kodi will do that. I am unsure whether it will work, but can you try to place the executable file the lnk shortcut is pointing to instead of "D:\Roms\killall2.lnk", e.g. "D:\Roms\myexefile.exe"

Hopefully that works. On linux it executes binaries when placed in the <start>System.Exec("/path/to/binary")</start> directive, as per the documentation.
Good luck!


RE: Adding custom CEC binding - pingaan1 - 2021-01-21

New code: 

<keymap>
    <MyVideoLibrary>
        <remote>
        <red><start>System.Exec("D:\bajs.exe")</start></red>
        </remote>
    </MyVideoLibrary>
    <MyVideoFiles>
    <remote>
        <red>ContextMenu</red>
    </remote>
    </MyVideoFiles>
</keymap>

Doesn't work. From what I understand it's supposed to run when I press the red button on the remote when I'm browsing my movies? Is it possible to make it a global thing instead?


RE: Adding custom CEC binding - pingaan1 - 2021-01-21

My guess is that  <start>System.Exec("/path/to/binary")</start> is different in Windows. Can't really find anything about it in the Wiki... =(


RE: Adding custom CEC binding - cvdgenugten - 2021-01-21

(2021-01-21, 00:21)pingaan1 Wrote: My guess is that  <start>System.Exec("/path/to/binary")</start> is different in Windows. Can't really find anything about it in the Wiki... =(

Hi,

syntax was off. I don't have CEC remote for windows PC, so I tested this on windows 10, kodi 18.9:
placed the following in my profile under AppData\Roaming\Kodi\userdata\keymaps\keymap.xml:
Code:
<keymap>
 <global>
  <keyboard>
   <key id="0xf09b">System.Exec("calc.exe")</key>
  </keyboard>
 </global>
</keymap>

The key ID I found, turning on debug logging and watching kodi.log for entries as I pressed F12, the key I wanted to map.
Now when I press F12, a calculator pops up, as expected.

As mentioned, I don't have the HDMI CEC remote option on my windows PC, but I assume the following should work:
Code:
<keymap>
 <global>
  <remote>
   <red>System.Exec("calc.exe")</red>
  <remote>
 </global>
</keymap>

This should (globally) map the red key on the remote input to execute the system command "calc.exe".
Let me know if this works for you?


RE: Adding custom CEC binding - cvdgenugten - 2021-01-21

(2021-01-21, 14:57)cvdgenugten Wrote:
(2021-01-21, 00:21)pingaan1 Wrote: My guess is that  <start>System.Exec("/path/to/binary")</start> is different in Windows. Can't really find anything about it in the Wiki... =(

Hi,

syntax was off. I don't have CEC remote for windows PC, so I tested this on windows 10, kodi 18.9:
placed the following in my profile under AppData\Roaming\Kodi\userdata\keymaps\keymap.xml:
Code:
<keymap>
 <global>
  <keyboard>
   <key id="0xf09b">System.Exec("calc.exe")</key>
  </keyboard>
 </global>
</keymap>

The key ID I found, turning on debug logging and watching kodi.log for entries as I pressed F12, the key I wanted to map.
Now when I press F12, a calculator pops up, as expected.

As mentioned, I don't have the HDMI CEC remote option on my windows PC, but I assume the following should work:
Code:
<keymap>
 <global>
  <remote>
   <red>System.Exec("calc.exe")</red>
  <remote>
 </global>
</keymap>

This should (globally) map the red key on the remote input to execute the system command "calc.exe".
Let me know if this works for you?

Oops, forgot to close the remote tag... typo:
Code:
<keymap>
 <global>
  <remote>
   <red>System.Exec("calc.exe")</red>
  </remote>
 </global>
</keymap>

Let me know!


rted this - pingaan1 - 2021-01-22

(2021-01-21, 14:58)cvdgenugten Wrote:
(2021-01-21, 14:57)cvdgenugten Wrote:
(2021-01-21, 00:21)pingaan1 Wrote: My guess is that  <start>System.Exec("/path/to/binary")</start> is different in Windows. Can't really find anything about it in the Wiki... =(

Hi,

syntax was off. I don't have CEC remote for windows PC, so I tested this on windows 10, kodi 18.9:
placed the following in my profile under AppData\Roaming\Kodi\userdata\keymaps\keymap.xml:
Code:
<keymap>
 <global>
  <keyboard>
   <key id="0xf09b">System.Exec("calc.exe")</key>
  </keyboard>
 </global>
</keymap>

The key ID I found, turning on debug logging and watching kodi.log for entries as I pressed F12, the key I wanted to map.
Now when I press F12, a calculator pops up, as expected.

As mentioned, I don't have the HDMI CEC remote option on my windows PC, but I assume the following should work:
Code:
<keymap>
 <global>
  <remote>
   <red>System.Exec("calc.exe")</red>
  <remote>
 </global>
</keymap>

This should (globally) map the red key on the remote input to execute the system command "calc.exe".
Let me know if this works for you?

Oops, forgot to close the remote tag... typo:
Code:
<keymap>
 <global>
  <remote>
   <red>System.Exec("calc.exe")</red>
  </remote>
 </global>
</keymap>

Let me know!

Got it working! Great, thanks!! =))

This, however, leads me to a followup question or two even.

1. When I press the button the app runs, but the focus falls back on Kodi. Is there a way to focus the app instead? I've tried calling upon it... Wait! I sorted this one out with AutoHotKey. 
2. How can I bind the remotes buttons to do keyboard strokes instead eg. left remote button doing left arrow on the keyboard?

Thanks a ton again! <3


RE: Adding custom CEC binding - pingaan1 - 2021-01-22

I haven't tried this yet, but perhaps it's as simple as putting the key code within the tags;

<keymap>
<global>
<remote>
<red>key id="0xf09b"</red>
<remote>
</global>
</keymap>

In this case binding F12 to the red key...?


RE: Adding custom CEC binding - pingaan1 - 2021-01-22

Like this of course:

Code:
<keymap>
<global>
  <remote>
   <red>key id="0xf09b"</red>
  </remote>
</global>
</keymap>



RE: Adding custom CEC binding - cvdgenugten - 2021-01-22

(2021-01-22, 17:52)pingaan1 Wrote: Like this of course:
Code:
<keymap>
<global>
<remote>
<red>key id="0xf09b"</red>
</remote>
</global>
</keymap>

Great to hear you got it working, case closed on that one. It had to be something simple, as I remember having the need in the past and I got it working.

rgdg the remote mapping to initiate a "virtual" keystroke, I doubt that is possible. The keymap used by Kodi will map a source to a function embedded in Kodi faik, not so much a source translation.
However, nothing is impossible, however I doubt this is something I would know Wink

I used to have this device, FLIRC, which would be able to do just that though. I would (seperately from Kodi, you have a binary you can run in windows for FLIRC) map a random remote to any key (real keypress) Kodi would accept. The red button would map to "keypress of my choice". This is, as mentioned, completely seperate from Kodi, requiring you to buy the hardware. The Flirc receiver is a universal infrared reader, which will map real keypresses to whatver you're sending from the remote. (source: https://flirc.tv/more/flirc-usb)

Anyhoo, glad to be of help to get your original issue solved.