v19 An addon script that creates its own keyboard mapping?
#1
I have a an addon that generates music playlists. Works nicely, and I can either run it through cumbersome menu access to addons, or easily using a keymap (~/.kodi/userdata/keymaps/keyboard.xml):

<keymap>
    <global>
        <keyboard>
            <q mod="ctrl">Quit()</q>
            <m mod="ctrl">RunScript(script.audio.playlistgenerator)</m>
        </keyboard>
    </global>
</keymap>

The question is, given how cumbersome this extra install effort is, can the addon use a setting (in settings.xml) that defines a key, to add it to the keymap itself (and change it if the setting changes)?

Haven't found a way to do that yet in the python API or Builtins. But maybe I missed it or it's trikier?
Reply
#2
(2020-07-06, 00:05)ThumbOne Wrote: The question is, given how cumbersome this extra install effort is, can the addon use a setting (in settings.xml) that defines a key, to add it to the keymap itself (and change it if the setting changes)?

If you mean, can the addon be modified to use a setting to define a key and then place that keymapping into the keymap file then my answer would be yes, that's possible.  You would need to translate the path from a Kodi internal path to a system path (so as to stay cross-platfrom) with something like xbmc.translatePath('special://userdata/keymaps/keyboard.xml') then use xbmc.vfs to check if the file exists, open it, parse the xml and see if your keymap already exists.  If yes, has setting changed?  Add keymap to file if necessary and re-write the file out.

Probably more work than editing the keymap file directly though Wink
Learning Linux the hard way !!
Reply
#3
(2020-07-06, 12:03)black_eagle Wrote:
(2020-07-06, 00:05)ThumbOne Wrote: The question is, given how cumbersome this extra install effort is, can the addon use a setting (in settings.xml) that defines a key, to add it to the keymap itself (and change it if the setting changes)?

If you mean, can the addon be modified to use a setting to define a key and then place that keymapping into the keymap file then my answer would be yes, that's possible.  You would need to translate the path from a Kodi internal path to a system path (so as to stay cross-platfrom) with something like xbmc.translatePath('special://userdata/keymaps/keyboard.xml') then use xbmc.vfs to check if the file exists, open it, parse the xml and see if your keymap already exists.  If yes, has setting changed?  Add keymap to file if necessary and re-write the file out.

Probably more work than editing the keymap file directly though Wink
Interesting. Would changing the keymap file have immediate effect on the running instance of Kodi?

Parsing XML isn't hard in Python. And the setting could be a string field and there could be an Action field that runs the script to do the XML seek, parse, rewrite.

Easier to do by hand, sure. But not professional. If I want to share this script with others, I like to think on its settings you could type a key code into a box, press a button and have that key sequence registered to launch the script. In fact this seems essential to me fro all scripts. The only other way I know to run the script is to navigate a pile f menus to find it and run it. Admittedly fewer menus in Chorus and Kore (where the keymap wont apply anyhow, so that's a good thing). But in the Kodi UI, if you have a script you want to use a lot, you need to map it to a keystroke IMHO.
Reply
#4
(2020-07-06, 13:28)ThumbOne Wrote: Would changing the keymap file have immediate effect on the running instance of Kodi?

No, but you can reload it with xbmc.executebuiltin("action(reloadkeymaps)")
Learning Linux the hard way !!
Reply
#5
Excellent! So it looks like it's doable. Albeit complicated enough that it's worth publishing a script that does it ;-)
Reply

Logout Mark Read Team Forum Stats Members Help
An addon script that creates its own keyboard mapping?0