I did what you suggested but it made no difference so I contacted Apple Support directly yesterday and they called me back from the States - it's usually Ireland. Anyway, the first lady mirrored my screens and tried all sorts of things to get the iMac to do what it should (I had already told her that both magic keyboards refused to work on the iMac but were fine on the laptop so we knew the issue lay with the iMac) but then after 45 minutes or so she transferred me into a "queue" to wait for the next level of expertise and about 30 minutes later, Sarah came online, took over my screen again and started to check out various possibilities.
I told her about a different issue I'd had earlier this year, when this iMac would not let me fill in my password at sign on and that sometimes I had to "uncheck the Mouse Keys" first She then found that "enable Mouse Keys" was checked at sign on, disabled them and that made the keyboard work fully again. Sorted.
Unfortunately today, my MacBook Air and my iMac aren't copying and pasting with each other so I've been using Airdrop a lot more than usual. Keeps me on my toes!
Thanks for your suggestions re solutions and Apple Care.
Brenda