source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 3 years ago

Adding new version

File size: 1.9 KB
Line 
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
32#include "Keyboard.h"
33
34// change this to match your platform:
35int platform = OSX;
36
37void setup() {
38  // make pin 2 an input and turn on the
39  // pullup resistor so it goes high unless
40  // connected to ground:
41  pinMode(2, INPUT_PULLUP);
42  Keyboard.begin();
43}
44
45void loop() {
46  while (digitalRead(2) == HIGH) {
47    // do nothing until pin 2 goes low
48    delay(500);
49  }
50  delay(1000);
51
52  switch (platform) {
53    case OSX:
54      Keyboard.press(KEY_LEFT_GUI);
55      // Shift-Q logs out:
56      Keyboard.press(KEY_LEFT_SHIFT);
57      Keyboard.press('Q');
58      delay(100);
59      Keyboard.releaseAll();
60      // enter:
61      Keyboard.write(KEY_RETURN);
62      break;
63    case WINDOWS:
64      // CTRL-ALT-DEL:
65      Keyboard.press(KEY_LEFT_CTRL);
66      Keyboard.press(KEY_LEFT_ALT);
67      Keyboard.press(KEY_DELETE);
68      delay(100);
69      Keyboard.releaseAll();
70      //ALT-l:
71      delay(2000);
72      Keyboard.press(KEY_LEFT_ALT);
73      Keyboard.press('l');
74      Keyboard.releaseAll();
75      break;
76    case UBUNTU:
77      // CTRL-ALT-DEL:
78      Keyboard.press(KEY_LEFT_CTRL);
79      Keyboard.press(KEY_LEFT_ALT);
80      Keyboard.press(KEY_DELETE);
81      delay(1000);
82      Keyboard.releaseAll();
83      // Enter to confirm logout:
84      Keyboard.write(KEY_RETURN);
85      break;
86  }
87
88  // do nothing:
89  while (true);
90}
91
92
93
94
95
96
97
98
Note: See TracBrowser for help on using the repository browser.