add the key event and optimize the format function