【问题标题】:How do I add variable to pynput如何将变量添加到 pynput
【发布时间】:2020-11-22 05:43:15
【问题描述】:
#import modules
from pynput.keyboard import *
import time
import pyautogui

#Ask user for ID and Pass
ID = int(input('Enter ID: '))
Pass = int(input('Enter Pass: '))

#Enable controller
k = Controller()


#Press and Release 'win.key'
k.press(Key.cmd)
k.release(Key.cmd)
time.sleep(1)

#Typing "zoom" with a tim.sleep
time.sleep(0.1)
k.press('z')
k.release('z')
time.sleep(0.1)
k.press('o')
k.release('o')
time.sleep(0.1)
k.press('o')
k.release('o')
time.sleep(0.1)
k.press('m')
k.release('m')
time.sleep(0.1)

#Execute enter key
k.press(Key.enter)
k.release(Key.enter)
time.sleep(2)

#Postion for mouse click
x=501
y=291

#Move mouse to position
pyautogui.moveTo(x, y, duration = 2)

#Click on the position
pyautogui.click()

#Enter Zoom credentials
k.type(ID)
k.type(Pass)

最后两行抛出错误: 回溯(最近一次通话最后): 文件“C:/Users/rijul/Desktop/PyCharm Projects/learningclass.py”,第 50 行,在 k.type(ID) 文件“C:\Users\rijul\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pynput\keyboard_base.py”,第 461 行,类型为 对于我,枚举(字符串)中的字符: TypeError: 'int' 对象不可迭代

附:您需要安装 zoom 才能正常工作...

【问题讨论】:

    标签: python variables module pyautogui pynput


    【解决方案1】:
    ID = int(input('Enter ID: '))
    Pass = int(input('Enter Pass: '))
    

    变量将输入作为integers,但k.type 需要字符串。

    解决此问题的一种方法是将其设为字符串 - str(ID)

    【讨论】:

    • 好的,现在错误消失了,但是 k.type 函数仍然没有输入用户输入
    • 应用程序是否使用directX?
    • 但这有关系吗? @TheLaggytablet
    • 我是这么认为的,因为如果游戏使用directX,就不需要正常的击键了。
    • 因此,directX 有一个模块可以提供帮助。 - here the link
    【解决方案2】:

    我认为您传递了错误的参数,因为 k.type 正在寻找 string 值,而您传递的是 integer。简而言之,您应该将IDPass 设为string 来代替integer

    ID = input('Enter ID: ')
    Pass = input('Enter Pass: ')
    

    【讨论】:

    • 好的,现在错误消失了,但是 k.type 函数仍然没有输入用户输入
    猜你喜欢
    • 2019-09-13
    • 1970-01-01
    • 2021-03-03
    • 2014-03-10
    • 2017-10-01
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多