Use the iPad’s built-in Bluetooth to connect a Bluetooth keyboard, such as the one that comes with newer iMacs. Just pair up the devices from Settings, Bluetooth.
The iPad gives you a code to type into the keyboard, before pressing Return. Some people report the need to make their iMac “forget” the keyboard before it can pair with an iPad. By default, using a Bluetooth keyboard hides the onscreen keyboard. Press the “eject” key on the physical keyboard to show the onscreen version again.