i cant see how the message pump (event driven) is going to work in a tight loop (your cpu will go through the roof), you could try putting a application.processmessages in the loop, but not recommended in tight loop either, you could try putting a small sleep and processmessage in, that may help.
the event onkeydown etc are the ones to use,
you could setavariable say called AllowKeyboardInput set it to true in your click event theninyour onkeyevents if AllowKeyboardInput then .....
bare in mind sleeps your app even events, so use a while currenttime-startime<maxtime do ... check for keyinput sleep(10);application.processmessages;