Jump to content
Flirc Forums

Flirc with Android TV


rothgar

Recommended Posts

*UPDATE* Final key mappings I found below

 

I'm got my Flirc working with Android TV. A USB keyboard works just fine with a microUSB adapter. Here's the key mapping I found

up = up
down = down
left = left
right = right
play/pause = enter
back = backspace/esc
search = Super (Windows) - could not map
home = alt+esc (doesn't close apps*)

I got everything working except for search and home. Search isn't really needed because it only accepts voice search by default so it looks for a bluetooth mic to activate which I don't have. No home button is killing me though. I can't exit some apps (XBMC) and can't easily jump between apps.

 

Is there a way to manually map a remote button to the media home button?

 

Just for reference, here's the Nexus Player's remote

 

uqX37my.png

and here's a quick picture of the adapter + flirc

B3Y_gpvCEAABOCn.jpg

If someone could help me map the home button this will be perfect.

 

*I found something interesting in that the keyboard shortcuts for home (alt+esc) will not exit apps. When you are within an app it only sends a back keypress. So if the app doesn't have a way to exit within the menu you may be stuck. I tested this with the flirc as well as with a keyboard. The home button on the remote is somehow detected differently when in an app.

Edited by rothgar
Link to comment
Share on other sites

Hi,

 

Do you know how to use command line? There is an executable called flirc_util.exe in Flirc folder (on Windows) or just flirc_util under Linux and OS X.

 

You can try running it like that:

flirc_util.exe record_api 154 102

(remove .exe from the command name in case of Linux and OS X). After you press enter it will wait for a remote button to be pressed like in the GUI.

 

Please let me know if this works.

Link to comment
Share on other sites

Normally the record_api command in flirc_util.exe allows you to record a key with a modifier. The first number is a combination of modifiers (left/right shift/control/alt/windows) and the second is a USB HID key code of the key. There is a special case when the second number is 102. This tells Flirc to send a key code defined by a first number from different HID usage table. The code 154 then means a Media Select Home button. I'm not sure if this is the correct one so you need to check it yourself.

 

I've described more in this thread:

Link to comment
Share on other sites

So 154 didn't work. I mapped it and tried pushing the remote key and nothing happened. So instead on my linux machine I ran xev to try and see what code my "home" key was pushing and it showed code 180 (B4 on the list). I tried mapping tat key and it just does a normal exit/backspace. Do you know another way to read the raw input from the keyboard media key? It might be tricky because I have to push function + f12 to get the key. I tried searching for a way to read the raw input but couldn't find anything that worked with the function/media keys so anything else you know of would be a big help.

 

Thanks

Link to comment
Share on other sites

Can you try with

flirc_util record_api 11 102

?

 

This is what I'm getting on HID interface when pressing Home media button on my Logitech keyboard. I've used EventGhost's Generid HID input plugin. It can't read input from keys in the HID keyboard usage table (Windows captures this earlier with hid keyboard filter driver) but it sees media key presses which are in HID consumer usage table.

Link to comment
Share on other sites

11 102 sends the "back" button but doesn't exit the app or return to the home screen.

 

I tried paring the nexus player's remote with my computer so I could read what input it sends but it won't show up on my computer when in pairing mode. :-/

 

Maybe I'm missing a step. After doing record_api is there anything I need to do to unset that IR code from the keyboard button sent? I have used the same IR code all 3 times and just thought maybe the old keys are still set in the flirc and new keys aren't being used.

Link to comment
Share on other sites

You should not be able to record the same key again without deleting it before recording again.

 

My last suggestion is for you to try all codes from 1 to 255 (second number still 102). I know that this may take some time. Maybe save your current config from the GUI or command line, then erase Flirc and start recording starting from code 1 102 and increment for all available buttons on the remote (remember which code for which button). Then try all the buttons with Android TV and if you don't find the Home button then erase again and start from next code after the one you recorded in previous round.

Link to comment
Share on other sites

I have an old Acer A500 tablet at home which has a normal USB A port. I only had time to do a quick test and I couldn't get any response from Flirc using my custom configuration. I've also confirmed that the media home button on a normal USB keyboard works properly with the tablet.

 

I have another Flirc which is not being used right now so I'll do some tests with it later.

Link to comment
Share on other sites

Alright, I went through every button 1-256. It wasn't too bad because I was able to write a quick loop to do 10 at a time and then just ran flirc_util format after each run.

 

I didn't find the the home or search buttons so I'm not sure if there are other keys to try or what that means. Maybe just saying that I'm using a Goldtouch keybard and the fn+f10 does home and fn+f11 does search.

 

Although I didn't find the keys I was looking for, I did find some other interesting keys people may want to check out.

 

All of these are the number before 102.

 

48 = sleep+wake

52/50 = sleep only (no wake)

53 = wake only (no sleep)

65/54/132 = select

66, 67, 68, 69 = up, down, left, right

111/112 = brightness controls (did nothing on my monitor except show the slider)

137 = Launch TV app (which isn't in the menu) but the app crashes immediately and asks to submit a bug

140 = prompted and said "you don't have an app that can do this"

 

 s2eXdsWl.jpg

 

All the other keys I tried 1-256 didn't do anything on the device

Link to comment
Share on other sites

Very nice finds.

 

Here is a list of HID usage tables and codes: http://www.freebsddiary.org/APC/usb_hid_usages.php. The codes are given in hex format so you need to convert from/to decimal. The code 140 (0x8C hex) in table 12 you've found to do something is defined as  Media Select Telephone so it would probably work on phones and invoke dialer app.

 

On the other hand I think I've just found the working key combination for invoking Home. It works at least for me on the Acer tablet. First go in the GUI into File->Advanced in the menu and check Sequence Modifiers option. Then record Alt+Esc or Win+Esc for Home button and Win+Space for Search button. Give it a try and let me know.

Link to comment
Share on other sites

Alt+esc got the home button!!

 

Although I'm on a mac right now and the command+esc and command+space didn't do home/search. I can try again later from a windows machine but I assume they send the same keys.

 

I've found with mine while alt+esc seems to work, it doesn't work as expected in some apps (plex for example)

 

Cheers Rob.

Link to comment
Share on other sites

  • 7 months later...

yawor/Jason,  do you have a command line to map to Media home key? 

 

I just bought Flirc and Nexus player and integrate them with my universal remote URC-880. I got every keys mapped and working on my URC-880 except Nexus Home button, which can exit any apps and go back to Nexus home screen. Logitech keyboard Media home key can also work the same as Nexus home button.

 

I have a workaround for this home button:

1)  Alt + Esc take me to Nexus home screen for all app (youtube, Kodi), except Netflix

2)  To exit Netflix,  I use F12 key but it has a confirmation pop-up (No/Yes).  to create an one-click button to exit Netflix, I combine F12 and right navigation key (to select 'yes' using URC-880).

 

