This is usually the battery - replacing battery have always woken mine up.
I have had BK fobs get to the point where they were barely usable giving trouble with ignition etc as well.
I had the key, transponder chip and fob transplanted into a replacement housing by a locksmith.
It's possible the transmitter for key fob is playing up - if that fails you'd need to encode a new one, and that would need to be run through a pairing process, but many locksmights can do this.
I got the BK fob case replaced at a shopping center locksmith.
Try a few if they tell you it's real expensive. First one I saw told me it couldn't be done, absolutely had to be replaced and encoded like a brand new unit....was full of shit. His quote would have cost as much as new keys from Mazda. ($500 from memory)
Actual cost of replacement case was under $100 for two fobs, from memory.
"Blue Meanie" 2007 Aurora Blue MPS 3 - 18x8.5+44 SSR GTX01 - 235/40R18 Michelin PS5 - 3.5" ETS TMIC - CPE stg 2 mount - HKS/CPE BPV - 2XS inlet - 2XS short shift - Corksport turbo manifold - HT 98 octane tune - Leather/Aluminium handbrake - Momo shifty knob - 7" touchscreen - JDM Mazda Retractable dashtop screen assembly - Bespoke Raspberry Pi Android based GPS/Carplay and instrumentation - 36AH reserve battery and C-TEK isolator - TEIN Street Advanced coilovers 1" drop - Superpro bushings - 220Kw/410Nm.
"Lipstick" 2013 Velocity Red MPS 3 - 18x7.5+48 Enkei RPF1 -225/40R18 Federal RS-RR - CPE TMIC - COBB inlet - CPE stg 2 mount - COBB Stage 1 98 octane tune - COBB shifty knob - 2XS short shift - 2XS turbo manifold.