Hey, Kim.
It says here you're using an iMac, so I'm going to assume you're using Apple's Magic Keyboard to go along with that. I personally haven't experienced an issue like this, but in the case this was happening, here's what I would do:
- Turn keyboard off, then on
- Insert new batteries (check battery percentage [System Prefs > Keyboard > Bottom Left]
- Disconnect keyboard form Bluetooth (System Prefs > Bluetooth > Hover over your keyboard, click the tiny 'x' symbol)
If you aren't using a Magic Keyboard, and are using a wired one, I've found this link for you to check out:
http://osxdaily.com/2017/10/14/troubleshooting-macos-high-sierra-problems/
There's a part of it which talks about a freezing cursor and keyboard, among many other trouble shoots, so it may be able to give you a hand.
I hope I helped!