"Doesn't recognize" means what exactly? Looks like mame is seeing 4 mice and 2 keyboards (4 mice = the 2 guns + 2 for optipac).
First I'd try disabling offscreen reload, testing for now.
Then try remapping in side map any analog type input (trackball analog, AD stick analog, dial analog, lightgun analog, paddle analog) in mame's remap menu. See if mame can remap to each of the guns and or TB; if it can, what's the mouse or gun number. If none work, try disabling mouse but leaving lightgun enabled, and then vice versa, again testing with remapping.
For best remapping guns, tab, Input (this game), scroll to your input, point both guns at middle of screen, enter, move the gun you want to near edge, and mame should register in about a second.