import os,time
import pyautogui as pag
from ctypes import * # 获取屏幕上某个坐标
dx = 0
dy = 0
def color(x, y):
gdi32 = windll.gdi32
user32 = windll.user32
hdc = user32.GetDC(None) # 获取颜色值
pixel = gdi32.GetPixel(hdc, x, y) # 提取RGB值
r = pixel & 0x0000ff
g = (pixel & 0x00ff00) >> 8
b = pixel >> 16
return [r, g, b]
while True:
try:
x,y = pag.position()
if dx!= x and dy != y:
print(color(x,y))
dx,dy = x,y
except:
pass
关于pyautogui的安装 pip install pyautogui
屏幕颜色值实时读取
本文介绍了一种使用Python和ctypes库实时读取屏幕指定坐标颜色值的方法,通过调用Windows API函数GetPixel实现。代码同时利用了pyautogui库获取鼠标位置,实现了鼠标移动时屏幕颜色的实时更新显示。
2389

被折叠的 条评论
为什么被折叠?



