Short answer: no, macOS can’t automatically “pass through” an iMac’s keyboard and trackpad to a MacBook when the iMac is being used as an AirPlay display. AirPlay is strictly a display-and-audio protocol; it doesn’t forward HID (keyboard/mouse/trackpad) input to the source Mac. Once AirPlay starts, the iMac remains its own computer, so its accessories stay paired to the iMac and won’t control the MacBook.
That said, there are workable alternatives, depending on how seamless you want things to feel. The most practical Apple-native option is Universal Control. When both Macs are signed into the same Apple Account, on the same network, and have Bluetooth enabled, you can move the pointer from the MacBook onto the iMac (or vice versa) and use one keyboard and trackpad across both machines.
If you specifically want the iMac’s keyboard and trackpad to control the MacBook, you basically have three options:
- Pair them directly to the MacBook via Bluetooth and leave them paired there permanently (manual switching only).
2. Use a software KVM which forwards input over the network.
3. Use a hardware USB/Bluetooth switch to toggle the accessories between Macs.