Hacking Tools
https://github.com/hackersanddesigners/tool_hacking https://hackersanddesigners.github.io/tool_hacking/build/
int led = 13; void setup() { pinMode(led, OUTPUT); } void loop() { digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); delay(1000); }
pinMode(2, INPUT_PULLUP); // Take note: LOW => pressed button
File > Examples > USB
#include <Keyboard.h> int buttonPin = 3; void setup() { pinMode( buttonPin, INPUT_PULLUP ); // connect the button to pin 3 Keyboard.begin(); // start the keyboard library delay(3000); // upload delay } void loop() { int pressed = digitalRead( buttonPin ); // read pin 3 if( pressed == LOW ){ // if the button is pressed Keyboard.write( 'd' ); // print the letter d delay( 100 ); // do nothing for 0.1 second } }
void setup() { // ... other code delay(3000); // wait a few seconds before starting the main program }
...code
Keyboard.press(KEY_LEFT_GUI); // Shift-Q logs out: Keyboard.press(KEY_LEFT_SHIFT); Keyboard.press('Q'); delay(100); Keyboard.releaseAll(); // enter: Keyboard.write(KEY_RETURN);
code...
Single key:
Text:
Modifier keys:
#include <Mouse.h> int buttonPin = 3; // Set a button to any pin void setup() { pinMode(buttonPin, INPUT_PULLUP); // Set the button as an input Mouse.begin(); // start the mouse library } void loop() { if (digitalRead(buttonPin) == LOW) // if the button goes low { Mouse.click(); // send mouse click even to the computer delay(1000); // delay so there aren't a kajillion clicks } }
#include "Mouse.h" int upButton = 3; int mouseButton = 4; void setup() { pinMode(upButton, INPUT_PULLUP); pinMode(mouseButton, INPUT_PULLUP); Mouse.begin(); } void loop() { if (digitalRead(upButton) == LOW ) { Mouse.move(0, -10, 0); // x, y, scrollwheel } if (digitalRead(mouseButton) == LOW) { // mouse button pressed Mouse.press(MOUSE_LEFT); } else { // mouse button released Mouse.release(MOUSE_LEFT); } // a delay so the mouse doesn't move too fast: delay(20); }
#include <Keyboard.h> int buttonPin = 3; void setup() { pinMode( buttonPin, INPUT_PULLUP ); // connect the button to pin 3 Keyboard.begin(); // start the keyboard library delay(10000); // upload delay } void loop() { int pressed = digitalRead( buttonPin ); // read pin 3 if ( pressed == LOW ) { // if the button is pressed int val = analogRead(A0); // 0 - 1023 int key = map(val, 0, 1023, 65, 122); Keyboard.write( key ); // print the letter d delay( 100 ); // do nothing for 0.1 second } }