The workaround above is working but not as seemless as using ONE home Nexus button (or keyboard media home key).

 

thanks to yawor from another thread.  I used command line to map window key.  combing window key and right navigation key into one search button on my URC-880,  I can launch search globally from anywhere (no matter what app you are in). 

Edited by fox123
Link to comment
Share on other sites

just found another way to mimic Home button: Alt + Tab.  This would take you back to Nexus home screen from any apps, including Netflix.  This is better my previous work around above.  Now I can use one button on my universal remote to go back to Nexus home from any apps.

 

I noticed one different about this key combo.  when it takes you back to the home screen, you would see a text line "your recent screen is here" or something like that. the home button from Nexus remote does not have this.

Link to comment
Share on other sites

  • 5 months later...

Hi there,

I am facing the same situation as you guys, trying to take the most of my flirc to control my nexus player.

I investigated how the Android key triggering system works, and I think that I pretty much understand why combinations like alt+esc works only in some programs, why it always work with the nexus remote, and what we need to achieve to have a fully working remote (even if I am not there yet).

So the first thing Android does is to match a HID codes it receives to the related  "Linux key code" (also called "scan code"), using the appropriate layout file which is stored in the "/system/usr/keylayout/xxxxxxx.kl" files. Each "Linux key code" will trigger an "Android key codename". In our case, Android will use the Generic.tl layout for the flirc because there is no specific file for it. An other example is the original remote of the nexus player which uses the "Nexus_Remote.kl" layout. Later on, we will see that we can create our own layout file for any input device by using its "Vendor ID" and "Product ID". I recommand you to have a look a this sample "Generic.kl" to better understand what .tl files are.

When an "Android key codename" is triggered, it will also be interpreted according to the keychar file, which is stored in the "/system/usr/keychar/xxxxxxx.kcm" files. Most of the "Android key codenames" can result in a different action when used together with a key-modifier such as ctrl, alt, numlock, etc. Those additional actions are specified in the keychar file. Again, Android will use the Generic.kcm keychar in our case, and we could create our own keychar file using the device "Vendor ID" and "Product ID".

Now to make the analyse complete, I have noticed that some Android applications like netflix or kodi will bypass the keychar file, and only the "Android key codenames" called in the layout file will be triggered. That's why a keyboard combination like alt+esc sometimes doesn t work, while in the same condition the original remote will trigger HOME flawlessly.

