key handling and cursor