Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Mouse boot protocol?

  1. #1
    Junior Member
    Join Date
    Mar 2016
    Posts
    2

    Mouse boot protocol?

    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 by justinj; 03-21-2016 at 03:47 AM. Reason: added Teensy version

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,927
    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).

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,927
    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?
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    Mar 2016
    Posts
    2
    Not sure if it breaks HID protocol, but using the current Teensyduino and editing usb_desc.c has worked for me
    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;
      }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •