Keyboard Not working Properly
Thanks to your investigative work, it appears that the common problem is the Bluetooth on iMac.

Try resetting you BT.

You will loose paring so you have to pair it again.

To reset BT hold Shit+Option and click on the BT icon in the menu bar.

Now you will see the Debug menu.