• Python自动按键程序片段


    本程序python2.7  http://pan.baidu.com/s/1gdILez5

    用的win32模块控制键盘 http://pan.baidu.com/s/1o6wSgdW

    #coding=GBK
    import threading
    import time 
    import win32con, win32api
    #循环执行自动按键程序
    def keyauto():
        waitTimes = 5
        perTimes = 0.8;
        print("run...")
        while True:
            #间隔5秒后开始自动按键
            time.sleep(waitTimes)
            pressKey(1, 0.1)  #鼠标左键,0.1秒后抬起
            pressKey(2, 0.1)  #R
            pressKey(9, 0.1)  #table
            pressKey(32, 0.1)  #space
            pressKey(67, 0.1)  #c
            pressKey(86, 0.1)  #v
            time.sleep(perTimes)
            pressKey(88, 0.1)  
            pressKey(1, 0.1)   #L
            pressKey(67, 0.1)  #c
            pressKey(48, 0.1)  #1
            time.sleep(perTimes)
            pressKey(49, 0.1)  #2
            time.sleep(perTimes)
            pressKey(50, 0.1)  #3
            
    #按下某个键(key)后,second秒后再抬起这个键。所有键码:http://zhidao.baidu.com/question/266291349.html
    def pressKey(key, second):
        win32api.keybd_event(key, 0, 0, 0)
        if(second != 0):
            time.sleep(second)
        win32api.keybd_event(key, 0, win32con.KEYEVENTF_KEYUP, 0)
    #开启一个线程并运行
    t = threading.Thread(target=keyauto())
    t.start()
  • 相关阅读:
    2019-12-18
    java读取XML文件,及封装XML字符串
    java不用中间变量交换两个值
    oracle获取当前月的第一个星期五
    2019-10-23
    HTTP中GET请求与POST请求的区别
    Java面试题整理(转载)
    java 字节流与字符流的区别
    20190822
    C++标准库string
  • 原文地址:https://www.cnblogs.com/pursuege/p/3929669.html
Copyright © 2020-2023  润新知