Thanks for the replies. 
I implemented the keybaord and when I run it manually and with Fill.tst script it seems to be running fine. The screen turns black when a key is pressed and turns white when it is released. 
However when i run it test it with Fill_atomatic.tst script it fails. I seems that when key is released by automatic script then the screen is not going white again. 
This is not what I see when I run the program manually or with Fill.tst script. When doing manually when I release the key the screen turns white as expected. 
Can you give me some hint what could be causing this. 
I am pasting Compare.tst and Output file below.
Thanks.
