How to get key id for USB connected keyboard keys?

I don’t have a CEC remote control for the monitor I am now testing a new OSMC on, instead I have a USB connected keyboard and it woks fine for the ordinary pre-defined stuff I can see in this Kodi Spec.

Now I want to create special jump commands for use when playing a video and with the TV where there is a CEC remote control I could do that using the keymaps dir in an xml file where I have entries like this:

<keymap>
  <FullscreenVideo>
    <keyboard>
      <key id="251">Seek(-175)</key> <!-- red -->
      <key id="252">Seek(-25)</key> <!-- green -->
      <key id="253">Seek(25)</key> <!-- yellow -->
      <key id="254">Seek(175)</key> <!-- blue -->
      <key id="166">Info</key> <!-- UP -->
      <key id="167">Info</key> <!-- DOWN -->
     </keyboard>
  </FullscreenVideo>
</keymap>

I have found the key id values for the various keys by using a special keymap file with 256 entries where each remote keypress prints the key id to the screen.

But I have no idea how to do this using the USB keyboard…
Since there seems to be a 16 bit code used I cannot use the keymap trick (cannot create a 65000+ lines big keymap file).

So how can I find the key id values for keys I press on the USB keyboard?

The easy way to get key id’s is to use the keymap editor. I remember finding a post I think on Kodi’s forum many years ago that explained how to discover that number using a different method but it was rather involved just to wrap your head around it all from what I remember. That being said the correct answer here is to NOT use key id’s unless you actually have to (ie keymapping CEC) and just use key names instead. For a keyboard I would suggest to either just look at Kodi’s default keymap to find the precise names [here] or else pull them yourself from Kodi’s log (which doesn’t work for CEC) by turning on debug logging and then in a ssh session run…

tail -f ~/.kodi/temp/kodi.log | grep HandleKey

When you press keys it will show the key name you need to use in a keymap.

Well, I have not done this before except for with a CEC remote on my 4 LG TV’s. And there I had to use the key id values, which I got by using a special keymap file which just displayed the key id when I pressed the remote’s buttons.

So I have assumed that this is what you need to do…

I would like to use the key names as you say, but where is a list of Kodi recognized key names?
Letters and numbers are easy I guess. But what about special keys like cursor keys and those that do not display anything when used in regular writing?

Assuming keys a,b,c,d etc are named as the symbol printed on the keytop (but lowercase) I tested with this content to make jump functions with specific jump sizes::

<keymap>
  <FullscreenVideo>
    <keyboard>
      <d>Seek(-175)</d> <!-- D -->
      <n>Seek(-25)</n> <!-- N -->
      <q>Seek(25)</q> <!-- Q -->
      <u>Seek(175)</u> <!-- U -->
      <w>Info</w> <!-- W-->
      <home>Info</home> <!-- home -->
     </keyboard>
  </FullscreenVideo>
</keymap>

This turned out to work the same as on my remote. :slight_smile:

But the Info display does not, with the CEC remote I can hit the key twice and on the first hit it brings up the info overlay but on the second hit on the CEC the Info display vanishes but here it stays on screen, I have to use the backspace key to remove it.
Why is that?

I already answered that. If you look at Kodi’s default keymap that I hyperlinked it should be pretty easy to infer what most of these keys are. Otherwise if you run the command I provided in a terminal window with debug enabled it literally tells you the exact key name to use every time you press a button/key (again, except for CEC as it logs incorrect names and can only be mapped using key id’s).

Because you are trying to use a home key to close the FullscreenInfo window without mapping a back action id in the FullscreenInfo window so it would interact in that window. Kodi isn’t going to have that odd assignment mapped by default. If you map to global then it maps everywhere other than a window where it was overridden. Anything mapped anywhere else is only mapped in the window it was mapped in. If you look at the keymap I made for the OSMC remotes you will find that I added mappings for quite a few windows so if you pressed a button to open a window that same button is set to close it as well so you can, like in your example, open and close an info window without moving your finger…