First you have to enable joystick input.
In commandline mame, edit to mame.ini to read:
### Input device options ###
joystick 1
The mame.ini can be created by running mame.exe -cc
If you are using mame32, there is a similiar option that needs to be checked in one of the config menus.
Then once in a game, press tab to remap your keys.