简体   繁体   English

Python win32com SendKeys失败

[英]Python win32com SendKeys fail

I've tried to do button press test and every time I do it, it fails somewhere. 我尝试进行按钮按下测试,每次执行时,它都会在某处失败。 There is always place where there are two (or more) lower case letters next to one another or two upper case. 总是存在两个(或多个)小写字母彼此相邻或两个大写字母相邻的地方。 Why is that? 这是为什么?

import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("notepad")
shell.AppActivate("Notepad")


def a():
    shell.SendKeys("{a}", 0)


def A():
    shell.SendKeys("{A}", 0)


def b():
    shell.SendKeys("{b}", 0)


def B():
    shell.SendKeys("{B}", 0)


def c():
    shell.SendKeys("{c}", 0)


def C():
    shell.SendKeys("{C}", 0)


def d():
    shell.SendKeys("{d}", 0)


def D():
    shell.SendKeys("{D}", 0)


def e():
    shell.SendKeys("{e}", 0)


def E():
    shell.SendKeys("{E}", 0)


def f():
    shell.SendKeys("{f}", 0)


def F():
    shell.SendKeys("{F}", 0)


def g():
    shell.SendKeys("{g}", 0)


def G():
    shell.SendKeys("{G}", 0)


def h():
    shell.SendKeys("{h}", 0)


def H():
    shell.SendKeys("{H}", 0)


def i():
    shell.SendKeys("{i}", 0)


def I():
    shell.SendKeys("{I}", 0)


def j():
    shell.SendKeys("{j}", 0)


def J():
    shell.SendKeys("{J}", 0)


def k():
    shell.SendKeys("{k}", 0)


def K():
    shell.SendKeys("{K}", 0)


def l():
    shell.SendKeys("{l}", 0)


def L():
    shell.SendKeys("{L}", 0)


def m():
    shell.SendKeys("{m}", 0)


def M():
    shell.SendKeys("{M}", 0)


def n():
    shell.SendKeys("{n}", 0)


def N():
    shell.SendKeys("{N}", 0)


def o():
    shell.SendKeys("{o}", 0)


def O():
    shell.SendKeys("{O}", 0)


def p():
    shell.SendKeys("{p}", 0)


def P():
    shell.SendKeys("{P}", 0)


def q():
    shell.SendKeys("{q}", 0)


def Q():
    shell.SendKeys("{Q}", 0)


def r():
    shell.SendKeys("{r}", 0)


def R():
    shell.SendKeys("{R}", 0)


def s():
    shell.SendKeys("{s}", 0)


def S():
    shell.SendKeys("{S}", 0)


def t():
    shell.SendKeys("{t}", 0)


def T():
    shell.SendKeys("{T}", 0)


def u():
    shell.SendKeys("{u}", 0)


def U():
    shell.SendKeys("{U}", 0)


def w():
    shell.SendKeys("{w}", 0)


def W():
    shell.SendKeys("{W}", 0)


def x():
    shell.SendKeys("{x}", 0)


def X():
    shell.SendKeys("{X}", 0)


def y():
    shell.SendKeys("{y}", 0)


def Y():
    shell.SendKeys("{Y}", 0)


def z():
    shell.SendKeys("{z}", 0)


def Z():
    shell.SendKeys("{Z}", 0)


def enter():
    shell.SendKeys("{ENTER}", 0)

a(), A(), b(), B(), c(), C(), d(), D(), e(), E(), f(), F(), g(), G(), h(), H(), i(), I(), j(), J(), k(), K(),
l(), L(), m(), M(), n(), N(), o(), O(), p(), P(), q(), Q(), r(), R(), s(), S(), t(), T(), u(), U(), w(), W(),
x(), X(), y(), Y(), z(), Z(), enter(),

Expected output: "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUwWxXyYzZ" 预期输出:“ aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUwWxXyYzZ”

Adding time.sleep(0.03) and above after each press fixes issue. 每次按修复问题后添加time.sleep(0.03)及更高版本。 Still don't know why Notepad is not interpreting keys correctly. 仍然不知道为什么记事本无法正确解释键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM