Help With Coding Functions

Hey guys, I’m fairly new to Arduino. I am using a Micro Arduino board to send keyboard key strokes to image pc’s at my job. I’m curious if there is a code or function to do both of the following:

  • Pause and not do anything until I hit a certain key, so, after it sends a keystroke, it will pause and do nothing so I can enter some data until I press the “Home” key and then continue with the script.

  • Gather the computers name from properties and be able to use that in certain areas during the reimage process. So, when the image requires that I rename the PC the arduino board reads what the PC is currently named, and sends it in a STRING.

Here is my current code for my board right now if it helps at all. Thanks guys in advance!!!

/*
* Generated with <3 by Dckuino.js, an open source project !
*/

#include "Keyboard.h"

void typeKey(int key)
{
Keyboard.press(key);
delay(50);
Keyboard.release(key);
}

/* Init function */
void setup()
{
// Begining the Keyboard stream
Keyboard.begin();

// Wait 500ms
delay(500);

delay(2500);

typeKey(KEY_F12);

delay(1000);

typeKey(KEY_F12);

delay(1000);

typeKey(KEY_F12);

delay(1000);

typeKey(KEY_F12);

delay(1000);

typeKey(KEY_F12);

delay(1000);

typeKey(KEY_F12);

delay(1000);

typeKey(KEY_F12);

delay(1000);

typeKey(KEY_F12);

delay(1000);

typeKey(KEY_F12);

delay(1000);

delay(10000);

typeKey(KEY_UP_ARROW);

typeKey(KEY_RETURN);

typeKey(KEY_RETURN);

typeKey(KEY_RETURN);

typeKey(KEY_RETURN);

delay(1000);

typeKey(KEY_F12);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_RETURN);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_F12);

delay(2000);

typeKey(KEY_RETURN);

delay(10000);

delay(10000);

delay(10000);

Keyboard.print("***********");

typeKey(KEY_TAB);

Keyboard.print("**********");

typeKey(KEY_TAB);

Keyboard.print("*****");

typeKey(KEY_RETURN);

delay(10000);

delay(10000);

delay(10000);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_DOWN_ARROW);

typeKey(KEY_RETURN);

delay(10000);

typeKey(KEY_TAB);

typeKey(KEY_UP_ARROW);

typeKey(KEY_TAB);

Keyboard.print("*****");

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_RETURN);

delay(10000);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(' ');

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_RETURN);

delay(10000);

typeKey(KEY_TAB);

typeKey(KEY_TAB);

typeKey(KEY_RETURN);

// Ending stream
Keyboard.end();
}

/* Unused endless loop */
void loop() {}

(1) please use code tags

(2) learn to use for loops

 typeKey(KEY_F12);

 delay(1000);

 typeKey(KEY_F12);

 delay(1000);

 typeKey(KEY_F12);

 delay(1000);

 typeKey(KEY_F12);

 delay(1000);

 typeKey(KEY_F12);

 delay(1000);

 typeKey(KEY_F12);

 delay(1000);

 typeKey(KEY_F12);

 delay(1000);

 typeKey(KEY_F12);

 delay(1000);

 typeKey(KEY_F12);

 delay(1000);

becomes

for (int i = 0; i < 9; i++)
{
 typeKey(KEY_F12);
 delay(1000);
}

You can also make a minimal function

 void typeKeyDelay(int key, int duration) 
{
   typeKey(key);
   delay(duration);
}

typeKey(KEY_F12);
delay(1000);

would become

typeKeyDelay(KEY_F12, 1000);

you can even build in the repeats in the function

 void TKDR(int key, int duration, int repeats) 
{
  while (repeats > 0)
  {
    typeKey(key);
    delay(duration);
    repeats = repeats - 1;
  }
}

Thanks for the tips. Do you have any thoughts or ideas about my question though?

No, no experience in that area

robtillaart:
No, no experience in that area

How does this look? Did I fix all your problems with my code?

/*
* Generated with <3 by Dckuino.js, an open source project !
*/

#include "Keyboard.h"

void typeKey(int key)
{
 Keyboard.press(key);
 delay(50);
 Keyboard.release(key);
}

/* Init function */
void setup()
{
 // Begining the Keyboard stream
 Keyboard.begin();

 // Wait 500ms
 delay(500);

 delay(2500);

 for (int i = 0; i < 9; i++)
{
   typeKey(KEY_F12);
   delay(1000);
}
 delay(10000);
 
 typeKey(KEY_UP_ARROW);

 for (int i = 0; i < 4; i++)
{
   typeKey(KEY_RETURN);
}

 delay(1000);

 typeKey(KEY_F12);

 typeKey(KEY_DOWN_ARROW);

 typeKey(KEY_RETURN);

for (int i = 0; i < 65; i++)
{
 typeKey(KEY_F12);
 delay(2000);
}

 typeKey(KEY_RETURN);

 delay(10000);

 delay(10000);

 delay(10000);

 Keyboard.print("connors.johnson");

 typeKey(KEY_TAB);

 Keyboard.print("yBPV8CHS1!");

 typeKey(KEY_TAB);

 Keyboard.print("tabitha");

 typeKey(KEY_RETURN);

 delay(10000);

 delay(10000);

 delay(10000);

 for (int i = 0; i < 14; i++)
{
   typeKey(KEY_DOWN_ARROW);
}

 typeKey(KEY_RETURN);

 delay(10000);

 typeKey(KEY_TAB);

 typeKey(KEY_UP_ARROW);

 typeKey(KEY_TAB);

 Keyboard.print("tabitha");

 for (int i = 0; i < 6; i++)
{
   typeKey(KEY_DOWN_ARROW);
}

 typeKey(KEY_RETURN);

 delay(10000);
 
 for (int i = 0; i < 3; i++)
 {
   typeKey(KEY_TAB);
 }

 typeKey(' ');
 
   for (int i = 0; i < 4; i++)
 {
   typeKey(KEY_TAB);
 }

 typeKey(KEY_RETURN);

 delay(10000);

 typeKey(KEY_TAB);

 typeKey(KEY_TAB);

 typeKey(KEY_RETURN);

 // Ending stream
 Keyboard.end();
}

