Start a teensy sketch after USB handshake has completed or upon a button has been pressed

arduinohidteensy

I have an issue in starting a sketch on my Teensy at the right time.

I work in a school as an IT technician and over the summer I go through all the computers on site, log-on and check if they're behaving correctly.
To avoid to log on more than 500 workstation. I thought that emulating a keyboard with teensy was the best way to make this process faster so I wrote some code to help me doing so…unfortunately there's a problem with timings.
To solve this issue I'd like the teensy to start the program after the usb device on windows has been installed correctly or after a button as been pressed.

Below is the code, please would it be possible for some of you gurus to help me out?

int count = 0;
const int buttonPin = 5;
int buttonState = 0;

void setup() 
{ 
    pinMode(buttonPin, INPUT);
}

void loop() {
   buttonState = digitalRead(buttonPin);
   if (buttonState == HIGH){  
      Keyboard.set_modifier(MODIFIERKEY_CTRL);
      Keyboard.send_now();
      Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
      Keyboard.send_now();
      Keyboard.set_key1(KEY_DELETE);
      Keyboard.send_now();
      Keyboard.set_modifier(0);
      Keyboard.set_key1(0);
      Keyboard.send_now();
      delay(2500);  
      Keyboard.print("Administrator");
      delay(1000);
      Keyboard.press(KEY_TAB); 
      Keyboard.release(KEY_TAB);
      delay(500); 
      Keyboard.print("XXXXXXXXXXXXXXXX");
      delay(500); 
      Keyboard.press(KEY_TAB); 
      Keyboard.release(KEY_TAB);
      delay(500);   
      Keyboard.press(KEY_ENTER); 
      Keyboard.release(KEY_ENTER);
} 

else {

     Keyboard.print("No Button Pressed!")
     }

} 

Many thanks in advance.

Best Answer

Having been in Shannon's position, I can understand what he's trying to do. Doing this by remote won't help. You have to physically go to each machine, turn it on, and check not just that it boots, but that the drives are OK, that the keyboard and mouse work, that the monitor is OK, etc. Last but not least is of course seeing that it is where it should be and updating the database if the PC has been moved (or putting it back where it belongs.)

This is as much a physical inventory as anything else. Since it is summer, I would also expect the PCs to be shut off to save power and reduce the school's electricity bill.

Horta's suggestion of using VNC is therefore out of the question - and VNC would be a bad choice, anyway. In a Windows System you would do better to use RDP (which is already installed compared to having to install and configure VNC 500 times.) Under Linux, you would have a good many options but still, Shannon has to go and physically check the machines.

I would also hope that the PCs in the school cannot be reached for VNC (or even RDP) over the internet.

I would have preferred to make this a comment to Horta's comment, but I don't have enough reputation for that.