USBMouseKeyboard

The USBMouseKeyboard interface is used to emulate a mouse and a keyboard at the same time over the USB port.

The USB connector should be attached to

  • p31 (D+), p32 (D-) and GND for the LPC1768 and the LPC11U24
  • The on-board USB connector of the FRDM-KL25Z

Hello World

» Import this program

#include "mbed.h"
#include "USBMouseKeyboard.h"
 
//LED1: NUM_LOCK
//LED2: CAPS_LOCK
//LED3: SCROLL_LOCK
BusOut leds(LED1, LED2, LED3);
 
//USBMouseKeyboard
USBMouseKeyboard key_mouse;
 
int main(void) {
    while (1) {
        key_mouse.mediaControl(KEY_VOLUME_DOWN);
        key_mouse.printf("Hello World from Mbed\r\n");
        key_mouse.keyCode('s', KEY_CTRL);
        key_mouse.move(20, 0);
        key_mouse.keyCode(KEY_SCROLL_LOCK);
        wait(1);
        leds = key_mouse.lockStatus();
    }
}

API

» Import this library into a program

Public Member Functions

  USBMouseKeyboard (MOUSE_TYPE mouse_type=REL_MOUSE, uint16_t vendor_id=0x0021, uint16_t product_id=0x0011, uint16_t product_release=0x0001)
  Constructor.
bool  update (int16_t x, int16_t y, uint8_t buttons, int8_t z)
  Write a state of the mouse.
bool  move (int16_t x, int16_t y)
  Move the cursor to (x, y)
bool  press (uint8_t button)
  Press one or several buttons.
bool  release (uint8_t button)
  Release one or several buttons.
bool  doubleClick ()
  Double click (MOUSE_LEFT)
bool  click (uint8_t button)
  Click.
bool  scroll (int8_t z)
  Scrolling.
bool  keyCode (uint8_t key, uint8_t modifier=0)
  To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key.
virtual int  _putc (int c)
  Send a character.
bool  mediaControl (MEDIA_KEY key)
  Control media keys.
uint8_t  lockStatus ()
  Read status of lock keys.
bool  send (HID_REPORT *report)
  Send a Report.
bool  sendNB (HID_REPORT *report)
  Send a Report.
bool  read (HID_REPORT *report)
  Read a report: blocking.
bool  readNB (HID_REPORT *report)
  Read a report: non blocking.

Details

You can choose either a relative mouse or an absolute mouse with the keyboard. By default, a USBMouseKeyboard is a relative mouse and a keyboard




2 comments:

12 Jun 2012

If you would like to use serial to keyboard mouse control try out this repository

» Import this programKeyboardMouseSerialV2

Updated many functions and bugs from the previous version. This program can emulate the keyboard and mouse on another computer using serial input [PC1-USB-MBED-USB-PC2] Control using serial input to keyboard/mouse output like a regular keyboard and mouse.

Connect EXT usb to Slave computer and mbed USB to Host computer [Host-Mbed-Slave]

Send the commands which have been noted inside the cpp file for you

17 Jun 2012

Is there a way to also add serial port to this usb connection? i'm already using the mbed usb for serial communication to another pc but i want to use this ext connection not only as usb but with serial aswell?

My mbed should look like this

          Serial?                      <Questioned Connection????
COMPUTER2 =======mbed------- COMPUTER1 <MY SETUP
          USB         SERIAL           <ALREADY ESTABLISHED CONNECTIONS

Posting comments for this page has been disabled