我在我的python腳本中使用ctypes lib時遇到了麻煩。這裏是我的代碼(在互聯網上找到):在jython中使用ctypes
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)
的第一個問題是,蟒蛇找不到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 <module>
> from _ctypes import Union, Structure, Array
就像init文件有一些錯誤O_O幫助傢伙! 問候,克里斯
並且錯誤是? – user470379 2011-03-03 21:22:01