本文介绍了Sendkeys功能出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我下载了适用于python 2.7的Sendkeys版本.它的效果很好!...适用于可以在字符串中输入的字母和数字.
So I downloaded a version of Sendkeys for python 2.7. Its working great!...for letters and numbers that can be entered in a string.
该函数具有以下形式:
def SendKeys(keys,
pause=0.05,
with_spaces=False,
with_tabs=False,
with_newlines=False,
turn_off_numlock=True):
"""
Sends keys to the current window.
`keys` : str
A string of keys.
`pause` : float
The number of seconds to wait between sending each key
or key combination.
`with_spaces` : bool
Whether to treat spaces as ``{SPACE}``. If `False`, spaces are ignored.
`with_tabs` : bool
Whether to treat tabs as ``{TAB}``. If `False`, tabs are ignored.
`with_newlines` : bool
Whether to treat newlines as ``{ENTER}``. If `False`, newlines are ignored.
`turn_off_numlock` : bool
Whether to turn off `NUMLOCK` before sending keys.
example::
SendKeys("+hello{SPACE}+world+1")
would result in ``"Hello World!"``
"""
并给出以下代码:
CODES = {
'BACK': 8,
'BACKSPACE': 8,
'BS': 8,
'BKSP': 8,
'BREAK': 3,
'CAP': 20,
'CAPSLOCK': 20,
'DEL': 46,
'DELETE': 46,
'DOWN': 40,
'END': 35,
'ENTER': 13,
'ESC': 27,
'HELP': 47,
'HOME': 36,
'INS': 45,
'INSERT': 45,
'LEFT': 37,
'LWIN': 91,
'NUMLOCK': 144,
'PGDN': 34,
'PGUP': 33,
'PRTSC': 44,
'RIGHT': 39,
'RMENU': 165,
'RWIN': 92,
'SCROLLLOCK': 145,
'SPACE': 32,
'TAB': 9,
'UP': 38,
'DOWN': 40,
'BACKSPACE': 8,
'F1': 112,
'F2': 113,
'F3': 114,
'F4': 115,
'F5': 116,
'F6': 117,
'F7': 118,
'F8': 119,
'F9': 120,
'F10': 121,
'F11': 122,
'F12': 123,
'F13': 124,
'F14': 125,
'F15': 126,
'F16': 127,
'F17': 128,
'F18': 129,
'F19': 130,
'F20': 131,
'F21': 132,
'F22': 133,
'F23': 134,
'F24': 135,
}
我只是想不通如何使用它们!具体来说,我希望能够退格.
I just cannot figure out how to use them! Specifically I would like to be able to backspace.
非常感谢您!
推荐答案
忽略CODES词典中的所有值. (即8、8、8、8、3、20、20等).唯一重要的是按键("BACK","BACKSPACE","BS"等),您可以通过以下方式使用它们:用方括号将它们括起来并调用函数:
Ignore all the values in the CODES dictionary. (That is, 8, 8, 8, 3, 20, 20, etc.) The only thing that matters are the keys ('BACK', 'BACKSPACE', 'BS', etc.), and you can use them by surrounding them with brackets and calling the function:
import SendKeys
send = "dirx{BACKSPACE}{ENTER}"
SendKeys.SendKeys(send)
发送"dir"命令.
仅此而已!
这篇关于Sendkeys功能出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!