Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Horizontal Scroll Mouse Wheel Support #393

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions src/HID-APIs/AbsoluteMouseAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ class AbsoluteMouseAPI
inline void end(void);

inline void click(uint8_t b = MOUSE_LEFT);
inline void moveTo(int x, int y, signed char wheel = 0, signed char hWheel = 0);
inline void move(int x, int y, signed char wheel = 0, signed char hWheel = 0);
inline void moveTo(int x, int y, signed char wheel = 0);
inline void move(int x, int y, signed char wheel = 0);
inline void scroll(signed char wheel = 0, signed char hWheel = 0);
inline void press(uint8_t b = MOUSE_LEFT);
inline void release(uint8_t b = MOUSE_LEFT);
inline void releaseAll(void);
Expand Down
14 changes: 10 additions & 4 deletions src/HID-APIs/AbsoluteMouseAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void AbsoluteMouseAPI::click(uint8_t b){
moveTo(xAxis, yAxis, 0);
}

void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel, signed char hWheel){
void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel){
xAxis = x;
yAxis = y;
HID_MouseAbsoluteReport_Data_t report;
Expand All @@ -85,12 +85,18 @@ void AbsoluteMouseAPI::moveTo(int x, int y, signed char wheel, signed char hWhee
report.xAxis = ((int32_t)x + 32768) / 2;
report.yAxis = ((int32_t)y + 32768) / 2;
report.wheel = wheel;
report.hWheel = hWheel;
SendReport(&report, sizeof(report));
}

void AbsoluteMouseAPI::move(int x, int y, signed char wheel, signed char hWheel){
moveTo(qadd16(xAxis, x), qadd16(yAxis, y), wheel, hWheel);
void AbsoluteMouseAPI::move(int x, int y, signed char wheel){
moveTo(qadd16(xAxis, x), qadd16(yAxis, y), wheel);
}

void AbsoluteMouseAPI::scroll(signed char wheel, signed char hWheel){
HID_MouseAbsoluteReport_Data_t report;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this? Doesnt this set the cursor to a fixed position, maybe 0,0?

report.wheel = wheel;
report.hWheel = hWheel;
SendReport(&report, sizeof(report));
}

void AbsoluteMouseAPI::press(uint8_t b){
Expand Down
25 changes: 13 additions & 12 deletions src/HID-APIs/MouseAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,23 @@ typedef union ATTRIBUTE_PACKED {
class MouseAPI
{
public:
inline MouseAPI(void);
inline void begin(void);
inline void end(void);
inline void click(uint8_t b = MOUSE_LEFT);
inline void move(signed char x, signed char y, signed char wheel = 0, signed char hWheel = 0);
inline void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
inline void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
inline MouseAPI(void);
inline void begin(void);
inline void end(void);
inline void click(uint8_t b = MOUSE_LEFT);
inline void move(signed char x, signed char y, signed char wheel = 0);
inline void scroll(signed char wheel = 0, signed char hWheel = 0);
inline void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
inline void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
inline void releaseAll(void);
inline bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
inline bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default

// Sending is public in the base class for advanced users.
virtual void SendReport(void* data, int length) = 0;
// Sending is public in the base class for advanced users.
virtual void SendReport(void* data, int length) = 0;

protected:
uint8_t _buttons;
inline void buttons(uint8_t b);
uint8_t _buttons;
inline void buttons(uint8_t b);
};

// Implementation is inline
Expand Down
11 changes: 9 additions & 2 deletions src/HID-APIs/MouseAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ void MouseAPI::click(uint8_t b)
move(0,0,0);
}

void MouseAPI::move(signed char x, signed char y, signed char wheel, signed char hWheel)
void MouseAPI::move(signed char x, signed char y, signed char wheel)
{
HID_MouseReport_Data_t report;
report.buttons = _buttons;
report.xAxis = x;
report.yAxis = y;
report.wheel = wheel;
report.hWheel = hWheel;
SendReport(&report, sizeof(report));
}

void MouseAPI::scroll(signed char wheel, signed char hWheel)
{
HID_MouseReport_Data_t report;
report.wheel = wheel;
report.hWheel = hWheel;
SendReport(&report, sizeof(report));
}

Expand Down