Keymap System.Exec(exec) problem

  • Using Libreelec 10 beta 2, I am trying to map a keyboard f12 key to this System.Exec() call in order to toggle the AV mode over a tcp socket from my keyboard or remote.

    It seems to do something because if I press f12 twice it resets Kodi, so something is wrong and I could use some help or suggestions for a better way to accomplish the same thing. It does not toggle the AV mode like the command does in an ssh window.

    I tried to use log file uploader, but it crashed. I send a one of the log files and try again with the log file uploader if needed.

    Per the log, I can see that the keymap is applied when f12 is pressed and it tries to run python3 /storage/.kodi/userdata/keymaps/AVMD0.py. The command python3 /storage/.kodi/userdata/keymaps/AVMD0.py or /usr/bin/python3 /storage/.kodi/userdata/keymaps/AVMD0.py runs perfectly from an ssh command line.

    keymap.xml:

    <?xml version="1.0" encoding="UTF-8"?>

    <keymap>

    <global>

    <keyboard>

    <f12>System.Exec(/usr/bin/python3 /storage/.kodi/userdata/keymaps/AVMD0.py)</f12>

    </keyboard>

    </global>

    </keymap>

    AVMD0.py:

    import sys

    import socket

    tcpsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    tcpsocket.connect( ('192.168.1.206', 10002) )

    tcpsocket.sendall(b'\rAVMD0 \r')

    data = tcpsocket.recv(1024)

    tcpsocket.close()

    #print('Received', repr(data))

    exit

    Two F12 key presses from the log:

    2021-05-11 11:20:23.544 T:1344 DEBUG <general>: Keyboard: scancode: 0x60, sym: 0x0125, unicode: 0x0000, modifier: 0x0

    2021-05-11 11:20:23.544 T:1344 DEBUG <general>: HandleKey: f12 (0xf09b) pressed, action is System.Exec(python3 /storage/.kodi/userdata/keymaps/AVMD0.py)

    2021-05-11 11:20:23.877 T:1344 DEBUG <general>: Keyboard: scancode: 0x60, sym: 0x0125, unicode: 0x0000, modifier: 0x0

    2021-05-11 11:20:25.691 T:1344 INFO <general>: Skipped 1 duplicate messages..

    2021-05-11 11:20:25.691 T:1344 DEBUG <general>: HandleKey: f12 (0xf09b) pressed, action is System.Exec(python3 /storage/.kodi/userdata/keymaps/AVMD0.py)


    Thanks in advance for any help with this!

    • Official Post

    add this to the beginning of your script

    Code
    #!/usr/bin/env python3 

    and drop the interpreter from the command

    Code
    <f12>System.Exec(/storage/.kodi/userdata/keymaps/AVMD0.py)</f12>
  • Thanks for your reply lrusak. I tried that and the f12 key press is still recognized, but nothing happens which is somewhat of an improvement. Does it matter that python script does not work at the command line unless the interpreter is specified?

    LibreELECMacPro:~ # /storage/.kodi/userdata/keymaps/AVMD0.py

    ': No such file or directory

    LibreELECMacPro:~ # python3 /storage/.kodi/userdata/keymaps/AVMD0.py

    LibreELECMacPro:~ #

    #!/usr/bin/env python3

    import sys

    import socket

    tcpsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    tcpsocket.connect( ('192.168.1.206', 10002) )tcpsocket.sendall(b'\rAVMD0 \r')

    data = tcpsocket.recv(1024)

    tcpsocket.close()

    #print('Received', repr(data))

    exit

    <?xml version="1.0" encoding="UTF-8"?>

    <keymap>

    <global>

    <keyboard>

    <f12>System.Exec(/storage/.kodi/userdata/keymaps/AVMD0.py)</f12>

    </keyboard>

    </global>

    </keymap>

  • Likely DOS line endings. Try dos2unix /storage/.kodi/userdata/keymaps/AVMD0.py

    Edit:

    Thanks mglae, that worked. I'll stick with nano and notepad++ now.

    I have it working as it should now. I changed the xml file from remote.xml instead of keyboard.xml. I am not sure it made the difference, but is correct in this case.

    In addition to the tv View Mode that was toggling, I was getting some kind of kodi context windows up most of the time, especially on successive key process.

    I changed the key from f12 to alt-f12 and it made no difference, but I am sticking with that.

    I then changed the MCE remote key from Visualizations to Aspect and it fixed the problem. The visualizations key must be sending some kind of multiple codes that flirc didn't process with the key map.

    Thanks again to all who chimed in here and to all the libreelec and kodi contributors!

    Edited 2 times, last by Cfan (May 15, 2021 at 3:03 PM).