Question

I am creating a simple side-scrolling space game for a presentation I will be giving at my school. I decided i should learn how to use joystick inputs as a challenge. It's really cool and almost done, but i noticed that while I'm playing, if I don't move the mouse every now and then, the monitor dims and looks like it's about to go into power save. Is there any way I can avoid this?

Was it helpful?

Solution

import pygame
x,y = pygame.mouse.get_pos()
pygame.mouse.set_pos([x+1,y+1])
pygame.mouse.set_pos([x,y])

It's not the neatest solution, but this will simulate a mouse movement. There's probably API's you can call or use of Pythons signal library. But depending on your platform the solution might vary quite a lot.

Or if you need to move the cursor when the window is not active?

import win32api, win32con
def move(x,y,press=False):
    win32api.SetCursorPos((x,y))
    if press:
        click(x,y)
def click(x,y):
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
move(10,10,True)

OTHER TIPS

pygame.event.pump()

I am going to guess that you getting joystick inputs from the pygame.joystick and not from pygame.event. If so, you maybe able to stop the computer from beginning to sleep by calling pygame.event.pump().

This should be called if no other pygame.event function is called, so background these can happen, and the system does not mistake the processed for non-responsive. pygame.event.get() would also be a working solution, if you also wanted events.

I tested this on OSX (10.13.3), but I know that pump() acts differently on different operating systems, so your results may vary (please comment).

It is also worth noting that the pygame.mouse.set_pos() did not work for me as it seems to do nothing on MacOS at the moment (pygame: 1.9.4.dev0).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top