Here are some steps you can try to solve the issue:
-
Disable the auto-sleep mode on the keyboard by holding fn(or fn1)+S+O for 4 seconds.
-
Try to pair the keyboard with your device via Bluetooth on other channels by holding fn+2/3 (fn1+W/E for K6 and K12) to see if it works.
-
Update your Mac to the latest software version.
-
Reset your Mac’s Bluetooth Module: https://www.macrumors.com/how-to/reset-mac-Bluetooth-module/
-
Check the Mac’s Wi-Fi and Bluetooth interference: https://support.apple.com/en-us/HT201542