my goal is to get the magnification.dll from Windows running in Python 3.6 with Ctypes. I'm able to zoom the screen, but I can't get the transformation of the input working. I hope someone knows how to fix this and can explain me, what I did wrong. Thanks. ( Magnification API (Windows) )
P.s. It can happen that you need to close the python process manually because zooming won't stop. (At least in Visual Studio Code)
magnification_api.py
import ctypes
class RECT(ctypes.Structure):
_fields_ = [("left", ctypes.c_long),
("top", ctypes.c_long),
("right", ctypes.c_long),
("bottom", ctypes.c_long)]
class Magnification:
def __init__(self):
self.dll = ctypes.CDLL("magnification.dll")
BOOL = ctypes.c_bool
FLOAT = ctypes.c_float
INT = ctypes.c_int
self.LPRECT = LPRECT = ctypes.POINTER(RECT)
self.PBOOL = PBOOL = ctypes.POINTER(ctypes.c_bool)
# MagInitialize
self.dll.MagInitialize.restype = BOOL
# MagUninitialize
self.dll.MagUninitialize.restype = BOOL
# MagSetFullscreenTransform
self.dll.MagSetFullscreenTransform.restype = BOOL
self.dll.MagSetFullscreenTransform.argtypes = (FLOAT, INT, INT)
# MagGetInputTransform
self.dll.MagGetInputTransform.restype = BOOL
self.dll.MagGetInputTransform.argtypes = (PBOOL, LPRECT, LPRECT)
def MagInitialize(self):
return self.dll.MagInitialize()
def MagUninitialize(self):
return self.dll.MagUninitialize()
def MagSetFullscreenTransform(self, magLevel, xOffset, yOffset):
return self.dll.MagSetFullscreenTransform(magLevel, xOffset, yOffset)
def MagGetInputTransform(self, pfEnabled, prcSource, prcDest):
return self.dll.MagGetInputTransform(pfEnabled, prcSource, prcDest)
zoomer.py
import ctypes
from magnification_api import Magnification
import time
class Main:
def __init__(self):
self.mag = Magnification()
def zoom(self, factor, x, y):
if factor > 1.0:
while True:
if self.mag.MagInitialize():
result = self.mag.MagSetFullscreenTransform(factor, 0, 0)
if result:
fInputTransformEnabled = self.mag.PBOOL()
rcInputTransformSource = self.mag.LPRECT()
rcInputTransformDest = self.mag.LPRECT()
if self.mag.MagGetInputTransform(fInputTransformEnabled, rcInputTransformSource, rcInputTransformDest):
# fails here
print("Success")
else:
print("Failed")
time.sleep(1)
if __name__ == "__main__":
m = Main()
m.zoom(1.05, 0, 0)