Sounds like the Magic Trackpad, sold between July 2010 and October 2015. It connected to Macs via Bluetooth.
Connect an Apple wireless keyboard, mouse, or trackpad with Mac - Apple Support
You need to unpair it from the old Mac before you can pair it with a new one. If you don't have the old iMac, or it isn't in good enough working order to let you do that, there are a couple of things you can try:
- Turning the Magic Trackpad off, then pressing and holding the power button until the LED indicator starts blinking rapidly (indicating that it is in pairing mode)
- Turning the power switch on and off five times. It's not clear why this would work, but one person said that it did.