Skip to content

Commit

Permalink
fix: mouse_data should be able to handle negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Jul 2, 2024
1 parent 235f5c5 commit 4fc1f13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions keywin/send_input/send_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ static PyObject* send_mouse_event(PyObject* self, PyObject* args) {

int x_overflow = 0;
int y_overflow = 0;
int mouse_data_overflow = 0;

for (UINT i = 0; i < number_of_events; i++) {
PyObject* mouse_event = PyTuple_GetItem(mouse_event_list, i);
const LONG x = PyLong_AsLongAndOverflow(PyTuple_GetItem(mouse_event, 0), &x_overflow);
const LONG y = PyLong_AsLongAndOverflow(PyTuple_GetItem(mouse_event, 1), &y_overflow);
const DWORD mouse_data = PyLong_AsUnsignedLong(PyTuple_GetItem(mouse_event, 2));
const DWORD mouse_data = PyLong_AsLongAndOverflow(PyTuple_GetItem(mouse_event, 2), &mouse_data_overflow);
const DWORD flags = PyLong_AsUnsignedLong(PyTuple_GetItem(mouse_event, 3));

if (x_overflow || y_overflow) {
if (x_overflow || y_overflow || mouse_data_overflow) {
return dispose_and_fail(inputs);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/test_keywin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ def test_mouse_helpers():
assert xbutton2_press()
assert xbutton2_release()
assert scroll(0)
assert scroll(-1)
assert scroll_horizontal(0)
assert scroll_horizontal(-1)
assert move(0, 0)
assert move_relative(0, 0)
assert not move(0xFFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFFF)
assert not move_relative(0xFFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFFF)
assert not scroll(0xFFFFFFFFFFFFFFFFF)
assert not scroll_horizontal(0xFFFFFFFFFFFFFFFFF)

0 comments on commit 4fc1f13

Please sign in to comment.