To record mame input run mame with with the following switch
mame.exe romfile -record myinput.inp
To playback the input run the following
mame.exe romfile -playback myinput.inp
If you are playing back input to record videos etc it is vital that you don;y press pause during your original recording. If you do you will get an out of sync error message while playing back the input.