我正在尝试跟踪各种应用程序(如桌面或某些 Web 应用程序)上的鼠标运动。这是为了了解和捕获用户行为(那些不懂计算机的用户,试图了解他们的行为方式以及与系统的交互方式)。例如,如果我让这样的用户坐在桌面前并离开他,我的程序应该跟踪他用鼠标所做的所有 Action ,我可以稍后将其与系统的设计相对应。
我在 pygame 中写了一个小程序来做同样的事情。
import pygame
x = y = 0
running = 1
screen = pygame.display.set_mode((640, 400))
while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
elif event.type == pygame.MOUSEMOTION:
print "mouse at (%d, %d)" % event.pos
screen.fill((0, 0, 0))
pygame.display.flip()
我想更改“screen = pygame.display.set_mode((640, 400))”。我不希望 pygame 打开一个新窗口。我想要我正在处理的同一个窗口,它跟踪鼠标的移动。即使我关闭我的编辑器,程序也应该运行。应该没有单独的屏幕。我该怎么做?
最佳答案
是的,在这种情况下,我已经更改了您的代码,如果鼠标位于坐标 (300,200),则它会将屏幕尺寸更改为 (400, 500)
附注看看我在开头添加的内容:
import pygame
from pygame.locals import * #just so that some extra functions work
pygame.init() #this turns pygame 'on'
x = y = 0
running = 1
screen = pygame.display.set_mode((640, 400))
while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
elif event.type == pygame.MOUSEMOTION:
print "mouse at (%d, %d)" % event.pos
if event.pos == (300,200):
screen = pygame.display.set_mode((400, 500))
screen.fill((0, 0, 0))
pygame.display.flip()
https://stackoverflow.com/questions/23535497/