Extract keyboard routine to a separate file