pywinauto: ctypes.ArgumentError @ click_input
Windows 10.0.15063 x64 Python 3.6.2 pywinauto 0.6.3
Setup (functional):
hwnd = my_kivy_app.get_hwnd()
app = pywinauto.Application()
app.connect(handle=hwnd)
window = app.window(handle=hwnd).wrapper_object()
Exception @:
window.click_input(button='left', pressed='', coords=(100, 100), double=False, absolute=False)
Traceback (most recent call last):
File "Test_Window_Commands.py", line 114, in <module>
app.run()
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\kivy\app.py", line 828, in run
runTouchApp()
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\kivy\base.py", line 504, in runTouchApp
EventLoop.window.mainloop()
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\kivy\core\window\window_sdl2.py", line 663, in mainloop
self._mainloop()
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\kivy\core\window\window_sdl2.py", line 405, in _mainloop
EventLoop.idle()
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\kivy\base.py", line 339, in idle
Clock.tick()
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\kivy\clock.py", line 581, in tick
self._process_events()
File "kivy\_clock.pyx", line 367, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7700)
File "kivy\_clock.pyx", line 397, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7577)
File "kivy\_clock.pyx", line 395, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7498)
File "kivy\_clock.pyx", line 167, in kivy._clock.ClockEvent.tick (kivy\_clock.c:3483)
File "C:\OneDrive\_Projects\Python\dev\kivy\basic\_app.py", line 140, in _wrapped
function(*args, **kwargs)
File "Test_Window_Commands.py", line 104, in ctrl_shift_alt
app._window.click_input(button='left', pressed='', coords=(100, 100), double=False, absolute=False)
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\pywinauto\base_wrapper.py", line 667, in click_input
coords = self.client_to_screen(coords)
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\pywinauto\base_wrapper.py", line 333, in client_to_screen
rect = self.element_info.rectangle
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\pywinauto\win32_element_info.py", line 142, in rectangle
return handleprops.rectangle(self.handle)
File "C:\OneDrive\_Frameworks\Python\3\lib\site-packages\pywinauto\handleprops.py", line 200, in rectangle
win32functions.GetWindowRect(handle, ctypes.byref(rect))
ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected LP_RECT instance instead of pointer to RECT
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (14 by maintainers)
Commits related to this issue
- Try to fix #419. — committed to vasily-v-ryabov/pywinauto by vasily-v-ryabov 7 years ago
- issue #419: extend RECT from wintypes. PEP-8 typo for RECT. — committed to airelil/pywinauto by airelil 5 years ago
- issue #419: fix rectangle comparison in MenuItem.click_input — committed to airelil/pywinauto by airelil 5 years ago
- Merge pull request #730 from airelil/issue_419 issue #419: extend RECT from wintypes. PEP-8 typo for RECT. — committed to pywinauto/pywinauto by vasily-v-ryabov 5 years ago
Thank you both (@airelil, @vasily-v-ryabov ) for clarifying things. I suppose you won’t reject any potential (ctypes related) PRs, that I might submit when I’ll have the time.
(worked around by
win32gui.GetWindowRect
) was because both modules had their own RECT (in terms of) definition, and prototype specified one but the other was passed. I think if both classes would have extendedwintypes.RECT
(without redefining _fields_, of course), andwindll.user32.GetWindowRect
’s last argtype would have beenPOINTER(wintypes.RECT)
, both could have worked with ctypesis a bug on Kivy’s side: [GitHub]: kivy/kivy - SetWindowLongPtrW ctypes prototype bug
I’m getting back to the old issues and I could reproduce the original issue with GetWindowRect. The fix is here (in master branch already, just verified it): https://github.com/pywinauto/pywinauto/commit/3a24b360220515f0e84b69af8962096bb28bccac#diff-a0da689e9deac595ceaf85dd5d6e8fa1
@Enteleform if it’s still relevant, do you have any more pywinauto issues related to this project?
Tried it, and the same issue occurs.
That seems like it should work. I managed to get the same functionality working in Kivy without any issues using:
win32gui.GetWindowRect
and/or theGetWindowRect
method ofpywin32
’sPyCWnd
objectuser32 = ctypes.WinDLL('user32', use_last_error=True)
user32.mouse_event
Maybe creating a
user32
instance withctypes.WinDLL
instead of usingctypes.windll.user32
will help?Yes.
Yes, here’s an MVCE: