You are viewing an older revision! See the latest version
USBKeyboard
Beta only!
This library is in beta, and only works with the betamode compiler and the beta libraries.
To use these, ensure you have enabled /betamode for the compiler, and that you import these examples as the basis for your experiments to ensure the beta mbed library is pulled in.
The USBKeyboard interface is used to emulate a keyboard over the USB port. You can send basic keys, keys with modifiers (CTRL + 's'), function keys and media keys
USB pins are available on p31 (D+) and p32 (D-)
Hello World¶
#include "mbed.h" #include "USBKeyboard.h" USBKeyboard keyboard; int main(void) { while (1) { keyboard.mediaControl(KEY_VOLUME_DOWN); keyboard.printf("Hello World from Mbed\r\n"); wait(1); } }
Import programUSBKeyboard_HelloWorld
USBKeyboard Hello World
API¶
[Not converted]
More examples¶
Program which controls sound and tracks of your playlist with switches:
#include "mbed.h" #include "USBKeyboard.h" USBKeyboard keyboard; //Bus of buttons BusInOut buttons(p21, p22, p23, p24, p25, p26, p29); int main(void) { uint8_t p_bus = 0; while (1) { //if the bus of buttons has changed, send a report if (buttons.read() != p_bus) { p_bus = buttons.read(); if(p_bus & 0x01) keyboard.mediaControl(KEY_MUTE); if(p_bus & 0x02) keyboard.mediaControl(KEY_VOLUME_DOWN); if(p_bus & 0x04) keyboard.mediaControl(KEY_VOLUME_UP); if(p_bus & 0x08) keyboard.mediaControl(KEY_NEXT_TRACK); if(p_bus & 0x10) keyboard.mediaControl(KEY_PLAY_PAUSE); if(p_bus & 0x20) keyboard.mediaControl(KEY_PREVIOUS_TRACK); if(p_bus & 0x40) keyboard.printf("Hello World\r\n"); } wait(0.01); } }
Import programUSBKeyboard_mediaKeys
USBKeyboard example with media keys