Kodi Community Forum

Full Version: Android TV Remote Control keymap
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
I just wanted to properly map the keys of the Android TV Remote Control app, or more specifically the Back button. So I first captured the keycodes via logging:

Code:
CAndroidJoystickState::ProcessEvent(type = key, keycode = 4, action = 0): pressed
CAndroidJoystickState: setting value for button [4 | 109] to 1
Button [ 4 ] on virtual-remote pressed
Empty button map detected for game.controller.default

Next step was to create keymap file which I named virtual-remote.xml:

Code:
<keymap>
  <global>
    <remote name="virtual-remote">
      <button id="4">Back</button>
      <button id="85">PlayPause</button>
    </remote>
  </global>
</keymap>

I placed it into a backup captured by the Kodi Backup add-on, then restored from that. I verified the file to be under:

Code:
/storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/userdata/keymaps

So I restarted Kodi but unfortunately, the Back action is not captured. Log is still the same as above. What am I missing?

Where I wasn't quite sure:
I took the name 'virtual-remote' from the log. I assume it is correct to apply that one in the XML?
I chose the remote tag in the XML. Do I have to use keyboard maybe?
The virtual-remote now appears twice under Input>Peripherals.

I am also attaching a log of the Kodi boot phase (with the above XML in place) and several non-working Back button presses. [LOG]
Seems my XML is wrong:

Code:
09:51:13.918 T:18446744072427202864   ERROR: Remote Translator: Can't find button button
09:51:13.918 T:18446744072427202864   ERROR: Previous line repeats 1 times.
Changed <remote> to <joystick>:
Code:
<keymap>
  <global>
    <joystick name="virtual-remote">
      <button id="4">Back</button>
      <button id="85">PlayPause</button>
    </remote>
  </joystick>
</keymap>

Still not working. [LOG]

Code:
10:06:04.456 T:18446744072427202864   DEBUG: Keyboard: scancode: 0x04, sym: 0x0008, unicode: 0x0000, modifier: 0x0
10:06:04.509 T:18446744072429324592 WARNING: CPeripheralBusAndroid: ignoring input event for unknown input device with ID 79
10:06:04.541 T:18446744072427202864   DEBUG: OnKey: backspace (0xf008) pressed, action is Back

Seems like it is now detecting the action, but it is not executed.

Need help.
OT, but why do you even bother with that one?
To me it is to basic. I'm using TV remote with customized buttons and I'm quite pleased with it. In fact, so much that I hardly use Kore anymore.
I love it basic Wink .

Probably somebody can help Sad .
Same error still inside with the joystick variant:
Code:
10:05:45.387 T:18446744072427202864    INFO: Loading special://masterprofile/keymaps/virtual-remote.xml
10:05:45.387 T:18446744072427202864   ERROR: Joystick Translator: Can't find button button
10:05:45.389 T:18446744072427202864   ERROR: Previous line repeats 1 times.
10:05:45.389 T:18446744072427202864    INFO: Loading special://profile/keymaps/virtual-remote.xml
10:05:45.390 T:18446744072427202864   ERROR: Joystick Translator: Can't find button button
10:05:45.391 T:18446744072427202864   ERROR: Previous line repeats 1 times.

Next thing I will try:
Code:
<keymap>
  <global>
    <keyboard>
      <key id="4">Back</key>
      <key id="85">PlayPause</key>
    </keyboard>
  </joystick>
</keymap>
looking at it you're not ending your global tag?

so you have :

Code:
<keymap>
   <global>
     <keyboard>

but your'e closing it off with:

Code:
</keyboard>
</joystick>
</keymap>

should it not be:


Code:
</keyboard>
</global>
</keymap>
Yes, of course. Was just wrong in the forums, but not in Kodi Wink

Code:
<keymap>
  <global>
    <keyboard>
      <key id="4">Back</key>
      <key id="85">PlayPause</key>
    </keyboard>
  </global>
</keymap>

It however also does not work. [LOG]

virtual-remote.xml is now read correctly it seems:

Code:
17:09:57.836 T:18446744072427301168    INFO: Loading special://masterprofile/keymaps/virtual-remote.xml
17:09:57.839 T:18446744072427301168    INFO: Loading special://profile/keymaps/virtual-remote.xml

But when I press the button:

Code:
17:10:23.892 T:18446744072429422896   DEBUG: CAndroidJoystickState::ProcessEvent(type = key, keycode = 4, action = 0): pressed
17:10:23.893 T:18446744072429422896   DEBUG: CAndroidJoystickState: setting value for button [4 | 109] to 1
17:10:23.903 T:18446744071994788144   DEBUG: Button [ 4 ] on virtual-remote pressed

