【发布时间】:2018-04-19 18:17:39
【问题描述】:
我的目标是从使用 Ctypes 的 Python 3.6 中运行的 Windows 获取 magnification.dll。我可以缩放屏幕,但无法转换输入。 我希望有人知道如何解决这个问题并可以向我解释我做错了什么。谢谢。 (Magnification API (Windows))
附:您可能需要手动关闭 python 进程,因为缩放不会停止。 (至少在 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)
【问题讨论】:
标签: windows python-3.x dll ctypes