在jython中使用ctypes [英] Using ctypes with jython

查看:216
本文介绍了在jython中使用ctypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python脚本中使用ctypes lib时遇到麻烦.这是我的代码(可以在Internet上找到):

I have a trouble with using ctypes lib in my python script. Here is my code (found on the Internet):

if __name__ == "__main__":
    from ctypes import *
    user32 = windll.user32
    kernel32 = windll.kernel32

    class RECT(Structure):
        _fields_ = [
            ("left", c_ulong),
            ("top", c_ulong),
            ("right", c_ulong),
            ("bottom", c_ulong)];

    class GUITHREADINFO(Structure):
        _fields_ = [
        ("cbSize", c_ulong),
        ("flags", c_ulong),
        ("hwndActive", c_ulong),
        ("hwndFocus", c_ulong),
        ("hwndCapture", c_ulong),
        ("hwndMenuOwner", c_ulong),
        ("hwndMoveSize", c_ulong),
        ("hwndCaret", c_ulong),
        ("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,所以我将从项目站点下载的文件复制到

The first problem was that python couldn't find the ctypes so i copied the files downloaded from the project site to

netbeans\6.9\jython-2.5.1\Lib\

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

(yep, im using netbeans) and then it shows this error:

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

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

Just like the init file has some errors o_O Help guys! Greetings, Chris

推荐答案

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

Jython doesn't yet have full support for ctypes: http://bugs.jython.org/issue1328

您不能简单地采用为CPython编译的ctypes库,然后将其插入Jython.

You can't simply take the ctypes library compiled for CPython, and plug it into Jython.

这篇关于在jython中使用ctypes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