I've finally got to simplify an autohotkey script and make it work. I've added it to code of the script I'm using. This is the code:
#IfWinActive ahk_class MAME
~1Joy9::
if getkeystate("Joy3")
Send, {F2 down}
Send, {F2 up}
return
Apart from buttons for pause, show fps, coin and start, I use button combinations for using MAME's UI. The different action buttons + start button (joy9) perform functions: throtle, menu, overclock, service menu, reset, quit. Now, thanx to the script, when I press joy3 + the start button, I enter the service menu or bios (in case I am running a Neogeo game).