I want to calculate the time of user mouse events in Pygame, if the user does not move the mouse for about 15 seconds, then I want to display the text on the screen. I tried the time module for this, but it does not work.
import pygame,time pygame.init() #codes ... ... font = pygame.font.SysFont(None,25) text = font.render("Move your mouse!", True, red) FPS = 30 while True: #codes ... ... start = time.time() cur = pygame.mouse.get_pos() #catching mouse event end = time.time() diff = end-start if 15 < diff: gameDisplay.blit(text,(10,500)) pygame.display.update() clock.tick(FPS) pygame.quit() quit()
The output of the output is not what I want, I donβt know how to calculate it if the user does not move the mouse.
If I want to write text when the user mouse is in a special area, it works like:
if 100 < cur[0] < 200 and 100 < cur[1] < 200: gameDisplay.blit(text,(10,500))
But how can I calculate? I could not even find how to say Python, the user mouse is in the same coordinates or not. Then I can say that if the changes in the coordinates of the mouse begin the timer, and if it is more than 15, print the text.
Edit: You can assume this in normal Python without the Pygame module, suppose you have a function that captures mouse events, and then how to tell Python if the coordinates of the mouse do not change, start the timer, if the time is more than 15 seconds, print the text then update the timer.
user4435153
source share