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)
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\
(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
Just like the init file has some errors o_O Help guys! Greetings, Chris