He:
https://digistump.com/board/index.php/topic,2389.0.htmlsays this isnt possible but I may have found a way!
Here are two important functions:
https://digistump.com/wiki/digispark/tricksI would try to check if the clock was calibrated at bootup, which means it is connected, and if it isnt reboot.
Do that until it indicates the clock was calibrated at bootup which means the usb connection is active.
I dont have a way to test if this works but I may write the code later.
The only problem is that your Digispark may be set to have the clock at 16,5 mhz even if not connected to usb which would make this way impossible.
When you get your new Digispark I will be finished

EDIT: Try this if you find your digispark:
#include "DigiKeyboard.h"
#include <avr/boot.h>
boolean doLoop = true;
void setup() {
pinMode(0, OUTPUT); //LED on Model B
pinMode(1, OUTPUT); //LED on Model A or Pro
}
void loop() {
DigiKeyboard.delay(500); //some delay, I dont know if this is needed but maybe the Digispark needs some time to calibrate the clock
if(is_clock_calibrated() == 0){
reboot();
}
else{
if(doLoop == true){
digitalWrite(0, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(1, HIGH);
DigiKeyboard.delay(5000); // <-- use DigiKeyboard.delay here (documentation says thgis tells the computer the "Keyboard" is still connected)
// /\
//ENTER DELAY AFTER THE 5 SECOND BOOT DELAY HERE
for(int i=0; i<5; i++) {
// /\
// How many times do you want to enter "N" ?
DigiKeyboard.update();
DigiKeyboard.sendKeyStroke(KEY_N);
DigiKeyboard.delay(5000); // <-- use DigiKeyboard.delay here (documentation says this tells the computer the "Keyboard" is still connected)
// /\
// DELAY BETWEEN KEYSTROKES (ms)
}
}
// WARNING: ALL DELAYS ARE IN MILLISECONDS -> 1000ms = 1s
else{
digitalWrite(0, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(1, LOW);
DigiKeyboard.delay(10000);
}
doLoop = false;
}
}
byte read_factory_calibration(void) {
byte SIGRD = 5; // for some reason this isn't defined...
byte value = boot_signature_byte_get(1);
return value;
}
boolean is_clock_calibrated(void) {
return read_factory_calibration() != OSCCAL;
}
void reboot(void) {
noInterrupts(); // disable interrupts which could mess with changing prescaler
CLKPR = 0b10000000; // enable prescaler speed change
CLKPR = 0; // set prescaler to default (16mhz) mode required by bootloader
void (*ptrToFunction)(); // allocate a function pointer
ptrToFunction = 0x0000; // set function pointer to bootloader reset vector
(*ptrToFunction)(); // jump to reset, which bounces in to bootloader
}
The LED on the Digispark schould turn on when the Atom Board connects with it, max 5s later (if the digispark reboots because it gets no connection and 1ms later the Atom Board turns on, the Bootloader waits 5s to start the program so the delay should be from 0-5s.)
EDIT2: Sadly this doesnt work for me. I think they changed the default clock rate to 16.5mhz so the is_clock_calibrated will return true even if it isnt connected to usb

Maybe you can change that back but I dont know how.
Maaaaaaybeeee you could connect an USB data pin to any other Input pin and check if there is any data coming in but that would need some diving into the usb documentation, I may look into it later but for now, I would just try how long the boot time of the Atom is and adjust the delay or let the digispark send "n" as long as it is powered (if the atom board is ok with receiving "n" while it is running and that doesnt change some settings)
EDIT3: Connecting any USB Pin to any other Input pin prevents the PC from recognising the Digispark as a USB device...
I don't see a simple solution for this but maybe you'll find something, I'll keep looking too.
Let me know if you find a solution!
Another Idea! Does your board have a PS2 connector? Maybe you could connect the power pin of these to an IO pin on the Digispark, the PS2 voltage should be off if the board is off.
Ok I think I'm stupid... you want it to recognize the keyboard recognition and not just bootup, right? I don't think that's possible. If it was possible, the Rubber Ducky would certainly have it and it doesn't so I see no way to do this... I would just try to time the delay right...
KASA