Commit d57f23588e8e0ece7c7f235f00f18b239e29a151
1 parent
f9db67b7
usb
Showing
3 changed files
with
202 additions
and
0 deletions
Show diff stats
No preview for this file type
@@ -0,0 +1,88 @@ | @@ -0,0 +1,88 @@ | ||
1 | +#define OSX 0 | ||
2 | +#define WINDOWS 1 | ||
3 | +#define UBUNTU 2 | ||
4 | +#define ti 20 | ||
5 | + | ||
6 | +#include "Keyboard.h" | ||
7 | +#include <string.h> | ||
8 | + | ||
9 | +// change this to match your platform: | ||
10 | +int platform = WINDOWS; | ||
11 | + | ||
12 | +void setup() { | ||
13 | + // make pin 2 an input and turn on the pull-up resistor so it goes high unless | ||
14 | + // connected to ground: | ||
15 | + pinMode(2, INPUT_PULLUP); | ||
16 | + Keyboard.begin(); | ||
17 | +} | ||
18 | + | ||
19 | +void keyboardprint ( String texte ){ | ||
20 | + int i = 0; | ||
21 | + while (texte[i]!='\0'){ | ||
22 | + if(texte[i]=='@'){ | ||
23 | + Keyboard.write('"'); | ||
24 | + } | ||
25 | + else if(texte[i]=='"'){ | ||
26 | + Keyboard.write('@'); | ||
27 | + } | ||
28 | + else if(texte[i]=='\\'){ | ||
29 | + Keyboard.press(KEY_RIGHT_ALT); | ||
30 | + Keyboard.press(92); | ||
31 | + } | ||
32 | + else { | ||
33 | + Keyboard.write(texte[i]); | ||
34 | + } | ||
35 | + delay(ti); | ||
36 | + Keyboard.releaseAll(); | ||
37 | + i++; | ||
38 | + } | ||
39 | + } | ||
40 | + | ||
41 | +void loop() { | ||
42 | + while (digitalRead(2) == HIGH) { | ||
43 | + // do nothing until pin 2 goes low | ||
44 | + delay(500); | ||
45 | + } | ||
46 | + delay(1000); | ||
47 | + | ||
48 | + switch (platform) { | ||
49 | + case OSX: | ||
50 | + Keyboard.press(KEY_LEFT_GUI); | ||
51 | + // Shift-Q logs out: | ||
52 | + Keyboard.press(KEY_LEFT_SHIFT); | ||
53 | + Keyboard.press('Q'); | ||
54 | + delay(100); | ||
55 | + Keyboard.releaseAll(); | ||
56 | + // enter: | ||
57 | + Keyboard.write(KEY_RETURN); | ||
58 | + break; | ||
59 | + case WINDOWS: | ||
60 | + // ouvertur power shell | ||
61 | + Keyboard.write(KEY_LEFT_GUI); | ||
62 | + delay(ti); | ||
63 | + keyboardprint("powershell"); | ||
64 | + Keyboard.write(KEY_RETURN); | ||
65 | + delay(1000); | ||
66 | + keyboardprint("Invoke-WebRequest -Uri "); | ||
67 | + keyboardprint("\"https://www.mediacollege.com/audio/tone/files/440Hz_44100Hz_16bit_30sec.mp3\""); | ||
68 | + keyboardprint(" -OutFile \"./mp3.mp3\""); | ||
69 | + Keyboard.write(KEY_RETURN); | ||
70 | + delay(1000); | ||
71 | + keyboardprint(".\\mp3.mp3"); | ||
72 | + Keyboard.write(KEY_RETURN); | ||
73 | + break; | ||
74 | + case UBUNTU: | ||
75 | + // CTRL-ALT-DEL: | ||
76 | + Keyboard.press(KEY_LEFT_CTRL); | ||
77 | + Keyboard.press(KEY_LEFT_ALT); | ||
78 | + Keyboard.press(KEY_DELETE); | ||
79 | + delay(1000); | ||
80 | + Keyboard.releaseAll(); | ||
81 | + // Enter to confirm logout: | ||
82 | + Keyboard.write(KEY_RETURN); | ||
83 | + break; | ||
84 | + } | ||
85 | + | ||
86 | + // do nothing: | ||
87 | + while (true); | ||
88 | +} |
@@ -0,0 +1,113 @@ | @@ -0,0 +1,113 @@ | ||
1 | +#include <Keyboard.h> | ||
2 | + | ||
3 | +#include <Wire.h> | ||
4 | +#include "Adafruit_MPR121.h" | ||
5 | + | ||
6 | +#include <string.h> | ||
7 | +#define ti 20 | ||
8 | + | ||
9 | +#ifndef _BV | ||
10 | +#define _BV(bit) (1 << (bit)) | ||
11 | +#endif | ||
12 | + | ||
13 | +// You can have up to 4 on one i2c bus but one is enough for testing! | ||
14 | +Adafruit_MPR121 cap = Adafruit_MPR121(); | ||
15 | + | ||
16 | +// Keeps track of the last pins touched | ||
17 | +// so we know when buttons are 'released' | ||
18 | +uint16_t lasttouched = 0; | ||
19 | +uint16_t currtouched = 0; | ||
20 | +int tab[]={3,7,15,2,6,14,1,5,9,0,4,8}; | ||
21 | + | ||
22 | + | ||
23 | +void Printstr(String msg){ | ||
24 | + Serial.println(msg); | ||
25 | +} | ||
26 | + | ||
27 | +void keyboardprint ( String texte ){ | ||
28 | + int i = 0; | ||
29 | + while (texte[i]!='\0'){ | ||
30 | + if(texte[i]=='@'){ | ||
31 | + Keyboard.write('"'); | ||
32 | + } | ||
33 | + else if(texte[i]=='"'){ | ||
34 | + Keyboard.write('@'); | ||
35 | + } | ||
36 | + else if(texte[i]=='\\'){ | ||
37 | + Keyboard.press(KEY_RIGHT_ALT); | ||
38 | + Keyboard.press(92); | ||
39 | + } | ||
40 | + else { | ||
41 | + Keyboard.write(texte[i]); | ||
42 | + } | ||
43 | + delay(ti); | ||
44 | + Keyboard.releaseAll(); | ||
45 | + i++; | ||
46 | + } | ||
47 | + } | ||
48 | + | ||
49 | +void setup() { | ||
50 | + //keyboard out | ||
51 | + pinMode(2, INPUT_PULLUP); | ||
52 | + Keyboard.begin(); | ||
53 | + | ||
54 | + //Serial | ||
55 | + Serial.begin(9600); | ||
56 | + | ||
57 | + while (!Serial) { // needed to keep leonardo/micro from starting too fast! | ||
58 | + delay(10); | ||
59 | + } | ||
60 | + | ||
61 | + //keyboard in | ||
62 | + Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); | ||
63 | + | ||
64 | + // Default address is 0x5A, if tied to 3.3V its 0x5B | ||
65 | + // If tied to SDA its 0x5C and if SCL then 0x5D | ||
66 | + if (!cap.begin(0x5A)) { | ||
67 | + Serial.println("MPR121 not found, check wiring?"); | ||
68 | + while (1); | ||
69 | + } | ||
70 | + Serial.println("MPR121 found!"); | ||
71 | +} | ||
72 | + | ||
73 | + | ||
74 | + | ||
75 | + | ||
76 | + | ||
77 | +void loop() { | ||
78 | + // Get the currently touched pads | ||
79 | + currtouched = cap.touched(); | ||
80 | + | ||
81 | + for (uint8_t i=0; i<12; i++) { | ||
82 | + // it if *is* touched and *wasnt* touched before, alert! | ||
83 | + if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { | ||
84 | + Serial.print(tab[i]); Serial.println(" touched"); | ||
85 | + } | ||
86 | + // if it *was* touched and now *isnt*, alert! | ||
87 | + if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { | ||
88 | + Serial.print(tab[i]); Serial.println(" released"); | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
92 | + // reset our state | ||
93 | + lasttouched = currtouched; | ||
94 | + | ||
95 | + // comment out this line for detailed data from the sensor! | ||
96 | + return; | ||
97 | + | ||
98 | + // debugging info, what | ||
99 | + Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX); | ||
100 | + Serial.print("Filt: "); | ||
101 | + for (uint8_t i=0; i<12; i++) { | ||
102 | + Serial.print(cap.filteredData(i)); Serial.print("\t"); | ||
103 | + } | ||
104 | + Serial.println(); | ||
105 | + Serial.print("Base: "); | ||
106 | + for (uint8_t i=0; i<12; i++) { | ||
107 | + Serial.print(cap.baselineData(i)); Serial.print("\t"); | ||
108 | + } | ||
109 | + Serial.println(); | ||
110 | + | ||
111 | + // put a delay so it isn't overwhelming | ||
112 | + delay(100); | ||
113 | +} |