Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mouse support or pre-release? #51

Closed
xiangxw opened this issue Feb 20, 2017 · 12 comments
Closed

mouse support or pre-release? #51

xiangxw opened this issue Feb 20, 2017 · 12 comments

Comments

@xiangxw
Copy link

xiangxw commented Feb 20, 2017

Hi, when can we use this library with mouse support? Looking forward to use it. Thanks.

@boppreh
Copy link
Owner

boppreh commented Feb 20, 2017

Hi

Take a look at https://github.com/boppreh/keyboard/blob/master/keyboard/mouse.py

It's available as from keyboard import mouse. It's not official, but functional.

@xiangxw
Copy link
Author

xiangxw commented Feb 21, 2017

I see, thanks a lot.
By the way, how can I identify the hwnd of a mouse or keyboard event?
Can this library be used in PyQt program ?

@boppreh
Copy link
Owner

boppreh commented Feb 21, 2017

The events detected are global. There's no notion of "window", or window handlers. You can call GetForegroundWindow to get the foreground window, maybe through ctypes or win32gui, but there's no direct support in this library.

And I'm not sure if it would work with a PyQt program, because the Windows backend that handles keyboard events is its own Windows message-loop (https://github.com/boppreh/keyboard/blob/master/keyboard/_winkeyboard.py#L430). That may or may not interfere with the Qt event loop, you would have to test it. If you do, please post the results, that would be very useful to know.

If it doesn't work for PyQt, you may have more luck with a PyQt specific solution, such as https://pypi.python.org/pypi/PyGlobalShortcut/0.2.3 .

@xiangxw
Copy link
Author

xiangxw commented Feb 27, 2017

Hi, keyboard can be used with PyQt. But it will freeze input dialog sometimes, and I can't move the mouse. Maybe we should not call SetWindowsHookEx in anothor thread? or can we call SetWindowsHookEx in main thread and use Qt's main loop to do pythoncom.PumpMessages(), just like pyHook do? Thanks.

@s0hv
Copy link

s0hv commented Apr 9, 2017

I solved the freezing by moving pythoncom.PumpMessages() to the Qt loop using a QTimer

timer = QTimer()
timer.timeout.connect(pythoncom.PumpWaitingMessages())
timer.setInterval(10)  # Call pythoncom.PumpWaitingMessages() around 100 times per second
timer.start()

This seems to fix the problem for me but I haven't done any extensive testing so it might still freeze in some situations.

@dino8890
Copy link

dino8890 commented Jul 8, 2017

What are the requirements to consider mouse for release, at least the Windows version?

Since I need mouse hooks for the project I'm working on, I might contribute on the way as well(even though the functionality implemented so far is enough).

@boppreh
Copy link
Owner

boppreh commented Jul 8, 2017

@Doom8890 It's already available as from keyboard import mouse. There's no documentation page, but you can easily see what functions are available at https://github.com/boppreh/keyboard/blob/master/keyboard/mouse.py .

from keyboard import mouse
mouse.move(100, 200)
mouse.double_click()

You can also listen for events, record and replay macros. It's quite similar to keyboard, but simpler because there's less buttons and no layouts to worry about.

It's not "official", and not documented in the main page, because I think from keyboard import mouse looks silly and I can't think of any appropriate package name that isn't in use and wouldn't cause confusion with other similar packages. Is there anything you need that is not available at the moment?

@boppreh
Copy link
Owner

boppreh commented Jul 10, 2017

Good news everyone!

I've contacted the current owner of the mouse package and they agreed to transfer ownership of the name. So I'll be releasing a sister library to keyboard under the name of mouse, containing the code that's currently at from keyboard import mouse.

This is by far the best resolution I could hope for. Stay tune for news.

@klvbdmh
Copy link

klvbdmh commented Jul 11, 2017

Is there anything you need that is not available at the moment?

I'm not sure if I should post here, open another issue, or wait for the ownership transfer and a new repo. Anyway, I would like a mouse.drag function. It's nothing more than a combination of press, move, and release, but I find writing and using this helper function a lot.

@boppreh
Copy link
Owner

boppreh commented Jul 11, 2017

I'm not sure if I should post here, open another issue, or wait for the ownership transfer and a new repo. Anyway, I would like a mouse.drag function. It's nothing more than a combination of press, move, and release, but I find writing and using this helper function a lot.

Here; 85a4162

Unrelated, I'm getting some errors on the mouse listening parts. I'll have to investigate.

@klvbdmh
Copy link

klvbdmh commented Aug 9, 2017

Awesome, thanks!

@boppreh
Copy link
Owner

boppreh commented Aug 28, 2017

Now available at https://github.com/boppreh/mouse and pip install mouse, though it's still somewhat experimental.

@boppreh boppreh closed this as completed Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants