Knowledge points: the use of Python library and simple timer
1. The mouse automatically clicks on the screen code
(1) First, PIP install pymouse
(2) . running code: modulenotfounderror: no module named ‘windows’
Cause: lack of pyuserinput tool
Solution: PIP install pyuserinput
Could not find a version that satisfies the requirement pyhook (from pyuserinput) (from versions:)
No matching distribution found for pyHook (from pyuserinput)
Reason: lack of pyhook
Solution: http://www.lfd.uci.edu/~gohlke/pythonlibs/ Search pyhook to download
Then PIP install + path installation
(3). pip install PyUserinput
Running successfully!
2. Cycle timer
Thread timer principle:
Start thread after specified time interval! Application scenarios: complete the timing task, such as timing reminder, timing sending, timing collection function, etc
#Import thread module
import threading
timer = threading.Timer(interval, function, args=None, kwargs=None)
Parameter introduction:
Interval – timer interval, the number of seconds after which the timer task is started (unit: seconds);
Function – thread function;
Args – thread parameter, tuple type data can be passed, the default is null (default parameter);
Kwargs – thread parameter, dictionary type data can be passed, the default is null (default parameter)
3. Print Hello world after 3 seconds
Only once
4. Simple cycle timer
Continue to register a timer in function so that the function can be continued at the next interval
Timer itself, it is a thread. Every time the loop interval operation, the system must create a thread, and then recycle, which is very expensive for the system
If the time interval is very short, the system will create many threads at once. These threads are difficult to recycle quickly, resulting in the consumption of system memory and CPU resources
5. Four ways to realize timed tasks in Python 3
1> Cycle + sleep;
2> Timer class in thread module;
3> Schedule module;
4> Timing frame: apscheduler
6. Code
Reference documents: https://blog.csdn.net/weixin_ 41561539/article/details/94294828
https://blog.csdn.net/weixin_34203426/article/details/91394230