Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Thank You for your continued support and contributions!

+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  Keyremap plugin - remaps keys in rockbox
« previous next »
  • Print
Pages: [1] 2

Author Topic: Keyremap plugin - remaps keys in rockbox  (Read 2570 times)

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 876
Keyremap plugin - remaps keys in rockbox
« 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

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

Update(1/2/2023): devices with softlock (no physical hold switch) now have the option of _LOCKED contexts
you can choose a different keymapping when the device is locked
_REMOTE contexts are also now supported

* Screenshot from 2022-02-19 05-27-15.png (23.99 kB, 322x646 - viewed 104 times.)

* Screenshot from 2022-02-19 05-35-38.png (24.27 kB, 322x646 - viewed 87 times.)
« Last Edit: January 02, 2023, 01:23:53 PM by Bilgus »
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 876
Re: Keyremap plugin - remaps keys in rockbox
« Reply #1 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)
« Last Edit: February 24, 2022, 12:39:46 AM by Bilgus »
Logged

Offline STEELBAS

  • Member
  • *
  • Posts: 5
Re: Keyremap plugin - remaps keys in rockbox
« Reply #2 on: February 23, 2022, 01:17:26 PM »
Nice work, I'll be sure to try this out.
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 876
Re: Keyremap plugin - remaps keys in rockbox
« Reply #3 on: February 23, 2022, 10:00:11 PM »
Now in the latest dev builds
« Last Edit: February 24, 2022, 12:40:05 AM by Bilgus »
Logged

Offline dconrad

  • Developer
  • Member
  • *
  • Posts: 133
Re: Keyremap plugin - remaps keys in rockbox
« Reply #4 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?
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 876
Re: Keyremap plugin - remaps keys in rockbox
« Reply #5 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
« Last Edit: February 24, 2022, 09:46:11 AM by Bilgus »
Logged

Offline bahus

  • Member
  • *
  • Posts: 117
Re: Keyremap plugin - remaps keys in rockbox
« Reply #6 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...

* user_keyremap5.kmf.txt (0.06 kB - downloaded 30 times.)
« Last Edit: March 05, 2022, 06:53:29 AM by bahus »
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 876
Re: Keyremap plugin - remaps keys in rockbox
« Reply #7 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]
« Last Edit: March 05, 2022, 07:58:51 AM by Bilgus »
Logged

Offline bahus

  • Member
  • *
  • Posts: 117
Re: Keyremap plugin - remaps keys in rockbox
« Reply #8 on: March 05, 2022, 08:44:57 AM »
Quote from: Bilgus on March 05, 2022, 07:56:58 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.
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 876
Re: Keyremap plugin - remaps keys in rockbox
« Reply #9 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
Logged

Offline bahus

  • Member
  • *
  • Posts: 117
Re: Keyremap plugin - remaps keys in rockbox
« Reply #10 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...
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 876
Re: Keyremap plugin - remaps keys in rockbox
« Reply #11 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

Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 876
Re: Keyremap plugin - remaps keys in rockbox
« Reply #12 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},
}
Logged

Offline chris_s

  • Developer
  • Member
  • *
  • Posts: 222
Re: Keyremap plugin - remaps keys in rockbox
« Reply #13 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:
  • Press Menu button on WPS to enter Browser, instead of returning to the main menu
  • Press Menu button to go up one level
  • Press Play button to go to WPS (eventually)
  • Press Select button on WPS to display playlist
  • Press Menu+Select to return to main menu
« Last Edit: May 24, 2022, 02:07:05 PM by chris_s »
Logged

Offline Frankenpod

  • Member
  • *
  • Posts: 641
Re: Keyremap plugin - remaps keys in rockbox
« Reply #14 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!
Logged

  • Print
Pages: [1] 2
« previous next »
+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  Keyremap plugin - remaps keys in rockbox
 

  • SMF 2.0.19 | SMF © 2021, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.034 seconds with 16 queries.