device USB Samir
Dependents: USBJoystick_HelloWorld3
Fork of USBDevice by
Revision 1:2544b20d1413, committed 2017-05-10
- Comitter:
- bouaziz
- Date:
- Wed May 10 20:52:59 2017 +0000
- Parent:
- 0:140cdf8e2d60
- Commit message:
- essai clavier emulation
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 |
diff -r 140cdf8e2d60 -r 2544b20d1413 USBHID/USBKeyboard.cpp --- 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.
diff -r 140cdf8e2d60 -r 2544b20d1413 USBHID/USBKeyboard.h --- a/USBHID/USBKeyboard.h Wed May 30 18:28:11 2012 +0000 +++ b/USBHID/USBKeyboard.h Wed May 10 20:52:59 2017 +0000 @@ -121,7 +121,8 @@ * @returns true if there is no error, false otherwise */ bool keyCode(uint8_t key, uint8_t modifier = 0); - + bool keyCode2(uint8_t key, uint8_t modifier=0, uint8_t release=1); + bool key_release(); /** * Send a character *