I knew and already thought and solved it. That is handled by
TForm2.FormClose. I tested it several times, it won't work correctly if the code is put on Form1 because after Form2 opened, Form1 cannot detect keypress because the focus is on Form2.
Test it, and you will know what I mean.