CODE


#include <hidboot.h>
#include <usbhub.h>
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
int SKEY = 8;
class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key);
protected:
void OnKeyDown (uint8_t mod, uint8_t key);
void OnKeyUp (uint8_t mod, uint8_t key);
void OnKeyPressed (uint8_t key);
};
void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
{
MODIFIERKEYS mod;
*((uint8_t*)&mod) = m;
Serial.print((mod.bmLeftCtrl == 1) ? "C" : " ");
Serial.print((mod.bmLeftShift == 1) ? "S" : " ");
Serial.print((mod.bmLeftAlt == 1) ? "A" : " ");
Serial.print((mod.bmLeftGUI == 1) ? "G" : " ");
Serial.print(" >");
PrintHex<uint8_t>(key, 0x80);
Serial.print("< ");
Serial.print((mod.bmRightCtrl == 1) ? "C" : " ");
Serial.print((mod.bmRightShift == 1) ? "S" : " ");
Serial.print((mod.bmRightAlt == 1) ? "A" : " ");
Serial.println((mod.bmRightGUI == 1) ? "G" : " ");
};
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
Serial.print("DN ");
PrintKey(mod, key);
uint8_t c = OemToAscii(mod, key);
}
void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
{
Serial.print("UP ");
PrintKey(mod, key);
}
void KbdRptParser::OnKeyPressed(uint8_t key)
{
Serial.print("ASCII: ");
Serial.println((char)key);
};
USB Usb;
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
KbdRptParser Prs;
void setup() {
Serial.begin(9600);
#if !defined(__MIPSEL__)
while (!Serial);
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 1 );
HidKeyboard.SetReportParser(0, &Prs);
}
void loop() {
Usb.Task();
}
Also in my if statement that I made I know I need something before == sign but I tried multiple things and they did not work so I just left it blank and the reason I used the number 16 was because that was the value assigned to the S key in which I wanted to use to light an led. As for that int I made at the very top idk what that is I think that was a mistake from an initial attempt so ignore that. Anyways any help would be greatly appreciated!
PASTED CODE
#include <hidboot.h>
#include <usbhub.h>
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
int SKEY = 8;
class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key);
protected:
void OnKeyDown (uint8_t mod, uint8_t key);
void OnKeyUp (uint8_t mod, uint8_t key);
void OnKeyPressed (uint8_t key);
};
void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
{
MODIFIERKEYS mod;
((uint8_t)&mod) = m;
Serial.print((mod.bmLeftCtrl == 1) ? "C" : " ");
Serial.print((mod.bmLeftShift == 1) ? "S" : " ");
Serial.print((mod.bmLeftAlt == 1) ? "A" : " ");
Serial.print((mod.bmLeftGUI == 1) ? "G" : " ");
Serial.print(" >");
PrintHex<uint8_t>(key, 0x80);
Serial.print("< ");
Serial.print((mod.bmRightCtrl == 1) ? "C" : " ");
Serial.print((mod.bmRightShift == 1) ? "S" : " ");
Serial.print((mod.bmRightAlt == 1) ? "A" : " ");
Serial.println((mod.bmRightGUI == 1) ? "G" : " ");
};
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
Serial.print("DN ");
PrintKey(mod, key);
uint8_t c = OemToAscii(mod, key);
}
void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
{
Serial.print("UP ");
PrintKey(mod, key);
}
void KbdRptParser::OnKeyPressed(uint8_t key)
{
Serial.print("ASCII: ");
Serial.println((char)key);
};
USB Usb;
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
KbdRptParser Prs;
void setup() {
Serial.begin(9600);
#if !defined(MIPSEL)
while (!Serial);
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 1 );
HidKeyboard.SetReportParser(0, &Prs);
}
void loop() {
Usb.Task();
}