pygame.mouse--鼠标

pygame.mouse函数

pygame.mouse.get_pressed()  ——  获取鼠标按键的情况(是否被按下)

复制代码
import pygame

pygame.init()
screen = pygame.display.set_mode((196, 100))
pygame.display.set_caption("pygame.mouse函数")

while True:
    event=pygame.event.wait()
    if event.type == pygame.QUIT:
        exit()
    b=pygame.mouse.get_pressed()   #获取鼠标按键的情况(是否被按下)
    #返回一个由布尔值组成的列表,代表所有鼠标按键被按下的情况。True意味着在调用此方法时该鼠标按键正被按下
    #(1, 0, 1)  表示左键和右键被按下(左键、中键、右键)
    #这条语句没有体现滚轮的滚动
  #必须先调用pygame.event.wait等语句后才能工作
print(b) pygame.display.update()
复制代码

 

pygame.mouse.get_pos()  ——  获取鼠标光标的位置

复制代码
import pygame

pygame.init()
screen = pygame.display.set_mode((196, 100))
pygame.display.set_caption("pygame.mouse函数")

while True:
    event=pygame.event.wait()
    if event.type == pygame.QUIT:
        exit()
    b=pygame.mouse.get_pos()   #获取鼠标光标的位置
    #返回鼠标光标的坐标 (x, y)。这个坐标以窗口左上角为基准点
    #必须先调用pygame.event.wait等语句后才能准确获取

    print(b)

    pygame.display.update()
复制代码

 

pygame.mouse.get_rel()  ——  获取鼠标与前一位置的偏移量

pygame.mouse.set_pos()  ——  设置鼠标光标的位置

复制代码
import pygame

pygame.init()
screen = pygame.display.set_mode((196, 100))
pygame.display.set_caption("pygame.mouse函数")

while True:
    event=pygame.event.wait()
    if event.type == pygame.QUIT:
        exit()
    pygame.mouse.set_pos(50,10)   #设置鼠标光标的位置
    #如果鼠标光标是可视的,则光标将会跳到新的坐标上。移动鼠标将会产生一个新的 pygame.MOUSEMOTION 事件

    print('a')

    pygame.display.update()
复制代码

 

pygame.mouse.set_visible()  ——  隐藏或显示鼠标光标

b=pygame.mouse.set_visible(False)  #设置鼠标是否可见
#True 可见,False 不可见
#返回值:返回在设置之前的状态

 

pygame.mouse.get_focused()  ——  检查程序界面是否获得鼠标焦点

b=pygame.mouse.get_focused()  #pygame窗口是否在接收鼠标事件
    #当 pygame 正在接受鼠标输入事件(或者用专业术语说,鼠标正在处于“active”或“focus”状态)返回值为 True

 

pygame.mouse.set_cursor()  ——  设置鼠标光标在程序内的显示图像

pygame.mouse.get_cursor()  ——  获取鼠标光标在程序内的显示图像

b=pygame.mouse.get_cursor()  #获取鼠标光标在程序内的显示图像
#((16, 16), (0, 0), (0, 0, 64, 0, 96, 0, 112, 0, 120, 0, 124, 0, 126, 0, 127, 0, 127, 128, 124, 0, 108, 0, 70, 0, 6, 0, 3, 0, 3, 0, 0, 0), (192, 0, 224, 0, 240, 0, 248, 0, 252, 0, 254, 0, 255, 0, 255, 128, 255, 192, 255, 224, 254, 0, 239, 0, 207, 0, 135, 128, 7, 128, 3, 0))

 

 

 

 

posted @   天子骄龙  阅读(1512)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示

目录导航