added flushing for key events