SavinaRoja / PyUserInput

A module for cross-platform control of the mouse and keyboard in python that is simple to install and use.
GNU General Public License v3.0
1.07k stars 244 forks source link

Function `click` does not transform argument to `int` automatically #61

Open PaleNeutron opened 9 years ago

PaleNeutron commented 9 years ago

I tried the code in readme but got error like this:

>>> x_dim, y_dim = m.screen_size()
>>> m.click(x_dim/2, y_dim/2, 1)
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    m.click(x_dim/2, y_dim/2, 1)
  File "C:\Python34\lib\site-packages\pymouse\base.py", line 56, in click
    self.press(x, y, button)
  File "C:\Python34\lib\site-packages\pymouse\windows.py", line 32, in press
    self.move(x, y)
  File "C:\Python34\lib\site-packages\pymouse\windows.py", line 70, in move
    windll.user32.SetCursorPos(x, y)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: Don't know how to convert parameter 1

This is because x_dim/2 is 960.0 not 960.

So, add a type coercions or modify the readme.

ajitjadhav28 commented 8 years ago

Facing same error in ubuntu - Traceback (most recent call last): File "Joystic.py", line 34, in myMouse.click(x_cur, y_cur, click) File "build/bdist.linux-x86_64/egg/pymouse/base.py", line 45, in click File "build/bdist.linux-x86_64/egg/pymouse/unix.py", line 34, in press File "/usr/lib/python2.7/dist-packages/Xlib/ext/xtest.py", line 100, in fake_input y = y) File "/usr/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1456, in init self._binary = self._request.to_binary(_args, *_keys) File "", line 2, in to_binary struct.error: cannot convert argument to integer

pepijndevos commented 8 years ago

I'd insta-merge a PR on https://github.com/PyUserInput/PyUserInput for such a type coercion, but I have an exam today, so I don't have the time to write and test a patch.

ajitjadhav28 commented 8 years ago

It's Ok.. Thanks for developing such a nice utility. All the best for your exam..