| 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 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardLogout |
| 26 |
*/ |
| 27 |
|
| 28 |
#define OSX 0 |
| 29 |
#define WINDOWS 1 |
| 30 |
#define UBUNTU 2 |
| 31 |
|
| 32 |
#include "Keyboard.h" |
| 33 |
|
| 34 |
// change this to match your platform: |
| 35 |
int platform = OSX; |
| 36 |
|
| 37 |
void setup() { |
| 38 |
// make pin 2 an input and turn on the pull-up resistor so it goes high unless |
| 39 |
// connected to ground: |
| 40 |
pinMode(2, INPUT_PULLUP); |
| 41 |
Keyboard.begin(); |
| 42 |
} |
| 43 |
|
| 44 |
void loop() { |
| 45 |
while (digitalRead(2) == HIGH) { |
| 46 |
// do nothing until pin 2 goes low |
| 47 |
delay(500); |
| 48 |
} |
| 49 |
delay(1000); |
| 50 |
|
| 51 |
switch (platform) { |
| 52 |
case OSX: |
| 53 |
Keyboard.press(KEY_LEFT_GUI); |
| 54 |
// Shift-Q logs out: |
| 55 |
Keyboard.press(KEY_LEFT_SHIFT); |
| 56 |
Keyboard.press('Q'); |
| 57 |
delay(100); |
| 58 |
Keyboard.releaseAll(); |
| 59 |
// enter: |
| 60 |
Keyboard.write(KEY_RETURN); |
| 61 |
break; |
| 62 |
case WINDOWS: |
| 63 |
// CTRL-ALT-DEL: |
| 64 |
Keyboard.press(KEY_LEFT_CTRL); |
| 65 |
Keyboard.press(KEY_LEFT_ALT); |
| 66 |
Keyboard.press(KEY_DELETE); |
| 67 |
delay(100); |
| 68 |
Keyboard.releaseAll(); |
| 69 |
// ALT-l: |
| 70 |
delay(2000); |
| 71 |
Keyboard.press(KEY_LEFT_ALT); |
| 72 |
Keyboard.press('l'); |
| 73 |
Keyboard.releaseAll(); |
| 74 |
break; |
| 75 |
case UBUNTU: |
| 76 |
// CTRL-ALT-DEL: |
| 77 |
Keyboard.press(KEY_LEFT_CTRL); |
| 78 |
Keyboard.press(KEY_LEFT_ALT); |
| 79 |
Keyboard.press(KEY_DELETE); |
| 80 |
delay(1000); |
| 81 |
Keyboard.releaseAll(); |
| 82 |
// Enter to confirm logout: |
| 83 |
Keyboard.write(KEY_RETURN); |
| 84 |
break; |
| 85 |
} |
| 86 |
|
| 87 |
// do nothing: |
| 88 |
while (true); |
| 89 |
} |