mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Added new Keyboard combo examples
This commit is contained in:
parent
2cff5593ec
commit
2c90355ca2
@ -0,0 +1,73 @@
|
||||
/*
|
||||
Arduino Programs Blink
|
||||
|
||||
This sketch demonstrates the Keyboard library.
|
||||
|
||||
When you connect pin 12 to ground, it creates a new
|
||||
window with a key combination (CTRL-N),
|
||||
then types in the Blink sketch, then auto-formats the text
|
||||
using another key combination (CTRL-T), then
|
||||
uploads the sketch to the currently selected Arduino using
|
||||
a final key combination (CTRL-U).
|
||||
|
||||
Circuit:
|
||||
* Arduino Leonardo
|
||||
* wire to connect D12 to ground.
|
||||
|
||||
created 5 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
|
||||
*/
|
||||
void setup() {
|
||||
// make pin 12 an input and turn on the
|
||||
// pullup resistor so it goes high unless
|
||||
// connected to ground:
|
||||
pinMode(12, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (digitalRead(12) == HIGH) {
|
||||
// do nothing until pin 12 goes low
|
||||
delay(500);
|
||||
}
|
||||
// new document:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press('N');
|
||||
Keyboard.releaseAll();
|
||||
// wait for new window to open:
|
||||
delay(1000);
|
||||
// Type out "blink":
|
||||
Keyboard.println("void setup() {");
|
||||
Keyboard.println("pinMode(13, OUTPUT);");
|
||||
Keyboard.println("}");
|
||||
Keyboard.println();
|
||||
Keyboard.println("void loop() {");
|
||||
Keyboard.println("digitalWrite(13, HIGH);");
|
||||
Keyboard.print("delay(3000);");
|
||||
// 3000 ms is too long. Delete it:
|
||||
for (int keystrokes=0; keystrokes < 6; keystrokes++) {
|
||||
Keyboard.type(KEY_BACKSPACE);
|
||||
}
|
||||
// make it 1000 instead:
|
||||
Keyboard.println("1000);");
|
||||
Keyboard.println("digitalWrite(13, LOW);");
|
||||
Keyboard.println("delay(1000);");
|
||||
// tidy up:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press('T');
|
||||
Keyboard.releaseAll();
|
||||
delay(3000);
|
||||
// upload code:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press('U');
|
||||
Keyboard.releaseAll();
|
||||
|
||||
// wait for the sweet oblivion of reprogramming:
|
||||
while(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Keyboard wake-on-interrupt
|
||||
|
||||
This sketch demonstrates the Keyboard library.
|
||||
|
||||
With most operating systems, when the computer is in sleep mode,
|
||||
tapping the space bar will wake it up. This sketch puts your
|
||||
computer to sleep, waits ten seconds, then wakes it up.
|
||||
|
||||
|
||||
Circuit:
|
||||
* Arduino Leonardo
|
||||
* wire to connect D12 to ground.
|
||||
|
||||
created 5 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardSleep
|
||||
*/
|
||||
|
||||
// give the operating systems numbers:
|
||||
#define OSX 0
|
||||
#define WIN7 1
|
||||
#define WINXP 2
|
||||
#define UBUNTU 3
|
||||
|
||||
int plastform = OSX; // change this to match your platform
|
||||
|
||||
void setup() {
|
||||
// make pin 12 an input and turn on the
|
||||
// pullup resistor so it goes high unless
|
||||
// connected to ground:
|
||||
pinMode(12, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (digitalRead(12) == HIGH) {
|
||||
// do nothing until pin 12 goes low
|
||||
delay(500);
|
||||
}
|
||||
|
||||
//Put the computer to sleep:
|
||||
switch (platform) {
|
||||
case OSX:
|
||||
Keyboard.press(KEY_LEFT_GUI);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_F12);
|
||||
Keyboard.releaseAll();
|
||||
break;
|
||||
case WIN7:
|
||||
Keyboard.press(KEY_LEFT_GUI);
|
||||
Keyboard.press(KEY_RIGHT_ARROW);
|
||||
Keyboard.press(KEY_RETURN);
|
||||
Keyboard.releaseAll();
|
||||
break;
|
||||
case WINXP:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_DELETE);
|
||||
delay(1000);
|
||||
Keyboard.type('S');
|
||||
Keyboard.type('H');
|
||||
break;
|
||||
case UBUNTU:
|
||||
// ubuntu keystrokes?
|
||||
|
||||
break;
|
||||
}
|
||||
// wait ten seconds, then wake the computer back up:
|
||||
delay(10000);
|
||||
Keyboard.type(' ');
|
||||
|
||||
// wait forever:
|
||||
while(true);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user