1

I'm using the Mouse library with an ATmega32U4 connected to Linux via USB.

I would like to issue horizontal scroll commands, but the Mouse.move() function only seems to accept X movement, Y movement and vertical scroll parameters.

How can I send horizontal scroll commands from the Arduino to the computer?

  • 3
    You need to rewrite the core to provide buttons 6 and 7. – Ignacio Vazquez-Abrams Oct 30 '17 at 12:18
  • You could combine it with Keyboard to use the Ctrl and Shift keys for other scroll options. – Majenko Oct 30 '17 at 13:03
2

As suggested in the comments, I edited the core libraries to achieve this.

I'm using PlatformIO, so the library files I needed to edit were here:

~/.platformio/packages/framework-arduinoavr/libraries/Mouse/src/

And the required changes (to change a wheel parameter for horizontal (h) and vertical (v) scroll parameters were as follows:

Mouse.h

Change the declaration of move():

...
void move(signed char x, signed char y, signed char h = 0, signed char v = 0); 
...

Mouse.cpp

Add the following to the report descriptor after the last INPUT message:

...
0x05, 0x0c,        //       USAGE PAGE (Consumer Devices)
0x0a, 0x38, 0x02,  //       USAGE (AC Pan)
0x15, 0x81,        //       LOGICAL_MINIMUM (-127)
0x25, 0x7f,        //       LOGICAL_MAXIMUM (127)
0x75, 0x08,        //       REPORT_SIZE (8)
0x95, 0x01,        //       REPORT_COUNT (1)
0x81, 0x06,        //       INPUT (Data, Var, Rel)
...

Change the definition of move():

void Mouse_::move(signed char x, signed char y, signed char h, signed char v)
{
    uint8_t m[5];
    m[0] = _buttons;
    m[1] = x;
    m[2] = y;
    m[3] = v;
    m[4] = h;
    HID().SendReport(1, m, 5);
}

The following terminal commands were also useful in testing these changes:

# List input devices
xinput --list

# List device capabilities
xinput --list <device-id>

# Watch for data sent from the device
watch -n 0.1 xinput query-state <device-id>
  • The NicoHood/HID library github.com/NicoHood/HID has a lot for keyboards (media keys and so on), but not everything for mice. I don't know if horizontal scrolling is somewhere in there. – Jot Oct 30 '17 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.