Justin Gensel / USBDevice

Fork of USBDevice by mbed official

Files at this revision

API Documentation at this revision

Comitter:
jgensel3
Date:
Sun Apr 23 19:56:19 2017 +0000
Parent:
8:335f2506f422
Child:
65:31cc40e7864a
Commit message:
wrote 2 functions to press and release keys

Changed in this revision

USBHID/USBKeyboard.cpp Show annotated file Show diff for this revision Revisions of this file
USBHID/USBKeyboard.h Show annotated file Show diff for this revision Revisions of this file
--- a/USBHID/USBKeyboard.cpp	Fri Mar 01 13:10:29 2013 +0000
+++ b/USBHID/USBKeyboard.cpp	Sun Apr 23 19:56:19 2017 +0000
@@ -474,6 +474,43 @@
 }
 
 
+bool USBKeyboard::pressKey(uint8_t key, uint8_t modifier){
+     HID_REPORT report;
+
+    report.data[0] = REPORT_ID_KEYBOARD;
+    report.data[1] = modifier;
+    report.data[2] = 0;
+    report.data[3] = keymap[key].usage;
+    report.data[4] = 0;
+    report.data[5] = 0;
+    report.data[6] = 0;
+    report.data[7] = 0;
+    report.data[8] = 0;
+
+    report.length = 9;
+
+    if (!send(&report)) {
+        return false;
+    }
+    return true;
+}
+
+void USBKeyboard::releaseAllKeys(){
+    HID_REPORT report;
+    report.data[0] = REPORT_ID_KEYBOARD;
+    report.data[1] = 0;
+    report.data[2] = 0;
+    report.data[3] = 0;
+    report.data[4] = 0;
+    report.data[5] = 0;
+    report.data[6] = 0;
+    report.data[7] = 0;
+    report.data[8] = 0;
+    
+    report.length = 9;
+    send(&report);
+}
+
 bool USBKeyboard::mediaControl(MEDIA_KEY key) {
     HID_REPORT report;
 
--- a/USBHID/USBKeyboard.h	Fri Mar 01 13:10:29 2013 +0000
+++ b/USBHID/USBKeyboard.h	Sun Apr 23 19:56:19 2017 +0000
@@ -121,6 +121,10 @@
     * @returns true if there is no error, false otherwise
     */
     bool keyCode(uint8_t key, uint8_t modifier = 0);
+    
+    bool pressKey(uint8_t key, uint8_t modifier = 0);
+    
+    void releaseAllKeys();
 
     /**
     * Send a character