I can map both retrokeyboard and retropad inputs in the MAME OSD like this:
But to be able to do that I had to null out my retropad keyboard inputs in my MAME 2015 override config. That way the retropad keyboard inputs (keyboard mapped to pad) don’t conflict with retrokeyboard inputs (native keyboard, basically). This has the side effect of disabling my ability to control RA’s GUI with the keyboard when I use the MAME core. If you want to try this method, turn off per core configs if you use them and enable auto loading of override configs in your RA settings. Then create a MAME 2015 folder in your config folder and inside that a MAME 2015.cfg file with these contents:
input_player1_a = "nul"
input_player1_b = "nul"
input_player1_y = "nul"
input_player1_x = "nul"
input_player1_select = "nul"
input_player1_start = "nul"
input_player1_l = "nul"
input_player1_r = "nul"
input_player1_l2 = "nul"
input_player1_r2 = "nul"
input_player1_l3 = "nul"
input_player1_r3 = "nul"
input_player1_left = "nul"
input_player1_right = "nul"
input_player1_up = "nul"
input_player1_down = "nul"
Then when you try mapping stuff in the MAME OSD, you can do keyboard and pad inputs separately.