So how can this help us ? First let's have a look at the "Generic.kl" file. Our main problem is to trigger the HOME and the DPAD_CENTER "Android key codenames" , which are the actions used by the original remote to go to home and perform a click which works with the virtual keyboard. By looking through the file, we can see the two "Linux key code" which correspond to those actions, respectively 172 and 353. Now we need to find which HID codes match those "Linux key codes". For that I found this table where the first row is the HID code in hexa, and the third is the "Linux Key Code", aka LKC, in hexa :

- The LKC 172 makes "0x00ac", which match the HID code "0x0223" (547 in decimal) in the "HID Consumer Page 0x0c" (= table 12).

- Unfortunately there is no match for the LKC 353 = "0x0161". BUT I found that we can use the "Android key codename" KEYCODE_NUMPAD_5 which, after processing through the keychar file, triggers DPAD_CENTER if the numlock is off (which seems to be by default). The LCK for this one 76 makes "0x004c" which match the HID code "0x005d" (decimal 93) in the "HID Keyboard and Keypad Page 0x07" (= table 7).

Thanks to the flirc "record_api" command, we can record HID codes from the 7 and 12 HID tables, but we seem to be limited to a decimal value of 255 (at least in the 12th table, as stated by yawor above). A great new feature would be to simulate any HID code from any HID page via the flirc, without limitations ^^

So what else can we do ? Instead of reproducing complex HID codes to trigger existing LKC, we could simply modify the actions of the LKC in the layout file to trigger our own "Android key codenames". The flirc user "halfluck" already came up with this solution in this thread. The documentation to create a custom layout file is described hereWe should duplicate the Generic.kl file and rename it to "Vendor_20a0_Product_0001.kl", then edit the action of some less used keyboard keys. For example, "key 35 H" could become "key 35 HOME", which would make any flirc record of keyboard key "h" triggers the home screen, whatever application is running in foreground.

The only downside of this method is that you need root to modify the keylayout and keychar folders on Android.

I have not rooted my nexus player yet, but I will keep you updated when I do ;-) If it works as expected, I will order my second flirc :-)

In the meantime, I hope that this post helped some of you. Note that this method is not specific to the Nexus Player, it is valid for all Android versions.

Best regards,

Laurent

 

Edited by kalhimeo
Link to comment
Share on other sites

I played a bit more with the keycodes and the record_api command today.

I have found the HID code for DPAD_CENTER, no need to use the KEYCODE_NUMPAD_5 trick anymore. The code is "0x0c 0x0041" which can be mapped via flirc using "65 102".

It's really a pity that we can't use the full range of the "Consumer Devices" table, that would solve the HOME problem with the code "0x0c 0x0223" (virtually 547 102) without the need for root.

Maybe jason could review a bit the handling of the basic HID codes: since there are only 231 characters in the table "7 - Keyboard/Keypad", could we use some codes from 232 to 255 as exceptions to fully cover the "12 - Consumer Devices" table ? For now you are using the code 102 (Keyboard Power) as an exception to send the first 255 HID codes via the modifier byte, but as we know, one byte is not enough to cover the 667 commands of the "12 - Consumer Devices" table.

Could we imagine using the codes 253, 254 and 255 for this purpose ? Therefore "253" would cover HID commands from 0-255, "254" from 256-511, and "255" from 512 to 667. I think that this would make more sense than using the code 102. We could even imagine to cover more tables with the remaining numbers if needed.

An other solution to fix the HOME button on Android TV only, would be to hard code a unique byte sequence which would reproduce "0x0c 0x0223".

Thanks to the courageous readers who hold till the end ^^

Laurent

Edited by kalhimeo
Link to comment
Share on other sites

You have to open a terminal and type the commands.

On windows explorer, navigate to the flirc folder ( \Program files x86\flirc\) , maintain shift and right clic on an empty space. In the menu you should see "open commands here" (or something like that, my computer is not in english).

You can now type the flirc_util commands in the terminal window which has just open

Link to comment
Share on other sites

  • 2 months later...

Thanks for the help on this guys. I found that with my Forge TV, Win + Enter works as the "proper" home button, exiting even out of Kodi to the home screen.

Ideally, I think I would rather have a button to bring up the Forge TV menu (which can be used to get to the home screen), but I have not been able to figure out a way, may be some proprietary code.

Anyway, hope this helps!

Link to comment
Share on other sites

  • 3 months later...

Does somebody have a config file they can link for the Nexus Player? I'm trying to set the keys, but pressing any key (i.e. up arrow, down arrow) on my keyboard doesn't register.. I can only get IR commands from remote controls to work with this.

Thanks in advance.

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...