Mouse boot protocol?

Status
Not open for further replies.

justinj

New member
I bought a Teensy 3.2 as I couldn't get my Arduino Micro to work with the BootKeyboard library.
The Teensy works fine as a keyboard in boot mode, however I can't get the mouse to work. Is there something I need to do to get the mouse functioning in boot mode? When I plug it into a computer running Windows 7 the code works fine and as expected. When I connect it via the KVM (The reason I need it in boot mode) it doesn't function. The sketch is designed to operate the KVM (Screen toggle and click a button with emulated mouse) from a 4 button remote and since switching to Teensy the screen toggle (Double tap CTRL) works (The keypress is registering as the LED does flash).

Code:
const int KeypadA = 4;
const int KeypadB = 3;
const int KeypadC = 2;
const int KeypadD = 1;
int Keypress = 0;
int KeyA = 0;
int KeyB = 0;
int KeyC = 0;
int KeyD = 0;
  
void setup() {
  Mouse.screenSize(1920, 1080);
  pinMode(KeypadA, INPUT);
  pinMode(KeypadB, INPUT);
  pinMode(KeypadC, INPUT);
  pinMode(KeypadD, INPUT);
  pinMode(13, OUTPUT);  
  for(int x = 0; x < 125; x++){
    digitalWrite(13, HIGH);
    delay(20);
    digitalWrite(13, LOW);
    delay(20);
  }
}

void loop() {
  delay(2);
  Keypress = digitalRead(KeypadA);
  if (Keypress == HIGH) {
    KeyA = KeyA + 1;
    KeyB = 0;
    KeyC = 0;
    KeyD = 0;
  }
  Keypress = digitalRead(KeypadB);
  if (Keypress == HIGH) {
    KeyA = 0;
    KeyB = KeyB + 1;
    KeyC = 0;
    KeyD = 0;
  }
  Keypress = digitalRead(KeypadC);
  if (Keypress == HIGH) {
    KeyA = 0;
    KeyB = 0;
    KeyC = KeyC + 1;
    KeyD = 0;
  }
  Keypress = digitalRead(KeypadD);
  if (Keypress == HIGH) {
    KeyA = 0;
    KeyB = 0;
    KeyC = 0;
    KeyD = KeyD + 1;
  }
  if (KeyA == 3) {
    digitalWrite(13, HIGH);
    Keyboard.press(MODIFIERKEY_CTRL);
    delay(20);
    digitalWrite(13, LOW);
    Keyboard.release(MODIFIERKEY_CTRL);
    delay(100);
    digitalWrite(13, HIGH);
    Keyboard.press(MODIFIERKEY_CTRL);
    delay(20);
    digitalWrite(13, LOW);
    Keyboard.release(MODIFIERKEY_CTRL);
    delay(860);
    KeyA = 0;
    KeyB = 0;
    KeyC = 0;
    KeyD = 0;
  }
  if (KeyB == 3) {
    digitalWrite(13, HIGH);
    Mouse.moveTo(1650,1036);
    delay(50);
    digitalWrite(13, LOW);
    Mouse.click();
    delay(950);
    KeyA = 0;
    KeyB = 0;
    KeyC = 0;
    KeyD = 0;
  }
}
 
Last edited:
At the very least, you're going to have to edit usb_desc.c. Look for this:

Code:
#ifdef MOUSE_INTERFACE
        // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
        9,                                      // bLength
        4,                                      // bDescriptorType
        MOUSE_INTERFACE,                        // bInterfaceNumber
        0,                                      // bAlternateSetting
        1,                                      // bNumEndpoints
        0x03,                                   // bInterfaceClass (0x03 = HID)
        0x00,                                   // bInterfaceSubClass (0x01 = Boot)
        0x00,                                   // bInterfaceProtocol (0x02 = Mouse)

As you can see, those 2 lines are zero to 0x00, telling your PC the boot protocol isn't supported. As a first try, maybe just change them to 0x01 and 0x02 and see what happens?

We added the absolute positioning stuff to the USB mouse some time ago, which is the reason it no longer supports boot protocol. You'll probably have to undo that, which means editing the HID descriptor to remove the report IDs, and then editing the usb_mouse.c code to not transmit that first byte for the report ID (and never transmit the absolute position report).
 
Looks like the github history doesn't go back far enough.

Here's the oldest backup I have, with the old version that once supported mouse boot protocol, but not Mouse.moveTo(). This is extremely old, so I really can't give you any support with this, other than digging up and sharing this ancient code. Hopefully it at least helps a little?
 

Attachments

  • ancient_corelib_mouse_bootprotocol.zip
    117.5 KB · Views: 140
Not sure if it breaks HID protocol, but using the current Teensyduino and editing usb_desc.c has worked for me :D
That being said, I had to play around with it a bit to get Mouse.move to work in place of Mouse.moveTo; Pulled mouse to top left of the screen, then with a bit of tinkering got some values in a for loop that work regardless of what Windows mouse sensitivity was set to (I think this may be due to large steps in mouse movement that it treats as VERY rapid movement which in turn is affected little to nil by the Mouse speed settings).

Code:
if (KeyB == 3) {
    for(int x = 0; x < 20; x++){
      Mouse.move(-100,-100);
      delay(1);
    }
    delay(200);
    digitalWrite(13, HIGH);
    for(int x = 0; x < 5; x++){
      Mouse.move(125,79);
      delay(1);
    }
    Mouse.click();
    digitalWrite(13, LOW);
    delay(950);
    KeyA = 0;
    KeyB = 0;
    KeyC = 0;
    KeyD = 0;
  }
 
Status
Not open for further replies.
Back
Top