Skip to content

Instantly share code, notes, and snippets.

@pbsds
Created September 18, 2014 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbsds/d07fdc374febf51e04aa to your computer and use it in GitHub Desktop.
Save pbsds/d07fdc374febf51e04aa to your computer and use it in GitHub Desktop.
This is something i made quick to get a feel of how a monitor with a certain input lag would feel like.
import pygame
pygame.init()
pygame.display.set_caption("Mouse Latency Simulator - by pbsds")
pygame.font.init()
window = pygame.display.set_mode((1280, 720))
font = pygame.font.Font(None, 20)
pygame.mouse.set_visible(False)
delayedMouse = []
latency = 40#ms
latency_Spr = font.render("%ims latency" % latency, False, (255, 255, 255))
mouse = [0, 0]
while 1:
tick = pygame.time.get_ticks()
update = False
events = pygame.event.get()
for i in events:
if i.type == pygame.MOUSEMOTION:
delayedMouse.append((tick + latency, i.pos))
elif i.type == pygame.MOUSEBUTTONDOWN:
if i.button == 4:
latency += 1
elif i.button == 5:
if latency >= 1: latency -= 1
else: continue
latency_Spr = font.render("%ims latency" % latency, False, (255, 255, 255))
update = True
elif i.type == pygame.QUIT:
sys.exit()
while len(delayedMouse):
if delayedMouse[0][0] < tick:
mouse = delayedMouse.pop(0)[1]
update = True
else:
break
if update:
window.fill((0, 0, 0))
window.blit(latency_Spr, (0, 0))
pygame.draw.rect(window, (255, 255, 255), (mouse[0], mouse[1], 10, 10))
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment