Getting a 4-digit number from a keypad

And is supposed the program is inside "for (int i = 0; i < 4;)" till gets four keys pressed.

I don't know what you mean by this, but getKey() is NOT a blocking function. It is NOT waiting for you to press a key.