distributed
New member
I have a Teensy 3.6 with a USB host header installed and a keyboard plugged into it, and have been playing around with the USBHost_t36 library examples and can receive key presses from the keyboard.
What I am having trouble with is to figure out which of the modifier keys was set on key press and release.
Some help with figuring out which of the ctrl,shift,alt,gui keys was pressed would be really appreciated!
Below I have listed the output I receive over the serial and the key combination I pressed on the keyboard attached:
I am assuming that something in the 4 byte code received will have the information I want.
Relevant excerpt from my code is listed below:
Once I figure this out I would like to help update the USBHost_t36 library examples to include this case.
I have been able to get most of the other stuff on T3.6 that I wanted working (RTC, uSD card, etc.) and this is the only thing I am stuck with now :-(
Thanks!
What I am having trouble with is to figure out which of the modifier keys was set on key press and release.
Some help with figuring out which of the ctrl,shift,alt,gui keys was pressed would be really appreciated!
Below I have listed the output I receive over the serial and the key combination I pressed on the keyboard attached:
I am assuming that something in the 4 byte code received will have the information I want.
Code:
// I pressed and released: p
onPress>> sz(4) 112 0x70 'p' 1110000
onRelease>> sz(4) 112 0x70 p
// I pressed and released: shift+p
onPress>> sz(4) 80 0x50 'P' 1010000
onRelease>> sz(4) 80 0x50 P
// I pressed and released: ctrl+p
onPress>> sz(4) 16 0x10 '' 10000
onRelease>> sz(4) 16 0x10
// I pressed and released: alt+p
onPress>> sz(4) 112 0x70 'p' 1110000
onRelease>> sz(4) 112 0x70 p
// and now the same sequence with "s"
onPress>> sz(4) 115 0x73 's' 1110011
onRelease>> sz(4) 115 0x73 s
onPress>> sz(4) 83 0x53 'S' 1010011
onRelease>> sz(4) 83 0x53 S
onPress>> sz(4) 19 0x13 '' 10011
onRelease>> sz(4) 19 0x13
onPress>> sz(4) 115 0x73 's' 1110011
onRelease>> sz(4) 115 0x73 s
Relevant excerpt from my code is listed below:
Code:
USBHost myusb;
KeyboardController keyboard1(myusb);
void setup()
{
while (!Serial) ; // wait for Arduino Serial Monitor
myusb.begin();
keyboard1.attachPress(OnPress);
keyboard1.attachRelease(OnRelease);
}
void OnPress(auto key)
{
char buff[128] = {0};
char poof[64] = {0};
long lk = key;
ltoa( lk, poof, 2);
snprintf(buff, 127, "onPress>> sz(%u) %u 0x%x '%c' %s\n", sizeof(key), key, key, key, poof);
Serial.print(buff);
}
void OnRelease(int key)
{
char buff[128] = {0};
snprintf(buff, 127, "onRelease>> sz(%u) %u 0x%x %c\n", sizeof(key), key, key, key);
Serial.print(buff);
}
Once I figure this out I would like to help update the USBHost_t36 library examples to include this case.
I have been able to get most of the other stuff on T3.6 that I wanted working (RTC, uSD card, etc.) and this is the only thing I am stuck with now :-(
Thanks!