USBMouseKeyboard
USBMouseKeyboard class hierarchy
You can use the USBMouseKeyboard interface to emulate a mouse and a keyboard at the same time over the USB port. You can send both key presses and mouse movements with this class.
USBMouseKeyboard class reference
Public Member Functions | |
USBMouseKeyboard (bool connect_blocking=true, MOUSE_TYPE mouse_type=REL_MOUSE, uint16_t vendor_id=0x0021, uint16_t product_id=0x0011, uint16_t product_release=0x0001) | |
Basic constructor. More... | |
USBMouseKeyboard (USBPhy *phy, MOUSE_TYPE mouse_type=REL_MOUSE, uint16_t vendor_id=0x0021, uint16_t product_id=0x0011, uint16_t product_release=0x0001) | |
Fully featured constructor. More... | |
virtual | ~USBMouseKeyboard () |
Destroy this object. More... | |
bool | update (int16_t x, int16_t y, uint8_t buttons, int8_t z) |
Write a state of the mouse. More... | |
bool | move (int16_t x, int16_t y) |
Move the cursor to (x, y) More... | |
bool | press (uint8_t button) |
Press one or several buttons. More... | |
bool | release (uint8_t button) |
Release one or several buttons. More... | |
bool | doubleClick () |
Double click (MOUSE_LEFT) More... | |
bool | click (uint8_t button) |
Click. More... | |
bool | scroll (int8_t z) |
Scrolling. More... | |
bool | key_code (uint8_t key, uint8_t modifier=0) |
To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key. More... | |
virtual int | _putc (int c) |
Send a character. More... | |
bool | media_control (MEDIA_KEY key) |
Control media keys. More... | |
uint8_t | lock_status () |
Read status of lock keys. More... | |
bool | ready () |
Check if this class is ready. More... | |
void | wait_ready () |
Block until this HID device is in the configured state. More... | |
bool | send (const HID_REPORT *report) |
Send a Report. More... | |
bool | send_nb (const HID_REPORT *report) |
Send a Report. More... | |
bool | read (HID_REPORT *report) |
Read a report: blocking. More... | |
bool | read_nb (HID_REPORT *report) |
Read a report: non blocking. More... | |
void | init () |
Initialize this instance. More... | |
void | deinit () |
Power down this instance. More... | |
bool | configured () |
Check if the device is configured. More... | |
void | connect () |
Connect a device This method can also be used to resume USB operation when USB power is detected after it was suspended via USBDevice::deinit. More... | |
void | disconnect () |
Disconnect a device. More... | |
void | sof_enable () |
Enable the start of frame interrupt. More... | |
void | sof_disable () |
Disable the start of frame interrupt. More... | |
bool | endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback< void()> callback=NULL) |
Add an endpoint. More... | |
template<typename T > | |
bool | endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void(T::*callback)()) |
Add an endpoint. More... | |
void | endpoint_remove (usb_ep_t endpoint) |
Remove an endpoint. More... | |
void | endpoint_remove_all () |
Remove all non-zero endpoints. More... | |
void | endpoint_stall (usb_ep_t endpoint) |
Stall an endpoint. More... | |
void | endpoint_unstall (usb_ep_t endpoint) |
Un-stall an endpoint. More... | |
uint32_t | endpoint_max_packet_size (usb_ep_t endpoint) |
Get the current maximum size for this endpoint. More... | |
void | endpoint_abort (usb_ep_t endpoint) |
Abort the current transfer on this endpoint. More... | |
bool | read_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size) |
start a read on the given endpoint More... | |
uint32_t | read_finish (usb_ep_t endpoint) |
Get the status of a read. More... | |
bool | write_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size) |
Write a data to the given endpoint. More... | |
uint32_t | write_finish (usb_ep_t endpoint) |
Get the status of a write. More... | |
virtual int | close () |
Close a file. More... | |
virtual ssize_t | write (const void *buffer, size_t length) |
Write the contents of a buffer to a file. More... | |
virtual ssize_t | read (void *buffer, size_t length) |
Read the contents of a file into a buffer. More... | |
virtual off_t | seek (off_t offset, int whence) |
Move the file position to a given offset from from a given location. More... | |
virtual off_t | tell () |
Get the file position of the file. More... | |
virtual void | rewind () |
Rewind the file position to the beginning of the file. More... | |
virtual int | isatty () |
Check if the file in an interactive terminal device. More... | |
virtual int | sync () |
Flush any buffers associated with the file. More... | |
virtual off_t | size () |
Get the size of the file. More... | |
virtual int | truncate (off_t length) |
Truncate or extend a file. More... | |
virtual off_t | lseek (off_t offset, int whence) |
Move the file position to a given offset from a given location. More... | |
virtual int | fsync () |
Flush any buffers associated with the FileHandle, ensuring it is up to date on disk. More... | |
virtual off_t | flen () |
Find the length of the file. More... | |
virtual int | set_blocking (bool blocking) |
Set blocking or nonblocking mode of the file operation like read/write. More... | |
virtual bool | is_blocking () const |
Check current blocking or nonblocking mode for file operations. More... | |
virtual int | enable_input (bool enabled) |
Enable or disable input. More... | |
virtual int | enable_output (bool enabled) |
Enable or disable output. More... | |
virtual short | poll (short events) const |
Check for poll event flags You can use or ignore the input parameter. More... | |
bool | writable () const |
Definition depends on the subclass implementing FileHandle. More... | |
bool | readable () const |
Definition depends on the subclass implementing FileHandle. More... | |
virtual void | sigio (Callback< void()> func) |
Register a callback on state change of the file. More... |
Protected Member Functions | |
virtual void | callback_state_change (DeviceState new_state) |
Called when USB changes state. More... | |
virtual void | callback_request (const setup_packet_t *setup) |
Called by USBDevice on Endpoint0 request. More... | |
virtual void | callback_request_xfer_done (const setup_packet_t *setup, bool aborted) |
Called by USBDevice on data stage completion. More... | |
virtual void | callback_power (bool powered) |
Called by USBDevice layer on power state change. More... | |
virtual void | callback_sof (int frame_number) |
Called by USBDevice layer on each new USB frame. More... | |
virtual void | callback_reset () |
Called by USBDevice layer on bus reset. More... | |
void | complete_request (RequestResult result, uint8_t *data=NULL, uint32_t size=0) |
Called to complete the setup stage of a callback request. More... | |
void | complete_request_xfer_done (bool success) |
Called to complete the data stage of a callback request. More... | |
void | complete_set_configuration (bool success) |
Called to complete a set configuration command. More... | |
void | complete_set_interface (bool success) |
Called to complete a set interface command. More... | |
uint8_t * | find_descriptor (uint8_t descriptor_type, uint8_t index=0) |
Find a descriptor type inside the configuration descriptor. More... | |
const usb_ep_table_t * | endpoint_table () |
Get the endpoint table of this device. More... | |
virtual void | start_process () |
Callback called to indicate the USB processing needs to be done. More... | |
virtual void | lock () |
Acquire exclusive access to this instance USBDevice. More... | |
virtual void | unlock () |
Release exclusive access to this instance USBDevice. More... | |
virtual void | assert_locked () |
Assert that the current thread of execution holds the lock. More... | |
virtual void | lock () |
Acquire exclusive access to this object. More... | |
virtual void | unlock () |
Release exclusive access to this object. More... |
USBMouseKeyboard example
//Dual mouse/keyboard device example
//Example will "type" ASCII characters to the screen, move the mouse around in a circle, and assert various media and modifier keys
#include "mbed.h"
#include "USBMouseKeyboard.h"
//LED1: NUM_LOCK
//LED2: CAPS_LOCK
//LED3: SCROLL_LOCK
BusOut leds(LED1, LED2, LED3);
//USBMouseKeyboard object
USBMouseKeyboard key_mouse;
int main(void) {
int16_t x = 0;
int16_t y = 0;
int32_t radius = 70;
int32_t angle = 0;
while (1) {
//moves the coordinates of the mouse around in a circle
x = cos((double)angle*3.14/50.0)*radius;
y = sin((double)angle*3.14/50.0)*radius;
//example of a media key press
key_mouse.media_control(KEY_VOLUME_DOWN);
//example of simple keyboard output
key_mouse.printf("Hello World from Mbed\r\n");
//function to move the mouse to coordinates "x, y"
key_mouse.move(x, y);
//example of modifier key press
key_mouse.key_code(KEY_CAPS_LOCK);
leds = key_mouse.lock_status();
wait(0.05);
key_mouse.media_control(KEY_VOLUME_UP);
key_mouse.key_code(KEY_NUM_LOCK);
leds = key_mouse.lock_status();
wait(0.05);
angle += 10;
key_mouse.key_code(KEY_SCROLL_LOCK);
leds = key_mouse.lock_status();
wait(0.05);
}
}