如何使用Python中的Windows倍率API来反转屏幕?

How do I use the Windows Magnification API in Python to invert the screen?

在 Python 中,如何使用 ctypes 模块在 Windows PC 上反转整个屏幕而不使用键盘快捷键(因为这些快捷键不可靠并且可以轻松关闭)?

我注意到可以使用 Windows Magnification API,但它是为 C 设计的。使用 ctypes,我可以与 DLL 交互,并反转屏幕。我可以初始化它:

from ctypes import *

class RECT(Structure):
    _fields_ = [('left', c_long),
                ('top', c_long),
                ('right', c_long),
                ('bottom', c_long)]
magnification_api = CDLL('magnification.dll')

# declare types
BOOL = c_bool
FLOAT = c_float
INT = c_int
LPRECT = LPRECT = POINTER(RECT)
PBOOL = PBOOL = POINTER(c_bool)

# MagInitialize
magnification_api.MagInitialize.restype = BOOL

# MagUninitialize 
magnification_api.MagUninitialize.restype = BOOL

magnification_api.MagInitialize() # initialize the API

magnification_api.MagUninitialize() # uninitialize

如何使用API反转屏幕?

您可以通过 ctypes 库使用 Windows 放大率 API:

from ctypes import *

class RECT(Structure):
    _fields_ = [('left', c_long),
                ('top', c_long),
                ('right', c_long),
                ('bottom', c_long)]
magnification_api = CDLL('magnification.dll')

# declare types
BOOL = c_bool
FLOAT = c_float
INT = c_int
LPRECT = LPRECT = POINTER(RECT)
PBOOL = PBOOL = POINTER(c_bool)
PMAGCOLOREFFECT = c_float * 25
MAGCOLOREFFECT = MAGCOLOREFFECT = POINTER(PMAGCOLOREFFECT)

# MagInitialize
magnification_api.MagInitialize.restype = BOOL

# MagUninitialize 
magnification_api.MagUninitialize.restype = BOOL

# MagSetFullscreenColorEffect
magnification_api.MagSetFullscreenColorEffect.restype = BOOL
magnification_api.MagSetFullscreenColorEffect.argtypes = (MAGCOLOREFFECT,)

magnification_api.MagInitialize() # initialize the API

magnification_api.MagSetFullscreenColorEffect((c_float * 25)(-1, 0, 0, 0, 0, 0, -1, 0, 0,  0, 0,  0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1)) # invert the screen

magnification_api.MagUninitialize() # use this to reset