博客首页:knighthood2001
欢迎点赞评论️
❤️ 热爱python,期待与大家一同进步成长!!❤️
SendKeys(text: str, interval: float = 0.01, waitTime: float = OPERATION_WAIT_TIME, charMode: bool = True, debug: bool = False)
上面是Sendkeys的函数定义,模拟键盘上的键入键。
其既可以输入文本内容,也可以输入键盘上的键。
text: 文本:str,要键入的键。 interval: 间隔,键之间的秒数。默认为0.01秒 waitTime: 默认为0.05秒 charMode: bool, 如果为 False,则键入的文本取决于输入法(如果输入法已打开)。 debug: bool, 如果为 True,则打印密钥。
按键举例:
值 | 按键描述 |
SendKeys('{Enter}') | 回车 |
SendKeys('{Ctrl}') | Ctrl |
SendKeys('{Delete}') | Delete |
SendKeys('{Alt}') | Alt |
SendKeys('{Space}') | Space |
SendKeys('{Shift}') | Shift |
SendKeys('{PageDown}') | PageDown |
SendKeys('{Win}') | Win |
SendKeys('{F1}') | F1 |
除了以上单独按键,还可以组合按键
SendKeys('{Ctrl}a') 表示Ctrl+a SendKeys('{Ctrl}{Shift}s')表示Ctrl+Shift+s SendKeys('{Win}r') 表示Win+r SendKeys('{Ctrl}v') 表示Ctrl+v SendKeys('{Ctrl}(AB)') 表示Ctrl+A+B SendKeys('{Ctrl}{v 3}') 表示同时按下 Ctrl+v,松开 Ctrl+v,然后键入'v'2次 SendKeys('{a 3}{B 5}') 表示输入a3次,b5次 SendKeys('{{}Hello{}}abc {a}{b}{c} test{} 3}{!}{a} (){(}{)}') 结果为{Hello}abc abc test}}}!a ()(),即{}中无内容,则去掉{},有内容则进行判断。 SendKeys('0123456789{Enter}')表示输入0123456789,然后回车 SendKeys('ABCDEFGHIJKLMNOPQRSTUVWXYZ{Enter}')同上 SendKeys('abcdefghijklmnopqrstuvwxyz{Enter}')同上 SendKeys('`~!@#$%^&*()-_=+{Enter}')同上 SendKeys('[]{{}{}}\\|;:\'\",<.>/?{Enter}')同上
结果如下