diff --git a/docs/reST/ref/event.rst b/docs/reST/ref/event.rst index 86d81e3e64..65ac71244b 100644 --- a/docs/reST/ref/event.rst +++ b/docs/reST/ref/event.rst @@ -74,9 +74,9 @@ specific attributes. ACTIVEEVENT gain, state KEYDOWN key, mod, unicode, scancode KEYUP key, mod, unicode, scancode - MOUSEMOTION pos, rel, buttons, instance_id - MOUSEBUTTONUP pos, button, instance_id - MOUSEBUTTONDOWN pos, button, instance_id + MOUSEMOTION pos, rel, buttons, touch + MOUSEBUTTONUP pos, button, touch + MOUSEBUTTONDOWN pos, button, touch JOYAXISMOTION joy (deprecated), instance_id, axis, value JOYBALLMOTION joy (deprecated), instance_id, ball, rel JOYHATMOTION joy (deprecated), instance_id, hat, value @@ -90,8 +90,8 @@ specific attributes. .. versionchanged:: 2.0.1 The ``unicode`` attribute was added to ``KEYUP`` event. -.. versionchanged:: 2.0.2 The ``instance_id`` attribute was added to ``MOUSEMOTION`` event: ``instance_id may be SDL_TOUCH_MOUSEID(-1), for events that were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent``, see `SDL MouseMotionEvent `__. -.. versionchanged:: 2.0.2 The ``instance_id`` attribute was added to ``MOUSEBUTTONUP``, ``MOUSEBUTTONDOWN`` events: ``instance_id may be SDL_TOUCH_MOUSEID(-1), for events that were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent``, see `SDL MouseButtonEvent `__. +.. versionchanged:: 2.0.2 The ``touch`` attribute was added to ``MOUSEMOTION`` event: indicates if the events were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent, see `SDL MouseMotionEvent `__. +.. versionchanged:: 2.0.2 The ``touch`` attribute was added to ``MOUSEBUTTONUP``, ``MOUSEBUTTONDOWN`` events: indicates if the events were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent``, see `SDL MouseButtonEvent `__. You can also find a list of constants for keyboard keys :ref:`here `. @@ -121,14 +121,14 @@ attributes. FINGERMOTION touch_id, finger_id, x, y, dx, dy FINGERDOWN touch_id, finger_id, x, y, dx, dy FINGERUP touch_id, finger_id, x, y, dx, dy - MOUSEWHEEL which, flipped, x, y, instance_id + MOUSEWHEEL which, flipped, x, y, touch MULTIGESTURE touch_id, x, y, pinched, rotated, num_fingers TEXTEDITING text, start, length TEXTINPUT text .. versionadded:: 1.9.5 -.. versionadded:: 2.0.2 The ``instance_id`` attribute was added to ``MOUSEWHEEL`` event, fixed amount horizontal scroll (x, positive to the right and negative to the left). +.. versionadded:: 2.0.2 The ``touch`` attribute was added to ``MOUSEWHEEL`` event, indicates if the events were generated by a touch input device, and not a real mouse. You might want to ignore such events, if your application already handles SDL_TouchFingerEvent. Fixed amount horizontal scroll (x, positive to the right and negative to the left). | diff --git a/src_c/event.c b/src_c/event.c index 28bd3d8b88..10bf6e00c5 100644 --- a/src_c/event.c +++ b/src_c/event.c @@ -1107,7 +1107,6 @@ dict_from_event(SDL_Event *event) _pg_insobj(dict, "scancode", PyInt_FromLong(event->key.keysym.scancode)); break; case SDL_MOUSEMOTION: - _pg_insobj(dict, "instance_id", PyLong_FromLong(event->motion.which)); // The mouse instance id, or SDL_TOUCH_MOUSEID obj = Py_BuildValue("(ii)", event->motion.x, event->motion.y); _pg_insobj(dict, "pos", obj); obj = @@ -1125,13 +1124,18 @@ dict_from_event(SDL_Event *event) SDL_BUTTON(3)) != 0)); _pg_insobj(dict, "buttons", tuple); } + _pg_insobj( + dict, "touch", + PyBool_FromLong((event->motion.which == SDL_TOUCH_MOUSEID))); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: - _pg_insobj(dict, "instance_id", PyLong_FromLong(event->button.which)); // The mouse instance id, or SDL_TOUCH_MOUSEID obj = Py_BuildValue("(ii)", event->button.x, event->button.y); _pg_insobj(dict, "pos", obj); _pg_insobj(dict, "button", PyInt_FromLong(event->button.button)); + _pg_insobj( + dict, "touch", + PyBool_FromLong((event->button.which == SDL_TOUCH_MOUSEID))); break; case SDL_JOYAXISMOTION: _pg_insobj(dict, "joy", _joy_map_instance(event->jaxis.which)); @@ -1213,7 +1217,8 @@ dict_from_event(SDL_Event *event) #endif _pg_insobj(dict, "y", PyInt_FromLong(event->wheel.y)); _pg_insobj(dict, "x", PyInt_FromLong(event->wheel.x)); - _pg_insobj(dict, "which", PyInt_FromLong(event->wheel.which)); // The mouse instance id, or SDL_TOUCH_MOUSEID + _pg_insobj(dict, "touch", PyBool_FromLong((event->wheel.which == SDL_TOUCH_MOUSEID))); + break; case SDL_TEXTINPUT: /* https://wiki.libsdl.org/SDL_TextInputEvent */