Rockbox Technical Forums

Support and General Use => Plugins/Viewers => Topic started by: Bilgus on February 19, 2022, 05:29:36 AM

Title: Keyremap plugin - remaps keys in rockbox
Post by: Bilgus on February 19, 2022, 05:29:36 AM
keyremap

I finally have a plugin written to allow users to change keymaps without recompiling
a build.

a lot of support code needed to be written to get to this point

builds after today (02-23-2022) have the keyremp plugin
https://gerrit.rockbox.org/r/c/rockbox/+/3274 (https://gerrit.rockbox.org/r/c/rockbox/+/3274)

in the first image you can see the edit interface

Add Context allows adding a new context
selecting a context adds a new action (2nd image)
empty contexts and actions with button&prebutton == NONE will not be saved to the remap

Update: Keymaps can now be exported and imported with plain text
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: Bilgus on February 23, 2022, 09:07:09 AM
Ive updated the plugin with a way to apply the keyremap temporarily, and a way to remove the remap (renames it to core_deleted.kmf.old)

A couple example remaps

WPS Long press Volume_Down to stop playback


First Select 'Add Context'
Choose 'CONTEXT_WPS'
Select item 'CONTEXT_WPS' to add a new action

you should now see
[Add Context]
[CONTEXT_WPS]
[WPS][NONE][NONE][NONE}

(if you add too many actions don't worry if button is set to NONE it will be ignored when saving and applying)

using the select button move to each field (long press selects the field)

The button and prebutton fields will automatically 'mathematically (bitwise) OR |' each button you select
(choose BUTTON_NONE to reset)

when you are fininshed your screen should look like this..
[Add Context]
[CONTEXT_WPS]
[WPS][ACTION_WPS_STOP][VOL_DOWN|BUTTON_REPEAT][NONE]


next choose Temp Core Remap and quit the plugin
(save if you desire or hit select at the prompt on exit to save)
Now go to the WPS play a song and a long press of volume down should stop playback

--------------------------------------------------------------------------------------------------------------
MAINMENU Long press Volume_Down to stop playback

First Select 'Add Context'
Choose 'CONTEXT_MAINMENU'
Select item 'CONTEXT_MAINMENU' to add a new action

you should now see
[Add Context]
[CONTEXT_MAINMENU]
[MAINMENU][NONE][NONE][NONE}

(if you add too many actions don't worry if button is set to NONE it will be ignored when saving and applying)

using the select button move to each field (long press selects the field)

The button and prebutton fields will automatically 'mathematically (bitwise) OR |' each button you select
(choose BUTTON_NONE to reset)

when you are fininshed your screen should look like this..
[Add Context]
[CONTEXT_MAINMENU]
[MAINMENU][ACTION_TREE_STOP][VOL_DOWN|BUTTON_REPEAT][NONE]


next choose Temp Core Remap and quit the plugin
(save if you desire or hit select at the prompt on exit to save)
Now go to the WPS play a song then return to main menu and a long press of volume down should stop playback

Notice how we didn't use ACTION_WPS_STOP here that isn't a valid action to the mainmenu and it will not work
(I had to look in the source to figure that one out)
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: STEELBAS on February 23, 2022, 01:17:26 PM
Nice work, I'll be sure to try this out.
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: Bilgus on February 23, 2022, 10:00:11 PM
Now in the latest dev builds
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: dconrad on February 24, 2022, 08:36:04 AM
That's awesome!

So do you need to define an entire keymap in the plugin, or can you just define one or two new actions which will take priority over the stock keymap, but otherwise use the stock keymap?
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: Bilgus on February 24, 2022, 09:09:27 AM
You don't need to define a whole keymap just a few actions that you want and if they aren't matched it falls through to the regular keymaps

keyremap contexts must match exactly -- re-mapped contexts run before the built in w/ fall through contexts
 ie. you can't remap CONTEXT_STD and expect it to match CONTEXT_WPS after if falls through to CONTEXT_STD
(keyremap only checks for matches in the (first) top level context)

The same caveats do apply as when you are doing a 'real' keymap though namely fallthrough contexts may eat your button before you get a match
--------------------------------------------------------------------------------------------
* Example: button = UP|REL, last_button = UP;
*  while looking in CONTEXT_WPS there is an action defined
*  {ACTION_FOO, BUTTON_UP|BUTTON_REL, BUTTON_NONE}
*  then ACTION_FOO in CONTEXT_WPS will be returned
*  EVEN THOUGH you are expecting a fully matched
*  ACTION_BAR from CONTEXT_STD
*  {ACTION_BAR, BUTTON_UP|BUTTON_REL, BUTTON_UP}
--------------------------------------------------------------------------------------------

PS. You can also block actions by using ACTION_NONE BTN PBTN
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: bahus on March 05, 2022, 06:51:43 AM
Another cool feature! Thanks Bilgus!

I'm trying to block annoying pitch screen action on long press Play button in WPS on my Sansa Clip Zip (tested on build ee87bfb933)

So I'm adding CONTEXT_WPS re-maping entry, next adding 2 keys to Button column: BUTTON_MULTIMEDIA_PLAYPAUSE and BUTTON_REPEAT

So my re-maping looks like (Button looks a bit strange):
Context: WPS
Action: NONE
Button: HOME | BUTTON_REPEAT | BUTTON_MULTIMEDIA | BUTTON_MULTIMEDIA_PLAYPAUSE
PreBtn: NONE

Next I click Temp Core Remap and test my changes. Pitch screen still appears on long Play press in WPS :(

What am I doing wrong?
Button column representation looks suspicios to me. Why HOME and BUTTON_MULTIMEDIA  is there? I didn't add it...

Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: Bilgus on March 05, 2022, 07:56:58 AM
if you look at the list of buttons it the source https://github.com/Rockbox/rockbox/blob/master/firmware/export/button.h#L95

BUTTON_MULTIMEDIA_PLAYPAUSE is #define BUTTON_MULTIMEDIA_PLAYPAUSE (BUTTON_MULTIMEDIA|0x01)

it just returns the constituent buttons

BUT that won't work to block pitchscreen

instead try:
[WPS][ACTION_NONE][BUTTON_UP|BUTTON_REPEAT][BUTTON_NONE]
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: bahus on March 05, 2022, 08:44:57 AM
instead try:
[WPS][ACTION_NONE][BUTTON_UP|BUTTON_REPEAT][BUTTON_NONE]

Works!! Thanks.

Some notes:
1) What about removing `BUTTON_` prefix in list of buttons and from cell? It seems already skipped in cell but only for first button. My remapping looks like: UP | BUTTON_REPEAT

2) Can list of keymaps in Load Keymaps be sorted by name? My current list looks like: [user_keyremap]1.kmf, 2.kmf, 6.kmf, 3.kmf, 4.kmf, 5.kmf.
Not sure why last keymap user_keyremap6.kmf in the middle of list...

3) Would be cool to support action that runs any particular plugin.
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: Bilgus on March 05, 2022, 09:54:05 AM
Plugins I'd like to do but I think I need a button level redirect to do it because they can use custom keymaps that will be really hard to figure out
without combing through source..

