使用ctypes和jython

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

我在python脚本中使用ctypes lib时遇到了麻烦.这是我的代码(在互联网上找到):

  1. if __name__ == "__main__":
  2. from ctypes import *
  3. user32 = windll.user32
  4. kernel32 = windll.kernel32
  5. class RECT(Structure):
  6. _fields_ = [
  7. ("left",c_ulong),("top",("right",("bottom",c_ulong)];
  8. class GUITHREADINFO(Structure):
  9. _fields_ = [
  10. ("cbSize",("flags",("hwndActive",("hwndFocus",("hwndCapture",("hwndMenuOwner",("hwndMoveSize",("hwndCaret",("rcCaret",RECT)
  11. ]
  12. def moveCursorInCurrentWindow(x,y):
  13. # Find the focussed window.
  14. guiThreadInfo = GUITHREADINFO(cbSize=sizeof(GUITHREADINFO))
  15. user32.GetGUIThreadInfo(0,byref(guiThreadInfo))
  16. focussedWindow = guiThreadInfo.hwndFocus
  17. # Find the screen position of the window.
  18. windowRect = RECT()
  19. user32.GetWindowRect(focussedWindow,byref(windowRect))
  20. # Finally,move the cursor relative to the window.
  21. user32.SetCursorPos(windowRect.left + x,windowRect.top + y)
  22. if __name__ == '__main__':
  23. # Quick test.
  24. moveCursorInCurrentWindow(100,100)

第一个问题是python无法找到ctypes,因此我将从项目站点下载的文件复制到

  1. netbeans\6.9\jython-2.5.1\Lib\

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

  1. > from ctypes import *
  2. > 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相关文章