我正在尝试制作一个模拟按键的程序,每5秒钟按一次数字,这样就可以进行5 10 15 20等等,但是我得到了很多乱七八糟的东西,我不理解为一种形式错误,这是代码:
from time import sleep
import pynput
from pynput.keyboard import Key, Controller, Listener
keyboard = Controller()
i = 1
while not i == 2:
print(i)
sleep(1)
i += 1
e = 0
f = 1
g = 1
while f == 1:
e += 5
q = len(str(e))
c = str(e)
while g < q+1:
keyboard.press(c[g:g])
keyboard.release(c[g:g])
g += 1
sleep(5)
这是错误:
Traceback (most recent call last):
File "E:\Python programs\clicker.py", line 18, in <module>
keyboard.press(c[g:g])
File "C:\Users\Loput\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pynput\keyboard\_base.py", line 384, in press
resolved = self._resolve(key)
File "C:\Users\Loput\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pynput\keyboard\_base.py", line 577, in _resolve
raise ValueError(key)
ValueError