使用ctypes和jython

前端之家收集整理的这篇文章主要介绍了使用ctypes和jython前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在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\

(是的,即时通讯使用netbeans)然后它显示错误

>    from ctypes import *
>  File "C:\Users\k\.netbeans\6.9\jython-2.5.1\Lib\ctypes\__init__.py",line 10,in 

就像init文件有一些错误o_O帮助人!
问候,克里斯

最佳答案
Jython尚未完全支持ctypes:http://bugs.jython.org/issue1328

你不能简单地为CPython编译ctypes库,并将其插入Jython.

猜你在找的Python相关文章