Skip to content Skip to sidebar Skip to footer

How Do I Use The Windows Magnification Api In Python To Invert The Screen?

In Python, how can you invert the entire screen on a Windows PC without using keyboard shortcuts (as these are unreliable and can be turned off easily) using the ctypes module? I'v

Solution 1:

You can use the Windows Magnification API through the ctypes library:

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

Post a Comment for "How Do I Use The Windows Magnification Api In Python To Invert The Screen?"