Commit 06e78c204091130ddfc76d464348758a61d3a17d
1 parent
5f97e6a2
add cle usb
Showing
1 changed file
with
102 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,102 @@ | @@ -0,0 +1,102 @@ | ||
1 | +/* | ||
2 | + Keyboard logout | ||
3 | + | ||
4 | + This sketch demonstrates the Keyboard library. | ||
5 | + | ||
6 | + When you connect pin 2 to ground, it performs a logout. | ||
7 | + It uses keyboard combinations to do this, as follows: | ||
8 | + | ||
9 | + On Windows, CTRL-ALT-DEL followed by ALT-l | ||
10 | + On Ubuntu, CTRL-ALT-DEL, and ENTER | ||
11 | + On OSX, CMD-SHIFT-q | ||
12 | + | ||
13 | + To wake: Spacebar. | ||
14 | + | ||
15 | + Circuit: | ||
16 | + - Arduino Leonardo or Micro | ||
17 | + - wire to connect D2 to ground | ||
18 | + | ||
19 | + created 6 Mar 2012 | ||
20 | + modified 27 Mar 2012 | ||
21 | + by Tom Igoe | ||
22 | + | ||
23 | + This example is in the public domain. | ||
24 | + | ||
25 | + http://www.arduino.cc/en/Tutorial/KeyboardLogout | ||
26 | +*/ | ||
27 | + | ||
28 | +#define OSX 0 | ||
29 | +#define WINDOWS 1 | ||
30 | +#define UBUNTU 2 | ||
31 | +#define ti 50 | ||
32 | + | ||
33 | +#include "Keyboard.h" | ||
34 | +#include <string.h> | ||
35 | + | ||
36 | +// change this to match your platform: | ||
37 | +int platform = WINDOWS; | ||
38 | + | ||
39 | +void setup() { | ||
40 | + // make pin 2 an input and turn on the pull-up resistor so it goes high unless | ||
41 | + // connected to ground: | ||
42 | + pinMode(2, INPUT_PULLUP); | ||
43 | + Keyboard.begin(); | ||
44 | +} | ||
45 | + | ||
46 | +void keyboardprint ( String texte ){ | ||
47 | + int i = 0; | ||
48 | + while (texte[i]!='\0'){ | ||
49 | + if(isAlpha(texte[i])){ | ||
50 | + if(!isLowerCase(texte[i])){ | ||
51 | + Keyboard.press(KEY_LEFT_SHIFT); | ||
52 | + } | ||
53 | + Keyboard.write(texte[i]-32*isLowerCase(texte[i])); | ||
54 | + } | ||
55 | + delay(ti); | ||
56 | + Keyboard.releaseAll(); | ||
57 | + i++; | ||
58 | + } | ||
59 | + } | ||
60 | + | ||
61 | +void loop() { | ||
62 | + while (digitalRead(2) == HIGH) { | ||
63 | + // do nothing until pin 2 goes low | ||
64 | + delay(500); | ||
65 | + } | ||
66 | + delay(1000); | ||
67 | + | ||
68 | + switch (platform) { | ||
69 | + case OSX: | ||
70 | + Keyboard.press(KEY_LEFT_GUI); | ||
71 | + // Shift-Q logs out: | ||
72 | + Keyboard.press(KEY_LEFT_SHIFT); | ||
73 | + Keyboard.press('Q'); | ||
74 | + delay(100); | ||
75 | + Keyboard.releaseAll(); | ||
76 | + // enter: | ||
77 | + Keyboard.write(KEY_RETURN); | ||
78 | + break; | ||
79 | + case WINDOWS: | ||
80 | + // ouvertur power shell | ||
81 | + Keyboard.write(KEY_LEFT_GUI); | ||
82 | + delay(ti); | ||
83 | + keyboardprint("powershell"); | ||
84 | + Keyboard.write(KEY_RETURN); | ||
85 | + keyboardprint("Invoke-WebRequest –Uri \"https://www.mediacollege.com/audio/tone/files/440Hz_44100Hz_16bit_30sec.mp3\" –OutFile \"./\" "); | ||
86 | + Keyboard.write(KEY_RETURN); | ||
87 | + break; | ||
88 | + case UBUNTU: | ||
89 | + // CTRL-ALT-DEL: | ||
90 | + Keyboard.press(KEY_LEFT_CTRL); | ||
91 | + Keyboard.press(KEY_LEFT_ALT); | ||
92 | + Keyboard.press(KEY_DELETE); | ||
93 | + delay(1000); | ||
94 | + Keyboard.releaseAll(); | ||
95 | + // Enter to confirm logout: | ||
96 | + Keyboard.write(KEY_RETURN); | ||
97 | + break; | ||
98 | + } | ||
99 | + | ||
100 | + // do nothing: | ||
101 | + while (true); | ||
102 | +} | ||
0 | \ No newline at end of file | 103 | \ No newline at end of file |