I've been tackling the very same problem myself just today. At the moment, I'm using this function I've written:
function pick_sprite(lower,upper)
for spritenumber=lower to upper
if mousex()>=sprite x(spritenumber) and mousex()<=sprite x(spritenumber)+sprite width(spritenumber) and mousey()>=sprite y(spritenumber) and mousey()<=sprite y(spritenumber)+sprite height(spritenumber)
picked=spritenumber
endif
next spritenumber
endfunction picked
which returns the sprite number of the top most sprite the mouse is over, between the lower and upper ranges declared. It returns 0 if the mouse isn't over a sprite within the range. It'll need adapting if you change the draw order of the sprites using sprite priority, though, because it assumes the topmost sprite has the highest sprite number. Also, I'm not exactly sure how the 'sprite height' command works, so it may screw up if the image size and sprite sizes are different.