device USB Samir

Dependents:   USBJoystick_HelloWorld3

Fork of USBDevice by Samuel Mokrani

Revision:
1:2544b20d1413
Parent:
0:140cdf8e2d60
--- a/USBHID/USBKeyboard.cpp	Wed May 30 18:28:11 2012 +0000
+++ b/USBHID/USBKeyboard.cpp	Wed May 10 20:52:59 2017 +0000
@@ -441,6 +441,65 @@
 int USBKeyboard::_putc(int c) {
     return keyCode(c, keymap[c].modifier);
 }
+// send continues key with out release commande
+// Samir Bouaziz 7 avril 2017
+bool USBKeyboard::keyCode2(uint8_t key, uint8_t modifier, uint8_t release) {
+    // Send a simulated keyboard keypress. Returns true if successful.
+    HID_REPORT report;
+    char code;
+    if(key<152) {
+        code=keymap[key].usage;
+    }else{
+        code=key;
+    }
+
+    report.data[0] = REPORT_ID_KEYBOARD;
+    report.data[1] = modifier;
+    report.data[2] = 0;
+    report.data[3] = code;
+    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;
+    }
+    report.data[1] = 0;
+    report.data[3] = 0;
+    if(release==1){
+        if (!send(&report)) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+// Simule qu'une touche s'est relachée
+//  Samir Bouaziz
+// 7 avril 2017 
+bool USBKeyboard::key_release(){
+        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;
+     if (!send(&report)) {
+        return false;
+    }
+    return true;
+}
 
 bool USBKeyboard::keyCode(uint8_t key, uint8_t modifier) {
     // Send a simulated keyboard keypress. Returns true if successful.