Listen to input event instead of keypress.

This way the last character typed is included in the saved state.

Currently only the previous n-1 characters are saved, so after a restart the input value is missing the last character typed.