1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Hello and welcome to the EESE! I've edited your post to make it flow a bit better. There are a couple things that would help others find a solution. 1) Which teensy is this? and 2) What is happening now, you say the timings aren't right so I assume that something is happening just at the wrong time \$\endgroup\$ – Funkyguy Jul 16 '14 at 14:13
  • 1
    \$\begingroup\$ Why are you not just installing VNC or setting up remote desktop so that you can login to all of them remotely and check for functionality? Are they not connected to the internet? \$\endgroup\$ – horta Jul 16 '14 at 14:17
  • \$\begingroup\$ If you find the (library?) code which implements the USB keyboard protocol, and discover some event which occurs reliably upon connection to set up the interface, you could use that to start a countdown timer to inputting the password. Another possibility might simply be a time delay from power on, at least if you plug it in after turning on the power. \$\endgroup\$ – Chris Stratton Jul 16 '14 at 15:32
  • \$\begingroup\$ Hello, and thanks for the help so far. I'll try to give as much details as possible. To answer to Shannon the teensy is the 3.1 and at the moment what happens is that the sketch runs even if the button is not pressed, I tried to simply add a delay at the beginning but I ended up wasting more time with longer delays or with shorter ones the handshake wasn't complete, the problem is that the teensy has to unlock the login screen pressing crtl+alt+del and then type user name and password.The beginning of the sketch is essential like the last bit. Thanks for your help \$\endgroup\$ – hsdb Jul 16 '14 at 21:09
  • \$\begingroup\$ Thanks Horta, unfortunately as said by JRE, I need to physically be in front of the PC. I need to make sure that everything is working correctly, keyboard, mouse, proxy, screen etc., of course is nothing impossible to do manually, but having a buddy who doesn't get tired and helps with 50% of the work simply using an usb is pretty attractive. We use RDP to log in (that of course is restricted for on site access only) with it I can just check the software and network integrity, to the code in future I'd like to add more bits like, a win key+R to run .BAT to update gp and delete local profiles \$\endgroup\$ – hsdb Jul 16 '14 at 21:23
1
\$\begingroup\$

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.

\$\endgroup\$
  • 2
    \$\begingroup\$ Ah, that makes more sense, thanks. For future reference, it's not Shannon who asked, it's user49471. Shannon just edited the post. \$\endgroup\$ – horta Jul 16 '14 at 15:00
  • \$\begingroup\$ What position am I in? \$\endgroup\$ – Funkyguy Jul 16 '14 at 18:56
  • \$\begingroup\$ Hi JRE, you got exactly the point of the summer work of a network manager in a school...where kids for one year spent time destroying keyboards and mice, swapping keys to compose profanities...I forgot to introduce my self, my name is Pier. \$\endgroup\$ – hsdb Jul 16 '14 at 21:33
  • \$\begingroup\$ Yeah, I got it 'cause I've been there and done that. 4 schools to cover, upwards of 1200 PCs. Flat feet and raw finger tips... \$\endgroup\$ – JRE Jul 17 '14 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.