[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Low-level read input (mouse, HID devices)



Wow that works! Thanks a lot, you made my day. It is however not truely low-level, since the values depend on my loop frequency, but anyway solves my tasks at 100%. And yes the trick is not obvious at ALL. It is very good reason to add this info to pygame official documentation since its a very common task.  

On Friday, January 16, 2015 at 12:26:18 AM UTC+1, Weeble wrote:
It is possible, just not entirely obvious. I believe you need to:

1. Grab mouse focus with pygame.event.set_grab()
2. Hide the mouse cursor with pygame.mouse.set_visible()
3. Read mouse events, taking the rel.x and rel.y properties to find
the relative mouse motion.

Make sure to have a way to release the grab, otherwise your app will
be difficult to get out of!

I haven't tried this lately, but I'm sure I've done it in the past.
Here's the documentation for SDL, which Pygame is built on top of, and
which describes the mouse motion events in a bit more detail:
http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlmousemotionevent.html

On 15 January 2015 at 23:05, Mikhail V <mikha...@xxxxxxxxx> wrote:
> Hello pygame devs and users,
>
> I have a simple task - I want to read input from the mouse - NOT the cursor
> position inside my window, but the actual input data from the device.
> So currently I suppose it is not possible with Pygame. Is there a possiblity
> to add such capabilities to Pygame? I know that depends on the device type
> and connection so it is impossible to implement tools for all devices. But
> having tools to read low-level input at least for the mouse is absolutely a
> must for developing interactive applications.
>
> If there is no chance with pygame then what would you recommend, say,  for
> Windows and C/C++ to read from the mouse at low level?
>
> Mikhail
>
>