Earlier on previous WWDC, Apple has released a feature that would allow Mac and iPad to share a same keyboard and mouse. This feature is called Universal Control, which will be roll out in macOS 12.3 and iPadOS 15.4. Currently this feature is available to test in each beta testing phase.
With this feature in place you would be able to control your iPad with your mouse and keyboard, even if the peripherals aren’t paired in the iPad. To use this feature on Mac, you will need to go to Displays > Advanced and whereas iPad you will need to go to General > AirPlay & Handoff > Cursor & Keyboard and activate universal control.