加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

使用ctypes和jython

发布时间:2020-12-16 22:42:10 所属栏目:Python 来源:网络整理
导读:我在python脚本中使用ctypes lib时遇到了麻烦.这是我的代码(在互联网上找到): if __name__ == "__main__": from ctypes import * user32 = windll.user32 kernel32 = windll.kernel32 class RECT(Structure): _fields_ = [ ("left",c_ulong),("top",("right

我在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,因此我将从项目站点下载的文件复制到

netbeans6.9jython-2.5.1Lib

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

>    from ctypes import *
>  File "C:Usersk.netbeans6.9jython-2.5.1Libctypes__init__.py",line 10,in 

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读