Clicking on the taskbar would remove focus from the application intended for the function. Without focus on an application performing the esc function would be pointless. Try it and you will see. Click the taskbar and then click Esc key on the keyboard. You will see nothing happens.
The only way for this to work is for the application to be capable of receiving external commands. Basically you would be running the executable a second time with additional parameters for commands. Doing this is the only way for Windows to pass commands to the application.
Long story short: It depends on the application you are wanting this capability for. The on-screen keyboard doesn't remove focus, the way clicking any other resource does.