Enter Your Project for a chance to win a Nano Grand Prize bundle for the most innovative use of Arduino plus a $400 shopping cart! | Project14 Home | |
Monthly Themes | ||
Monthly Theme Poll |
The CAPS LOCK key is the most annoying key on the keyboard. Majority of the times, you have noticed, It’s always getting in the way.
Ever enter a password with CAPS LOCK enabled? Huh... Enough times to get locked out of your account? Yeah, me too..(only sometimes).. I Agree'
Even Google decided to drop it all together in their Chromebooks.
Until the rest of the industry decides to follow their lead, they’ll likely be no shortage of awkward emails or overly aggressive comments that are the direct result of this treacherous key.
USB Output Reports and the CAPS LOCK State : Methodology
The CAPS LOCK state of a keyboard attached to a PC is maintained by the PC; not the keyboard. If you attach five keyboards to a PC and hit the CAPS LOCK key on one keyboard, the CAPS LOCK light on all five attached keyboards will illuminate. You can then hit the CAPS LOCK key on a different keyboard and all the CAPS LOCK lights will turn off.
This is implemented by the connected PC sending a periodic USB output report to all the attached keyboards. Inside this USB output report is a bit indicating the current state of the CAPS LOCK, NUM LOCK, and SCROLL LOCK keys. Attached keyboards examine these bits when the USB output report is received and turn their lights on and off according to these bits.
WARNING: THIS PROJECT HAS BEEN DERIVED FROM THE ORIGINAL WORKS OF GLEN ATKINS, AND INSPIRED FROM KEYSIGHT LAB'S WAVE-2020 SERIES BY DANIEL BOGDANOFF).
Working
The annoying caps lock buzzer looks like a keyboard to the host PC except it doesn’t have any keys. The host sends the periodic USB output reports to our “keyboard” and when the USB output report is received, our “keyboard” turns the buzzer on or off to match the state of the CAPS LOCK bit in the USB output report.
Think of it like the little indicator LED on your keyboard, but one that makes a terrible screeching noise that you simply can’t ignore. This is made possible by the fact that the Caps Lock status is handled at the OS level rather than the local input device.
As a side effect, you’ll always know when CAPS LOCK is enabled so entering the wrong password, joining lines when you’re just trying to scroll down in to your thesis report , or answering an entire email (to your .boss.) in ANGRY SCREED format should be history.
THINGS
-Arduino Pro Micro
-Small Buzzer (can be directly powered through Micro)
-An LED (optional; but I chose green one)
Without using the PIC ones (showcased in the original build), I chose to use ATMEGA32U4 based Pro Micro, which also provides the necessary USB 2.0 Data lines for both programming the microcontroller and as a dedicated USB - HID Device (emulated as Keyboard, Mouse, Joystick, PenTest, Rubber Ducky, Remote Injection Tool, etc. etc...tested them all .yay.)
Connections (Clean n Simple)..
- Connect Buzzer+ to pin 3 on pro micro, LED on 9 (your choice) and the rest is ground. You can also use 'pinButton=2 (pull-down)' to initiate a reverse Caps Lock on PC Keyboard from the microcontroller; 'Hacky-way to control'.
CODE:
#include "HID-Project.h"
const int pinLed = 3;
const int pinLed2 = 9;
const int pinButton = 2;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinLed2, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Sends a clean report to the host. This is important on any Arduino type.
BootKeyboard.begin();
}
void loop() {
// Update Led equal to the caps lock state.
// Keep in mind that on a 16u2 and Arduino Micro HIGH and LOW for TX/RX Leds are inverted.
if (BootKeyboard.getLeds() & LED_CAPS_LOCK)
{
digitalWrite(pinLed, HIGH);
digitalWrite(pinLed2, HIGH);
//delay(20);
//digitalWrite(pinLed, LOW);
//digitalWrite(pinLed2, LOW);
//delay(5);
}
else
digitalWrite(pinLed, LOW);
digitalWrite(pinLed2, LOW);
// Trigger caps lock manually via button
if (!digitalRead(pinButton)) {
BootKeyboard.write(KEY_CAPS_LOCK);
// Simple debounce
delay(300);
}
}
(Be sure to include the HID-Project Library from within the IDE Lib Manager; code works for Pro Micro & Leonardo based on Atmel.32U4), may work on Teensy.
'LHS=RHS' ...Proved!