I am sorry I haven't had time to test this before, but I did now and thank You very much for this!!! It works perfectly.
Of course I shouldn't have to deal with stuff like this, but I have Dell E6540 which is supposed to be high-end business laptop and it doesn't even have volume indicator by default! I had to solve this with AHK also, now I can at least see the volume level when I press the dedicated volume buttons. It would be better if it would open the default Windows volume slider but at least it's better than nothing.
Anyway, regarding this, since at first of course I tried to find settings for it but I only get choices like - Do nothing / Sleep / Hibernate / Shut down - when I access the appropriate Control Panel applet "Define power buttons and turn on password protection" (which in itself is contradictory to the content it displays but with MS UI I don't wonder).
So that was the reason I started researching this and now I have the solution (thanks again!). I loaded the scripts now and tested and since I am using a dock at work with an external monitor, at first it seemed that it doesn't work in that configuration but it also seems that Windows likes to duplicate displays by default. So I found the right place in Control Panel again, "Change the appearance of Your displays" - which by the way opens under "Adjust resolution" link - and chose "Show desktop only on 2". Well, as You can probably tell I don't like W7 Control Panel since it's messy and confusing and sometimes rediculous etc.
Voila, now with the scripts everything works as it's supposed to in the first place! Meaning when I close the lid off dock, the display goes off. When I close the lid in dock, both displays go off but external comes back after a second or two (if the display is duplicated like by default it is, the laptop display comes back too). I can't comprehend why the manufacturers of hardware / software fail to address these elementary issues...
So thank You again and I hope others who have problems with this will find this thread too!