Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

How to do a double-click? #66

Open
gitfoxi opened this issue Mar 21, 2015 · 7 comments
Open

How to do a double-click? #66

gitfoxi opened this issue Mar 21, 2015 · 7 comments

Comments

@gitfoxi
Copy link

gitfoxi commented Mar 21, 2015

mouse.click works great. But i can't figure out how to do a double-click. I've tried various ways. I'm on the mac platform.

            for _ in range(times):
                print "calling mouseclick"
                mouse.toggle(True, button)
                # sleep(0.1)
                mouse.toggle(False, button)
                # sleep(0.1)

For example, this doesn't work with or without the sleep calls.

I'd also be interested in being able to click and hold to drag a window for example.

If you want to try dragging then you might try something like mouse.toggle(True) and then later mouse.toggle(False). This does not have the effect of dragging the window smoothly. The window does jump from where it was to Where the mouse is when you you called the second toggle.

@potpath
Copy link

potpath commented Mar 21, 2015

For double-click, see my fork at https://github.com/potpath/autopy.

I ported double-click code from cliclick at https://github.com/BlueM/cliclick/blob/master/Actions/DoubleclickAction.m.

@gitfoxi
Copy link
Author

gitfoxi commented Mar 21, 2015

Thanks. Is your code cross-platform or does it only work on the Mac?

On Sat, Mar 21, 2015 at 8:45 AM, potpath notifications@github.com wrote:

For double-click, see my fork at https://github.com/potpath/autopy.

I ported double-click code from cliclick at
https://github.com/BlueM/cliclick/blob/master/Actions/DoubleclickAction.m.


Reply to this email directly or view it on GitHub
#66 (comment).

Michael

@gitfoxi
Copy link
Author

gitfoxi commented Mar 22, 2015

Your patch works for me. There were a couple lines you had to change to keep clang happy. I had to switch them back for the same reason. We're probably using different versions of some library.

diff --git a/src/autopy-key-module.c b/src/autopy-key-module.c
index b115321..99ec938 100644
--- a/src/autopy-key-module.c
+++ b/src/autopy-key-module.c
@@ -76,7 +76,7 @@ PyMODINIT_FUNC initkey(void)
                                       "autopy module for working with the "
                                       "keyboard");
 #endif
-       if (mod == NULL) return NULL; /* Error */
+       if (mod == NULL) return ; /* Error */

        /* Needed for type_string(). */
        deadbeef_srand_time();
@@ -117,7 +117,7 @@ PyMODINIT_FUNC initkey(void)
                PyModule_AddIntMacro(mod, K_SHIFT) < 0 ||
                PyModule_AddIntMacro(mod, K_CAPSLOCK) < 0) {
                PyErr_SetString(PyExc_ValueError, "Error adding keycode constant
-               return NULL;
+               return ;
        }
 #ifdef PYTHREE
        return mod;
diff --git a/src/autopy-mouse-module.c b/src/autopy-mouse-module.c
index 021be2a..4a1944e 100644
--- a/src/autopy-mouse-module.c
+++ b/src/autopy-mouse-module.c
@@ -85,14 +85,14 @@ PyMODINIT_FUNC initmouse(void)
        mod = Py_InitModule3("mouse", MouseMethods,
                                       "autopy module for working with the mouse
 #endif
-       if (mod == NULL) return NULL; /* Error */
+       if (mod == NULL) return ; /* Error */

        /* Add mouse button constants for click_mouse(). */
        if (PyModule_AddIntMacro(mod, LEFT_BUTTON) < 0 ||
                PyModule_AddIntMacro(mod, RIGHT_BUTTON) < 0 ||
                PyModule_AddIntMacro(mod, CENTER_BUTTON) < 0) {
                PyErr_SetString(PyExc_ValueError, "Error adding constants to mou
-               return NULL;
+               return ;
        }

        deadbeef_srand_time();

@gitfoxi
Copy link
Author

gitfoxi commented Mar 22, 2015

I think it might be the Python version. I'm using this one, installed by homebrew:

Python 2.7.8 (default, Oct 24 2014, 11:16:42)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin

@potpath
Copy link

potpath commented Mar 22, 2015

I haven't tested it on any platform other than Mac, but I think it should work.

I installed Python by MacPorts:

Python 3.4.3 (default, Mar 10 2015, 14:53:35) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin

For me, I think it should be about compiler. This is my clang:

Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

@gitfoxi
Copy link
Author

gitfoxi commented Mar 23, 2015

I have a similar clang:

Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

I think it's likely a python two versus Python three issue.

@gitfoxi
Copy link
Author

gitfoxi commented Mar 23, 2015

I implemented triple click in my fork. Let me know if you want want a pull request. Thanks again. This was really helpful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants