简体   繁体   English

Python鼠标库控制鼠标

[英]Python mouse library to control mouse

Ok, I've finished code and it's working perfectly fine:好的,我已经完成了代码,并且运行良好:

time.sleep(1)
mouse.move(1814, 19, absolute=True, duration=0)
mouse.click()                                           
time.sleep(1)

mouse.move(722, 196, absolute=True, duration=0)
mouse.double_click()                                    
time.sleep(20)

mouse.move(894, 923, absolute=True, duration=0)
mouse.click()                                           
time.sleep(1)

mouse.move(530, 452, absolute=True, duration=0)
mouse.click()                                           
time.sleep(3)

mouse.move(1580, 454, absolute=True, duration=1)
time.sleep(1)
mouse.drag(1580, 454, 797, 447, absolute=True, duration=1)       
time.sleep(1) 

mouse.move(530, 452, absolute=True, duration=0)
mouse.click()                                           
time.sleep(3)

mouse.move(1088, 654, absolute=True, duration=2)
time.sleep(1)
mouse.drag(1088, 654, 1115, 863, absolute=True, duration=1)        
time.sleep(1)

mouse.move(1094, 880, absolute=True, duration=0)
time.sleep(1)
mouse.drag(1094, 880, 1112, 190, absolute=True, duration=1)          
time.sleep(1)

mouse.move(682, 783, absolute=True, duration=0)                    
mouse.click()
time.sleep(2)

mouse.move(1689, 643, absolute=True, duration=0)
mouse.click()

Is there any way to make this code a function?有没有办法让这个代码成为 function? I mean, define function that will execute these mouse commands.我的意思是,定义将执行这些鼠标命令的 function。 I'd much appreciate help.我非常感谢帮助。 Thanks in advance.提前致谢。

BTW, what I need to do, is run this code on specific time(every Sunday at 23:59), maybe you could suggest other solutions how to do it.顺便说一句,我需要做的是在特定时间(每周日 23:59)运行此代码,也许您可以建议其他解决方案如何执行此操作。

I think yes.我想是的。 Make a function: def MouseClicker: -insert all that code here-制作一个 function:def MouseClicker:-在此处插入所有代码-

and then call it below.然后在下面调用它。

As I can see, everything is hardcoded so I don't think you can automate that.正如我所看到的,一切都是硬编码的,所以我认为你不能自动化。 But you can automate the script to run on your date.但是您可以自动化脚本以在您的日期运行。 Try make a Task for that date(with task scheduler if you are on windows) that runs a bash script with the line "pythonw nameoffile.py" and it just runs in the background.尝试为该日期创建一个任务(如果您在 Windows 上,则使用任务调度程序)运行带有“pythonw nameofile.py”行的 bash 脚本,它只是在后台运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM