2021-04-09 23:53:32

Hello, So I'm wanting to add mouse support to a thing I'm working on, My question is, How do pygame.mouse work? I checked the documentation, But I'm... Confused, I never worked with a mouse before so I'm not sure what to do, How do I check if for example, Someone swiped the mouse to the left? Up? Down? I know it'll be something with x y positioning probably, But Again, I'm not sure what to do exactly.

2021-04-09 23:58:38

You probably have to implement this yourself by remembering where the mouse used to be every tick and figuring it out by comparing the coordinates. E.g. "the mouse moved 10 units left since the last tick" means swipe left, or whatever.  Pretty sure pygame just gives you coords and stuff, not higher level pieces.  in fact I don't offhand know of anything that does higher level pieces, because mouse gestures are one of those things that's terribly unergonomic and not something even sighted people really want to deal with in the common case.

My Blog
Twitter: @ajhicks1992

2021-04-10 02:14:05

A quick Google yields thos link, I'd recommend checking the top accepted answer. For a quick and dirty reference, here you go.

#In your main loop...
events = pygame.event.get()
for event in events:
    if event.type == pygame.MOUSEBUTTONUP:
        pos = pygame.mouse.get_pos()
        # Do stuff with pos

There are other ways of doing this, naturally, the good old mouse.get_pressed or whatever it's called (sorry I haven't done pygame in a while), but this should get you started.

2021-04-10 04:14:19

Yeah, and to fill in the blanks a bit more...don't try to code up some complex logic for every single swipe. Start with one--left or right. Using the above pointers, take the mouse position, only detect that one swipe, and make TTS say something like "Swipe right detected" whenever you make that one gesture. And then do it again and again and again, until it is detected way more often than not. Then move onto another. I'm hoping you have TTS working, because you'll need something to quickly tell you what's going on in your world. Console debugging may not be quick enough. smile That's how I did it for godot-accessibility. Started by trying to detect everything, then realized I was overwhelmed because I had no idea how many pixels made sense, and I was getting false positives in all the wrong directions at once.

Anyhow, start simple. The swipes have to feel natural, and the only way to know if they do is to add them one at a time.