I just can't get this Back button to work and I still don't know what the right approach would be. This approach looked the best so far (even though the XML also wasn't read properly). It just did not want to execute the action.
It looks like your soft remote is being detected as a joystick. If that is the case, you can map it to a controller profile (see here).

The actions for game controllers are handled in the joystick.xml keymap. The wiki also has a section to modify joystick.xml.

Currently, joysticks aren't detected on startup on Android. Once the GitHub PR you commented on is merged, this problem should be fixed.

If the soft remote still doesn't work on tonight's nightly, I'll download the app and see what I can do.
Quote: It looks like your soft remote is being detected as a joystick. If that is the case, you can map it to a controller profile (see here).
I once did that. I "learned" the button to the Back control of the Kodi default controller. But this Back action did not behave the same as a Backspace on keyboard, see here. The problem I think was that when you reconnect the app (and therefore the remote/joystick), it would lose the state or something. And that will often happen with such a remote as you will lock your mobile device when not using the remote...

This thing is giving me a hard time...

Quote: The actions for game controllers are handled in the joystick.xml keymap. The wiki also has a section to modify joystick.xml.
So if I assign keycode 4 to Back in the XML, it will behave the same as if I "learned" that button in the UI and assigned it to the Back control of the Kodi default controller?

[EDIT]
How would the XML look like? I don't know the button name but only the keycode:
Code:
CAndroidJoystickState::ProcessEvent(type = key, keycode = 4, action = 0): pressed
CAndroidJoystickState: setting value for button [4 | 109] to 1
Button [ 4 ] on virtual-remote pressed
Empty button map detected for game.controller.default

[EDIT2]
Ah, I first have to "learn" the button to the Back control of the Kodi default controller and then, inside the XML, map the Back control to the Back action. Guess this is how it is supposed to work. It probably is PreviousMenu by default. Kind of complicated...

Quote: If the soft remote still doesn't work on tonight's nightly, I'll download the app and see what I can do.
Is this PR targeted for 17.1? Or Leia?
Tonight's nightly will be the 2017-03-03 build available at http://mirrors.kodi.tv/nightlies/. It is a development build of the current state of 17.1 RC 2.

EDIT: Sorry, the fix is in tomorrow's nightly.
What is also funny about Android TV Remote Control is that some virtual buttons are joystick, some others are keyboard...

Like the back button being joystick:
Code:
CAndroidJoystickState::ProcessEvent(type = key, keycode = 4, action = 0): pressed
CAndroidJoystickState: setting value for button [4 | 109] to 1
Button [ 4 ] on virtual-remote pressed

Or play/pause being keyboard:
Code:
Keyboard: scancode: 0x55, sym: 0x00b3, unicode: 0x0000, modifier: 0x0
CAndroidJoystickState::ProcessEvent(type = key, keycode = 85, action = 1): unpressed
OnKey: play_pause (0xf0bd) pressed, action is PlayPause

It can also be seen here that "back" by default is mapped to PreviousMenu inside the default joystick.xml which is just not practical for this remote. You just can't fully navigate Kodi with only PreviousMenu action. So I have to remap it to Back action and everything should be fine. Will try that in the evening.
(2017-03-03, 08:09)CiNcH Wrote: [ -> ]What is also funny about Android TV Remote Control is that some virtual buttons are joystick, some others are keyboard...

I'm not sure why this happens. I'm working on setting up a debug environment on the Shield so that I can continue hunting down the root cause.

(2017-03-03, 08:09)CiNcH Wrote: [ -> ]It can also be seen here that "back" by default is mapped to PreviousMenu inside the default joystick.xml which is just not practical for this remote. You just can't fully navigate Kodi with only PreviousMenu action. So I have to remap it to Back action and everything should be fine. Will try that in the evening.

This makes sense. If the Back action improves things then I can change the defaults. Let me know what you discover.
Quote: I'm not sure why this happens. I'm working on setting up a debug environment on the Shield so that I can continue hunting down the root cause.
I am using the iOS version of the Android TV Remote Control app BTW, see here. But I assume that the Android version behaves the same.

Quote: This makes sense. If the Back action improves things then I can change the defaults. Let me know what you discover.
Sure.
OK, I made some progress...

Checking the default joystick.xml, you will find this:

Code:
<b>Back</b>
...
<back>PreviousMenu</back>

So I simply "learned" the back button on Android TV Remote Control to the B control (instead of the Back control) on the Kodi default controller. That basically improved navigation a lot and I didn't need to alter joystick.xml.

I leave up to you what you want to do with <back> by default in joystick.xml. I never found PreviousMenu to be very useful. But it is probably best to leave it as it is to not break things for others...

There is still a problem with reconnecting the app, after which the remote behaves differently. Here is what I did:

(1) start Kodi with Android TV Remote Control opened and connected
(2) switch to PVR channel 'ORF1 HD'
(3) press Back button > main menu opens with 'ORF1 HD' still playing in background
(4) press Back button > main menu closes and 'ORF1 HD' again playing in foreground
(5) kill Android TV Remote Control app and re-open
(6) press Back button > main menu opens and 'ORF1 HD' playback is stopped (should be playing in background like before though)
(7) upload log

LOG

Why does Back suddenly behave differently after reconnecting the Android TV Remote Control app? It always stops playback on Back to main menu. May your PR fix this?
Pages: 1 2 3 4