Mame's a bit trickier because of the fact that it doesn't detect fake keystrokes, but I think it's doable.
If an app was built that allowed some sort of external communication, mamehooker could reset it back to 1st upon loading a game or other events. Probably the easiest way to make sure it goes back to 1st would be to reset the gears any time the start button is pressed. You wouldn't press that while racing but you most likely would press it at least once when going through the menus.
An integrated solution in mame itself is also doable, but it'd be a pain in the butt because the driver for every effected racing game would have to be modified.