Python Forum

Full Version: How to use a function from third party library?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
There is a library called mouse. It has a function called mouse.hook(callback). I'm trying to use this function to input mouse actions into a program where it otherwise wouldn't work. It has documentation explaining what it does, but I'm not quite sure what I need to do with said function.
Quote:Installs a global listener on all available mouses, invoking callback each time it is moved, a key status changes or the wheel is spun. A mouse event is passed as argument, with type either mouse.ButtonEvent, mouse.WheelEvent or mouse.MoveEvent.

Returns the given callback for easier development.
Any ideas how I can integrate this function into my code so that the mouse does X upon keypress?
import mouse
import keyboard

while True:
    if keyboard.is_pressed(']'):
        mouse.hook(mouse.move(10, 0, False, duration=0.01))
Link to documentation:
https://github.com/boppreh/mouse
Mouse.hook() is for receiving callback events from the mouse. mouse.move() is for creating synthetic mouse events. If you want to move the cursor, you don't need the hook.

Maybe try something like:

while True:
    if keyboard.is_pressed(']'):
        mouse.move(10, 0, False, duration=0.01)