IPT_KEYBOARD triggers the modal behavior. Arguably it should be slightly finer grained: if the system maps Esc, Tab, P, or any of the F-keys then modal.
We need to be able to "focus" keyboards, so you can emulate a system with two keyboards and type on them both using one keyboard. If we had a system that allowed that then controlling the emulator could just be another "keyboard".
Basically it would need to detect mapping conflicts and if there are any then somehow allow you to select which device wins.
It probably shouldn't be limited to keyboards, but the method to switch between other devices may get complicated. You might for example have two keyboards and two joysticks, the keyboards could have some conflicts with each other and the joysticks conflict with each other. But one of the keyboards could conflict with one of the joysticks. The non conflicted keys should always work no matter what device is selected.