the other stuff, no sorry its more code than its worth and greatly complicates the buffer situation
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: bahus on March 05, 2022, 01:27:45 PM
> I need a button level redirect to do it because they can use custom keymaps that will be really hard to figure out

I meant functionality to start some plugin/lua script by pressing some custom key combination. I didn't mean key remapping inside plugins...
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: Bilgus on March 06, 2022, 12:06:47 AM
you do have a few of those,  of the top of my head -- wps_hotkey can be set to open plugin,

Settings>General Settings>Hotkey

Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: Bilgus on March 06, 2022, 04:50:00 PM
Sample exported text keymap that can be imported to the plugin:

Code: [Select]
# Key Remap
# Device: Sandisk Sansa Fuze+
# Entries: 4

# Each entry should be PROPER_CASE and on its own line
# Comments run to end of line

CONTEXT_WPS = {
    {ACTION_WPS_STOP, BUTTON_VOL_DOWN | BUTTON_REPEAT, BUTTON_NONE},
}

CONTEXT_MAINMENU = {
    {ACTION_TREE_STOP, BUTTON_VOL_DOWN | BUTTON_REPEAT, BUTTON_NONE},
}
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: chris_s on May 12, 2022, 02:41:18 PM
Thanks for your hard work on this, bilgus! Takes a bit of getting used to, but is super useful and quick to use once you get the hang of it.  :) Hopefully it won't be too intimidating for some people to use who would benefit from it.

For anyone who prefers the button mapping on iPods to be closer to the original firmware, I'd suggest this keymap for you (may require some more tweaking, so it's possible I'll update this post later, but seems to work pretty well already – comments welcome):

Code: [Select]
# Key Remap
# Device: Apple iPod 4g Grayscale
# Entries: 20

# Each entry should be PROPER_CASE and on its own line
# Comments run to end of line

CONTEXT_TREE = {
    {ACTION_STD_MENU, BUTTON_SELECT | BUTTON_MENU, BUTTON_NONE},
    {ACTION_STD_CANCEL, BUTTON_MENU | BUTTON_REL, BUTTON_MENU},
}

CONTEXT_STD = {
    {ACTION_STD_CANCEL, BUTTON_PLAY | BUTTON_REL, BUTTON_PLAY},
    {ACTION_STD_CANCEL, BUTTON_MENU | BUTTON_REL, BUTTON_MENU},
}

CONTEXT_LIST = {
    {ACTION_STD_CANCEL, BUTTON_MENU | BUTTON_REL, BUTTON_MENU},
    {ACTION_STD_MENU, BUTTON_SELECT | BUTTON_MENU, BUTTON_NONE},
    {ACTION_STD_CANCEL, BUTTON_PLAY | BUTTON_REL, BUTTON_PLAY},
}

CONTEXT_SETTINGS = {
    {ACTION_STD_CANCEL, BUTTON_MENU | BUTTON_REL, BUTTON_MENU},
}

CONTEXT_MAINMENU = {
    {ACTION_STD_CANCEL, BUTTON_MENU | BUTTON_REL, BUTTON_MENU},
}

CONTEXT_WPS = {
    {ACTION_WPS_VIEW_PLAYLIST, BUTTON_SELECT | BUTTON_REL, BUTTON_SELECT},
    {ACTION_WPS_BROWSE, BUTTON_MENU | BUTTON_REL, BUTTON_MENU},
    {ACTION_WPS_MENU, BUTTON_SELECT | BUTTON_MENU, BUTTON_NONE},
}

CONTEXT_BOOKMARKSCREEN = {
    {ACTION_STD_CANCEL, BUTTON_MENU | BUTTON_REL, BUTTON_MENU},
}

Summarized changes to the original keymap:
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: Frankenpod on May 12, 2022, 04:35:47 PM
Trouble is I've gotten far too accustomed to the original default keymapping now to want to mess with it!
Title: Re: Keyremap plugin - remaps keys in rockbox
Post by: korvin on July 09, 2022, 07:39:01 AM
worstest plugin ever, it's easier to modify source code with keybinding and build/compile rockbox firmware from scratch + install it, as to force this plugin it to work. It does nothing after applying new keybindings.