I think with GDScript and how Godot works currently, there is not really any way to capture input when the project/game is not selected. As Megalomaniak mentioned, one reason for this is security. Another reason is that, for the most part, you only want to process input when the project/game is selected to allow for multitasking (like using a internet browser to check something while playing), for streaming (if you are running a live stream, you often need to switch between programs), and generally just because you want to know the player can see what is going on and having the window focused is a good way to know if the player can see the project.
If you really want to figure out how to do this, I would suggest looking into a C# solution, as there is likely to be more information on how to capture input in C# than GDScript.