fix key handler state issue