鼠标运动跟踪程序与python

问题描述 投票:1回答:1

我试图在各种应用程序(如桌面或某些Web应用程序)上跟踪鼠标移动。这是为了理解和捕获用户行为(那些计算机文盲的用户,试图了解他们的行为方式和与系统的交互)。例如,如果我让这样的用户坐在桌面前离开他,我的程序应该跟踪他用鼠标做出的所有动作,我以后可以将其与系统的设计相对应。

我在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打开一个新窗口。我想要我正在处理的窗口,它跟踪鼠标移动。即使我关闭了我的编辑器,程序也应该运行。应该没有单独的屏幕。我该怎么做 ?

python pygame mouseevent mouse mousemove
1个回答
0
投票

是的,你可以在这种情况下我已经更改了你的代码,这样如果鼠标位于坐标(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()
© www.soinside.com 2019 - 2024. All rights reserved.