Well it's not quite what I'm looking for : I'd like for the window to react (just like in your script) whether it's active ot not (focused or blurred) which isn't the case in your script.
If for example you're working in MS Word and you press the return key, then MS Word solely deals with it whereas I'd like for the perl script in the background to react as well. Thanks for your help !