zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    python 类
    python sys模块
    python os模块(2)
    python re模块
    python 最小公倍数
    python 最大公约数
    python datetime模块
    python 给定n,返回n以内的斐波那契数列
    python time模块
    python os模块(1)
  • 原文地址:https://www.cnblogs.com/pursuege/p/3929669.html
Copyright © 2011-2022 走看看