我在python脚本中使用ctypes lib时遇到了麻烦.这是我的代码(在互联网上找到):
if __name__ == "__main__":
from ctypes import *
user32 = windll.user32
kernel32 = windll.kernel32
class RECT(Structure):
_fields_ = [
("left",c_ulong),("top",("right",("bottom",c_ulong)];
class GUITHREADINFO(Structure):
_fields_ = [
("cbSize",("flags",("hwndActive",("hwndFocus",("hwndCapture",("hwndMenuOwner",("hwndMoveSize",("hwndCaret",("rcCaret",RECT)
]
def moveCursorInCurrentWindow(x,y):
# Find the focussed window.
guiThreadInfo = GUITHREADINFO(cbSize=sizeof(GUITHREADINFO))
user32.GetGUIThreadInfo(0,byref(guiThreadInfo))
focussedWindow = guiThreadInfo.hwndFocus
# Find the screen position of the window.
windowRect = RECT()
user32.GetWindowRect(focussedWindow,byref(windowRect))
# Finally,move the cursor relative to the window.
user32.SetCursorPos(windowRect.left + x,windowRect.top + y)
if __name__ == '__main__':
# Quick test.
moveCursorInCurrentWindow(100,100)
第一个问题是python无法找到ctypes,因此我将从项目站点下载的文件复制到
netbeans\6.9\jython-2.5.1\Lib\
> from ctypes import *
> File "C:\Users\k\.netbeans\6.9\jython-2.5.1\Lib\ctypes\__init__.py",line 10,in
最佳答案
原文链接:https://www.f2er.com/python/438702.html