It is not as easy as it sounds, you have in effect a re-triggriable monostable. You are much better off using a NE555 chip to do this than wasting a whole arduino.
It's just a part of a bigger project, so I'm planning to add it to Arduino..
I understand that it is not just 3-4 lines of code, that's why I asked for help.
Thanks anyway!
You will need to understand the blink without delay example, or search for state machine.
When you detect a low input set the output low and make a note of the time. Then each time round the loop you see if the current time minuse the time the push happened is greater than three seconds, if it is you then look to see if the push button has been released. If it has then set the output high if not then just keep looking at the input until it is released. Set the output high whe. This happens.
Implement all this with a state machine.