SOLVED Leonardo as keyboard will not start unless monitor started first

I have a Leonardo programmed as a keyboard. After power-up, it will not send any keystrokes until the IDE's monitor is started. Then it works without the monitor until power is lost.

From what I've read, the Leo can enumerate either as serial or HID. It seems to be stuck in serial mode until the monitor changes it.

How can I avoid needing the monitor to get the program to start properly? I use Linux - Debian on the desktop and Armbian on my Odroid.

Do you have this or similar in your code?

while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB
  }

If you don't need serial, just remove that.