Executing keypress from script?
#1
I've been trying to figure out if i can send a remote keypress from a script. (not execute a script from a keypress)

I found some forum posts and put together:

kodi-send -a "executehttpapi('sendkey(0x00007bdc)')"; but im not getting anything back. 

any pointers? thanks,
Reply
#2
kodi-send can be used with the python built-in functions.

https://kodi.wiki/view/List_of_built-in_functions

This is pretty up to date and "executehttpapi" doesn't exist at all. I'm somewhat interested where you have found that Wink

Let's start the other way round. What would you like to achieve in the end that it requires a (simulated) keypress from a remote. I mean, kodi-send is pretty powerfull and you can also use JSON to let Kodi do whatever you want. So I'm pretty curious what your goal is.
Reply
#3
Kodi-send is able to send button events:
Code:
kodi-send [OPTION] --button=BUTTON

Alternatively you can create a packet for EventServer yourself (b/c this is exactly what kodi-send is doing). In python it could look like this:
Code:

import sys
from socket import *
# osmc-specific thing
sys.path.append('/usr/share/pyshared/xbmc')
from xbmcclient import *

addr = ('127.0.0.1', 9777)
sock = socket(AF_INET, SOCK_DGRAM)
key = sys.argv[1] if len(sys.argv) > 1 else 'down'

packet_btn = PacketBUTTON(repeat=0,
                          down=1,
                          queue=1,
                          map_name='KB',
                          amount=0,
                          button_name=key)
packet_btn.send(sock, addr)

And if no XBMC python libraries are available (or you don't want to use it) you can try the same in bash (using socat):
Code:

#!/bin/bash
# set -x
key=${1:-down}
packet_size=$(echo -n "${key}" | wc -c | awk '{printf "%02x", $1+10}')
byte_1=$(echo "${packet_size}" | cut -b 1-1)
byte_2=$(echo "${packet_size}" | cut -b 2-2)
{
echo -ne "XBMC\x2\x0\x0\x3\x0\x0\x0\x1\x0\x0\x0\x1\x0\x${byte_1}${byte_2}"
echo -ne "\x62\xc4\x25\x45\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x3b\x0\x0KB\x00${key}\x0"
} | socat - UDP4:localhost:9777
Reply

Logout Mark Read Team Forum Stats Members Help
Executing keypress from script?0