To inspect what expiry options are currently set (credit to user aioobe on xkbset setting does not persist):
xkbset q exp
Configure the desired options not to expire on their own:
xkbset =mousekeys
xkbset =mousekeysaccel
See xkbset --help
for syntax and examples.
Configure mouse key acceleration:
xkbset mousekeysaccel 60 10 10 20 10
The above options alone would not persist on Ubuntu 22.04 as opposed to 20.04; mouse keys have to be enabled manually after startup (by pressing Num Lock twice, or toggling Settings > Accessibility > Pointing & Clicking > Mouse keys off and on again), which would cause the mouse key acceleration not to apply either. To work around this issue, add the following command to Startup Applications:
xkbset mousekeys
With the above options, the whole mouse keys feature may still expire on its own after an unknown timeout.
Manually add the expiration command into the startup applications as a workaround for this issue:
xkbset exp =mousekeys
The commands may need to be set in a specific execution order, i.e.:
xkbset mousekeys
xkbset exp =mousekeys
xkbset mousekeysaccel 60 10 10 20 10
xkbset exp =mousekeysaccel
Startup Applications are executed in alphabetical order, so you may need to add a specific Name for the commands to make sure the mouse keys are active before the mouse key acceleration is set.