Unfortunately, this did not work. I revoked the permission and restarted my phone. After reboot, MacroDroid would ask me to grant the permission for another macro that I set, which includes an action to change screen orientation (invoked from a button press in the notification bar). This macro then continues to work without problem. The keyboard one still only works when MacroDroid is running in the foreground.