Closed InsertPotatoHere closed 3 years ago
Instead of OnPress/attachOnPress, I used onRawPress.
However, I did need to comment out some lines in keyboard.cpp
for the lines that contained if(attachOnPressFunction)
, since they didnt seem to work properly. Commenting them out is a very bootleg/temporary way to fix this. I commented out 2 instances where if it checked for if this function existed, line 256 and line 275, as well as their closing braces. However, once done, the functions work as expected. Heres the replaced code snippet
#include <USBHost_t36.h>
USBHost myusb;
KeyboardController keyboard1(myusb);
void setup(){
while (!Serial) ; // wait for Arduino Serial Monitor
myusb.begin();
keyboard1.attachRawPress(OnRawPress);
keyboard1.attachRawRelease(OnRawRelease);
}
void OnRawPress(uint8_t key){
Serial.println(key);//Works, but has different keycodes
}
void OnRawRelease(uint8_t key){
Serial.println(key);
}
When attaching a function in the attachPress() function, the attached functions have no support for any modifier keys such as the GUI key are pressed or released. An example snipped is included below tested on Arduino IDE 1.8.9 with "USB Type: Keyboard" on a Teensy 3.6
In addition, keys such as Caps Lock, Num Lock, Print Screen, Scroll Lock, and Pause Break are able to call the OnPress and OnRelease functions as shown above, however they are returning 0. Neither of these keys return a modifier code nor a keycode, yet are still able to call the OnPress and OnRelease function with a likely null value. When looking into this, I found that Print Screen with codes: 0x46 (raw: 0xCE) stated on this fourm post returns 0 when pressed, but the actual keycode overlaps with the ASCII value for "F". I am unsure if it is because there are overlaps with key codes, but running
Keyboard.press(206);
still does not press the print screen key.