Move scan logic from main to keyboardscan