Connecting Macs and iPads
For Macs and iPads the latest feature : Universal Control natively supports sharing keyboard, trackpad & mouse with gestures too. It supports upto 3 devices to be connected together, and even files can be drag-and-dropped.
NOTE : As of now, at least one Mac is needed the mix, i.e. two iPads alone cannot be connected together.
Connecting Mac and iPhone
I was personally looking for a way to also Connect the Mac and iPhone, I hoped Universal Control could solve it but unfortunately iPhones are not supported in Universal Control (as of 2022).
A application I found that provides the functionality is KeyPad - Bluetooth Keyboard App.
It makes the Mac's keyboard act as an external bluetooth keyboard, which the iPhone can just connect to as if connecting to a conventional BT-Keyboard. For one device the service is free, connecting more than one device the service is paid. The application seems to work with any device that can benefit from an external bluetooth keyboard and mouse like Android Phones, Apple TV, Smart TVs, etc. It also has media controls built in.