Python Forum
How to use a function from third party library?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use a function from third party library?
#1
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
Reply
#2
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)
Reply
#3
Docs here: https://github.com/boppreh/mouse#api
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling a function (which accesses a library) from another file mouse9095 4 819 Jun-07-2023, 08:55 PM
Last Post: deanhystad
  Running 3rd party libs on Steam Deck (Arch Linux) with restricted access metulburr 0 1,855 Jan-07-2023, 10:41 PM
Last Post: metulburr
  Avoid third party functions to wrote my python code into system debug-log? mark 9 2,201 Apr-09-2022, 08:41 PM
Last Post: mark
  Override a library function that is not in __all__ Weird 7 3,284 Aug-23-2021, 05:03 PM
Last Post: Larz60+
  Did interpreter 'compile' all import modules(from thrid-party) jamesyuan 10 4,305 Oct-19-2020, 10:49 AM
Last Post: jamesyuan
  python library not defined in user defined function johnEmScott 2 3,857 May-30-2020, 04:14 AM
Last Post: DT2000
  installing third-party modules shabux 5 3,438 Apr-13-2020, 12:41 AM
Last Post: Larz60+
  How to detect third party packages used in the code SriRajesh 5 2,972 Sep-21-2019, 05:59 AM
Last Post: ndc85430
  Trouble on importing function from astropy library samsonite 4 3,708 Mar-21-2019, 12:18 PM
Last Post: samsonite
  3rd Party Modules - Installing martyl 9 5,696 Jun-15-2018, 01:49 AM
Last Post: martyl

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020