Created
September 18, 2014 21:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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