1234567891011121314151617181920212223242526272829303132 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- '''
- @文件 :delay.py
- @时间 :2022/02/17 15:37:43
- @作者 :None
- @版本 :1.0
- @说明 :精确到ms延迟函数
- '''
- import sys
- import ctypes
- from time import sleep
- def m_delay(ms):
- if sys.platform == "darwin" or sys.platform == "linux":
- sleep(ms / 1000)
- elif sys.platform == "win32" or sys.platform == "win64":
- stop_value = ctypes.c_longlong(0)
- start_value = ctypes.c_longlong(0)
- freq = ctypes.c_longlong(0)
- n = 0
- ctypes.windll.kernel32.QueryPerformanceFrequency(ctypes.byref(freq))
- count = ms * freq.value / 1000
- ctypes.windll.kernel32.QueryPerformanceCounter(ctypes.byref(start_value))
- while n < count:
- ctypes.windll.kernel32.QueryPerformanceCounter(ctypes.byref(stop_value))
- n = stop_value.value - start_value.value
- else:
- sleep(ms / 1000)
|