USB keyboard hardware proxy

@Paul @mcrc - I am thinking we probably should have an example keyboard forward sketch in the library...

Also wondering if we should Pull in the PRs from a couple of years ago to help with this and/or do similar...

But: I did verify that:
Code:
void OnHIDExtrasPress(uint32_t top, uint16_t key)
{
  if (top == 0xc0000) {
    Keyboard.press(0XE400 | key);
  }
}

void OnHIDExtrasRelease(uint32_t top, uint16_t key)
{
  if (top == 0xc0000) {
    Keyboard.release(0XE400 | key);
  }
}
Appears to work, at least when I tried it on Keyboard only.

I built it and ran it with my old Dell keyboard, and when I press the Calculator key on the keyboard, it brought up the calculator app...

Note: this was based semi on the code in the MediaButtons Example under USB Type keyboard
 
I actually tried this too, it doesnt trigger any Media Buttons :(
 
Last edited:
Your script passes normal keys just fine.
But media keys wont pass, same as the solution provided few posts before.
 
Probably need additional information, like:
Which Keyboard?
What computer (I am assuming Windows 10? 32 or 64 bit?
Which version of Arduino and Teensyduino?

Do those keys work on your computer if you plug the keyboard directly into your computer?
 
Keyboard: HyperX Alloy FPS Pro Mechanical Gaming Keyboard
Computer: Windows 10 64 bit
Arduino: 1.8.16
Teensyduino: 1.55

Yeah, they work perfectly fine directly plugged in, and they also being detected by the Mouse HIDParser. Just the pass through is not working with your .ino script or code.
 
Not sure what to suggest here... I tried three different keyboards And they are able to control things on my Window 10 64 bit machine...

Wondering fi the HyperX installs it's own driver to Keyboard? If you bring up the Keyboard controller does it show anything interesting? Like a non-Microsoft driver?
 
@mcrc - Not sure what else to try.

With the test sketch I have tried with three different keyboards and I tried building all of the different USB types that support keyboard on MMOD... Yes could try on T4.1 as well, but they should both be using the same code and have the same options with keyboard...

I did push up a slightly modified version of the sketch in #28 where I turned on Serial output.
And I try generate an error if keyboard is defined but not KEYMEDIA...
Code:
void OnHIDExtrasPress(uint32_t top, uint16_t key)
{
#ifdef KEYBOARD_INTERFACE
  if (top == 0xc0000) {
    Keyboard.press(0XE400 | key);
    #ifndef KEYMEDIA_INTERFACE
    #error "KEYMEDIA_INTERFACE is Not defined"
    #endif
  }
#endif
...

Walking through the usb_desc_h for T4.x, I believe that every time KEYBOARD_INTERFACE is defined so is: KEYMEDIA_INTERFACE
Except once, with the #elif defined(USB_EVERYTHING)
But there is nothing in boards.txt that will define this for T4.x AND it could not work as this one has in it more endpoints than a T4.x supports...

But regardless you may want to try same test to verify it is defined for your configuration.

Which USB type are you using? And have you made any changes to it?
 
It seems this passes through every key combination except the following key presses:
1. Windows Key (it doesn't pass through the Windows Key it seems)
2. Keeping CTRL pressed in combination with mouse wheel (for example to zoom in and out of an document)
This probably applies to ALT and ALT GR, too.

Take it as and idea to expand the current example.
 
Thanks, I try to take a look again...

1) If I remember correctly this may be totally on different interface or page... will check again.

2) I only updated the modifiers going out to host when key is pressed... Wonder if maybe I need to check this on every message coming in... Other than that the CTRL+MOUSE or two different devices so probably something external from this code... But who knows.

Thanks again
 
@smurf - pushed up a new copy to github/Pull Request.

I hopefully now keep the modifier keys more in sync...

So yes it should know when ALT or other alt is pressed regardless if you press another key or not...
 
@KurtE
Thank you for making this example

However, I believe you have to use "Keyboard.send_now();" whenever "Keyboard.set_modifier" is used.
I was having issues with the modifier keys getting stuck when holding a modifier and then pressing a regular key. But after adding send_now() the issue is resolved (although it still does not seem to be updated when calling "keyboard1.getModifiers()").

This also will fix the windows key
 
A simple example of a USB keyboard pass through. I verified it works on a Xbox One.

Code:
// derived from "mouse" example of USBHost_t36 library
// simple relaying of keystrokes between a keyboard connected to the
// usb host port of a teensy 3.6 and the output of the teensy
// acting as a usb keyboard

/*
  The Teensy 3.6 has a USB host port as well as the usual USB device port
  so it can act as a USB pass through or proxy device.

  The pull request below (not mine) allows a sketch to receive the
  USB keyboard HID report when it arrives from the USB host port.
  This version does not require changes to Keyboard.

  Latest usbhost_t36 from git
  https://github.com/PaulStoffregen/USBHost_t36

  with this pull request applied
  https://github.com/PaulStoffregen/USBHost_t36/pull/18

  Hardware
    Teensy 3.6 board
    https://www.pjrc.com/store/teensy36.html
    Teensy 3.6 USB host cable
    https://www.pjrc.com/store/cable_usb_host_t36.html
*/

#include "USBHost_t36.h"  // to host a usb keyboard
#include "Keyboard.h"     // to act as a usb keyboard device

USBHost myusb;
KeyboardController keyboard_in(myusb);

/*
  Key remap possiblities
    Swap LeftCtrl and CapsLock. Put CapsLock in the corner where it belongs!
    Switchable QWERTY, Dvorak, and colemak keyboard layouts
    Hardware key macros
    Remappings and macros that work even in BIOS and recovery mode.
    Remappings and macros that work with KVMs and game consoles.
*/
void reportReader(const uint8_t report[8])
{
  Keyboard.set_modifier(report[0]);
  Keyboard.set_key1(report[2]);
  Keyboard.set_key2(report[3]);
  Keyboard.set_key3(report[4]);
  Keyboard.set_key4(report[5]);
  Keyboard.set_key5(report[6]);
  Keyboard.set_key6(report[7]);
  Keyboard.send_now();
}

void setup()
{
  myusb.begin();
  keyboard_in.attachReportReader(reportReader);
}

void loop() {
  myusb.Task();
}

@Paul @mcrc - I am thinking we probably should have an example keyboard forward sketch in the library...

Also wondering if we should Pull in the PRs from a couple of years ago to help with this and/or do similar...

But: I did verify that:
Code:
void OnHIDExtrasPress(uint32_t top, uint16_t key)
{
  if (top == 0xc0000) {
    Keyboard.press(0XE400 | key);
  }
}

void OnHIDExtrasRelease(uint32_t top, uint16_t key)
{
  if (top == 0xc0000) {
    Keyboard.release(0XE400 | key);
  }
}
Appears to work, at least when I tried it on Keyboard only.

I built it and ran it with my old Dell keyboard, and when I press the Calculator key on the keyboard, it brought up the calculator app...

Note: this was based semi on the code in the MediaButtons Example under USB Type keyboard

Combining these two with the mouse.ino variables for hub, etc. worked the best for me.
 
Back
Top