/* Unused endless loop */
void loop() {}
  delay(10000);
  delay(10000);
  delay(10000);

Why are you stacking delay()s when you could just use one larger delay() ?

UKHeliBob:

  delay(10000);

delay(10000);
  delay(10000);



Why are you stacking delay()s when you could just use one larger delay() ?

to breath in between?

UKHeliBob:

  delay(10000);

delay(10000);
  delay(10000);



Why are you stacking delay()s when you could just use one larger delay() ?

I got this code through a USB Rubber Ducky Compiler. It came that way. I changed it. Do you have any idea how to do any of the original questions I had?

I got this code through a USB Rubber Ducky Compiler.

A what?

From the USB Rubber Ducky website:

The USB Rubber Ducky is a keystroke injection tool disguised as a generic flash drive. Computers recognize it as a regular keyboard and accept pre-programmed keystroke payloads at over 1000 words per minute.

Payloads are crafted using a simple scripting language and can be used to drop reverse shells, inject binaries, brute force pin codes, and many other automated functions for the penetration tester and systems administrator.

Since 2010 the USB Rubber Ducky has been a favorite among hackers, penetration testers and IT professionals. With origins as the first IT automation HID using an embedded dev-board, it has since grown into a full fledged commercial Keystroke Injection Attack Platform. The USB Rubber Ducky captured the imagination of hackers with its simple scripting language, formidable hardware, and covert design.

I'm out !

ConJon:
Hey guys, I'm fairly new to Arduino. I am using a Micro Arduino board to send keyboard key strokes to image pc's at my job. I'm curious if there is a code or function to do both of the following:

  • Pause and not do anything until I hit a certain key, so, after it sends a keystroke, it will pause and do nothing so I can enter some data until I press the "Home" key and then continue with the script.

Sure that's possible. But "pausing" your code is poor practice. Better to let the code run and just not do anything until something happens. "Pausing" the program means blocking execution. So nothing else happens. So you aren't going to be able to "enter some data" while it is paused.

See the Serial Input Basics thread. It is really about sending and receiving serial data, but the same techniques can be used no matter where the data is coming from.

It isn't clear exactly what you want to do here, your description is a little vague and ambiguous. Are you entering the data on the PC or the Arduino? If you're talking about typing on the computer, the Arduino has no way to know you hit the "home" key unless you have some code running on the PC to send some signal to the Arduino when that happens.

ConJon:

  • Gather the computers name from properties and be able to use that in certain areas during the reimage process. So, when the image requires that I rename the PC the arduino board reads what the PC is currently named, and sends it in a STRING.

The Arduino can't do anything directly to your computer. It can't control your computer. All it can do is send or receive data over the serial line. So you'd have to have some program running on the PC that can get that information about the PC name and send it out to Arduino over the serial interface.

Perhaps if you can describe what you actually want to accomplish then someone can help you to get there. But your idea of how to go about doing this has some major flaws.

Delta_G:
Sure that's possible. But "pausing" your code is poor practice. Better to let the code run and just not do anything until something happens. "Pausing" the program means blocking execution. So nothing else happens. So you aren't going to be able to "enter some data" while it is paused.

See the Serial Input Basics thread. It is really about sending and receiving serial data, but the same techniques can be used no matter where the data is coming from.

It isn't clear exactly what you want to do here, your description is a little vague and ambiguous. Are you entering the data on the PC or the Arduino? If you're talking about typing on the computer, the Arduino has no way to know you hit the "home" key unless you have some code running on the PC to send some signal to the Arduino when that happens.

The Arduino can't do anything directly to your computer. It can't control your computer. All it can do is send or receive data over the serial line. So you'd have to have some program running on the PC that can get that information about the PC name and send it out to Arduino over the serial interface.

Perhaps if you can describe what you actually want to accomplish then someone can help you to get there. But your idea of how to go about doing this has some major flaws.

Thanks. I am using the Arudino board as a keystroke tool that automatically sends out keystrokes from the code I have written. I am using these to image Laptops which is a tedious task when you have many to deploy. The code now goes through the image process flawlessly except when I need to input a name for the laptop which we have a customized ID number for each laptop we deploy. The ID is a series of 6 numbers that goes up by 1 for each new laptop we image and deploy. For example, I just recently imaged laptop 115036, the next laptop will be 115037. I am simply wondering if there is anyway to have the board automatically name the laptops automatically with that sequence of ID's.