在Python中创建自动打字机自动程序时出现问题

时间:2019-03-03 07:59:17

标签: python python-3.x bots discord

我想创建一个机器人,该机器人每隔1分钟和几秒钟一次自动复制并粘贴剪贴板上的所有内容。我想在Discord上使用它。当我运行该程序时,它会复制并粘贴良好,但是然后不执行enter命令,并且不会发送不一致的消息。这是我的代码,我用Pynput模拟了击键。我是python的新手,这是我的第一个程序。

如果有人可以帮助我制作一个可以逐个字符键入查询字符的现实机器人,请告诉我。如果有人患有不和谐症,我的不和谐症是:Bitmap#7807

我使用Python 3.5

import time

keyboard = Controller()

timeout = time.time() + 60*60*8 
time.sleep(4)
while True:
    test=0
    keyboard.press(Key.ctrl)
    time.sleep(0.5)
    keyboard.press('v')
    time.sleep(0.5)
    keyboard.release('v')
    time.sleep(0.5)
    keyboard.press(Key.shift)
    time.sleep(0.12)
    keyboard.press(Key.enter)
    time.sleep(0.12)
    keyboard.release(Key.enter)
    time.sleep(0.12)
    keyboard.release(Key.shift)
    time.sleep(0.12)
    keyboard.release(Key.ctrl)
    time.sleep(5)
    test = test+1

    if test == 261 or time.time() > timeout:
        break```

1 个答案:

答案 0 :(得分:0)

您不是要在释放“ V”之后释放“ Ctrl”吗?
另外,我不了解“ Shift”,您是否随后尝试创建空白行?

尝试一下:

[...]
keyboard.press(Key.ctrl)
time.sleep(0.5)
keyboard.press('v')
time.sleep(0.5)
keyboard.release('v')
time.sleep(0.5)
keyboard.release(Key.ctrl)
time.sleep(0.5)
keyboard.press(Key.shift)
time.sleep(0.12)
keyboard.press(Key.enter)
time.sleep(0.12)
keyboard.release(Key.enter)
time.sleep(0.12)
keyboard.release(Key.shift)
time.sleep(0.12)
keyboard.press(Key.enter)
time.sleep(0.12)
keyboard.release(Key.enter)
time.sleep(5)
[...]