Default [Q]Detect key press in background

Hi,
I want to be able to detect if the home and power button are pressed(like a screenshot) in the background.
Root is no problem.
Pleasw can someone help me. I have searched for hours and did not find anything helpfull :what:

Sent from my SM-N9005 using XDA Premium 4 mobile app