ctypes mouse_events

前端 未结 2 1001
你的背包
你的背包 2020-12-30 16:13

ctypes.windll.user32.mouse_event(3, 0, 0, 0,0)

I\'m messing around with mouse positions and stumbled upon this line which from what I understand emu

2条回答
  •  悲哀的现实
    2020-12-30 16:41

    This is from http://blog.lazynice.net/?p=63.

    The script detect the windows’s inactivity every minute. If the inactivity exceeds 5 minutes, it simply sends an mouse event that move the mouse a little, so the screensaver may think it comes from the user input then reset the timer. Just set the inactivity duration less than the screensaver’s waiting time then run it!

    from ctypes import Structure, windll, c_uint, sizeof, byref
    import time
    
    class LASTINPUTINFO(Structure):
        _fields_ = [('cbSize', c_uint), ('dwTime', c_uint)]
    
    def get_idle_duration():
        lastInputInfo = LASTINPUTINFO()
        lastInputInfo.cbSize = sizeof(lastInputInfo)
        windll.user32.GetLastInputInfo(byref(lastInputInfo)) 
        millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
        return millis / 1000.0
    
    while True:
        d = get_idle_duration()
        if d > 60 * 5:
            windll.user32.mouse_event(1, 1, 1, 0, 0)
        time.sleep(60)
    

提交回复
热议问题