首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python脚本在空闲状态下工作,但在通过控制台运行时会收到一个错误。[错误代码]只能规范非空字符串名。出乎意料的'‘

问Python脚本在空闲状态下工作,但在通过控制台运行时会收到一个错误。[错误代码]只能规范非空字符串名。出乎意料的'‘
EN

Stack Overflow用户
提问于 2021-12-29 08:45:31
回答 1查看 54关注 0票数 0
代码语言:javascript
复制
import time
import keyboard
import pyautogui
import sys
import numpy as np
import matplotlib.pyplot as plt



welcome = "Welcome to the manual multi script (This script is still in developement please be patient.)"
print (welcome.upper())
help = "\nIf you need anyhelp please contact Frame on discord. \n"
print (help.upper())



print('You are about to bind your coords to [ANTI-FREEZE]: \n')
print('Please press [SPACE] to continue\n ')

while True:
    if  keyboard.is_pressed('SPACE'):
        print('Press ENTER on the [ANTI-FREEZE] power to get its location')
        time.sleep(1)
    if keyboard.is_pressed('ENTER'):
        x,y = pyautogui.position()
        print("\nYour current X pos: " + str(x) + "," + "\nYour current Y pos: " + str(y))
        antifX1 = x
        antifY1 = y
        x = antifX1
        y = antifY1
        time.sleep(1)
        print("\n[ANTIFREEZE]Your current X and Y coord is: " + '[ ' + str(x) + ' , ' + str(y) + ' ] \n')
        break
    if keyboard.is_pressed('N'):
        print('\nNo Problem! Next Question... ')
        break



print('You are about to bind your coords to [PORTAL]: \n')
print('Please press [SPACE] to continue\n ')

while True:   
    if keyboard.is_pressed('SPACE'):
            print('Press ENTER on the PORTAL power to get its location')
            time.sleep(1)
    if keyboard.is_pressed('ENTER'):
            x,y = pyautogui.position()
            print("\nYour current X pos: " + str(x) + "," + "\nYour current Y pos: " + str(y))
            portalfX1 = x
            portalfY1 = y
            x = portalfX1
            y = portalfY1
            time.sleep(1)
            print("\n[PORTAL]Your current X and Y coord is: " + '[ ' + str(x) + ' , ' + str(y) + ' ] \n')
            break
    if keyboard.is_pressed('N'):
            print('\nNo Problem! Next Question... ')
            break

print('You are about to bind your coords to [FREEZE]: \n')
print('Please press [SPACE] to continue\n ')

while True:
    if keyboard.is_pressed('SPACE'):
            print('Press ENTER on the antifreeze power to get its location')
            time.sleep(1)
    if keyboard.is_pressed('ENTER'):
            x,y = pyautogui.position()
            print("\nYour current X pos: " + str(x) + "," + "\nYour current Y pos: " + str(y))
            freezefX1 = x
            freezefY1 = y
            x = freezefX1
            y = freezefY1
            time.sleep(1)
            print("\n[FREEZE]Your current X and Y coord is: " + '[ ' + str(x) + ' , ' + str(y) + ' ] \n')
            break
    if keyboard.is_pressed('N'):
        print('\nNo Problem! Next Question... ')
        break

notice = ('[NOTICE] an input delay on 1 means 1 drop per second\n')
print(notice.upper())
time.sleep(1)
while True:
    print('Drop Delay [MAKE SURE YOU INSERT ANSWER ON THIS LINE]: ')
    Apause = input()
    print('[Script Complete!]')
    Apause = pyautogui.PAUSE
    break
a = input('\nPlease enter keybind[ANTIFREEZE]: \n')
b = input('Please enter keybind[PORTAL]: \n')
c = input('Please enter keybind[FREEZE]: \n')
while True:
        pos = pyautogui.position()
        afreezePOS = pyautogui.position(antifX1, antifY1)
        portalPOS = pyautogui.position(portalfX1, portalfY1)
        freezePOS = pyautogui.position(freezefX1, freezefY1)
        if keyboard.is_pressed(a):
            pyautogui.click(afreezePOS)
            Apause
            pyautogui.mouseDown(button='left')
            Apause
            pyautogui.moveTo(pos)
            Apause
            pyautogui.mouseUp(button='left')
            Apause
            print('[ANTI] was pressed. \n')
        if keyboard.is_pressed(b):
            pyautogui.click(portalPOS)
            pyautogui.mouseDown(button='left')
            Apause
            pyautogui.moveTo(pos)
            Apause
            pyautogui.mouseUp(button='left')
            Apause
            print('[PORTAL] was pressed. \n')
        if keyboard.is_pressed(c):
            pyautogui.click(freezePOS)
            Apause
            pyautogui.mouseDown(button='left')
            Apause
            pyautogui.moveTo(pos)
            Apause
            pyautogui.mouseUp(button='left')
            Apause
            print('[FREEZE] was pressed. \n')

当我在python空闲程序中运行这段代码时,它工作得很好。我什么都试过了,似乎失去了希望。是否还有其他方式让用户输入他们自己的键绑定,就像我在这里试图做的那样?如果有其他选择的话,我很乐意这样做。当我在控制台上运行时,我会得到错误。

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\ovosc\Desktop\Multiking\Realmulti.py", line 99, in <module>
    if keyboard.is_pressed(a):
  File "C:\Users\ovosc\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard\__init__.py", line 417, in is_pressed
    steps = parse_hotkey(hotkey)
  File "C:\Users\ovosc\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard\__init__.py", line 358, in parse_hotkey
    steps.append(tuple(key_to_scan_codes(key) for key in keys))
  File "C:\Users\ovosc\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard\__init__.py", line 358, in <genexpr>
    steps.append(tuple(key_to_scan_codes(key) for key in keys))
  File "C:\Users\ovosc\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard\__init__.py", line 309, in key_to_scan_codes
    normalized = normalize_name(key)
  File "C:\Users\ovosc\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard\_canonical_names.py", line 1239, in normalize_name
    raise ValueError('Can only normalize non-empty string names. Unexpected '+ repr(name))
ValueError: Can only normalize non-empty string names. Unexpected ''

我完全迷路了,不知道怎么解决这个问题。有人知道这个问题是什么意思吗?

EN

回答 1

Stack Overflow用户

发布于 2021-12-29 08:54:20

我认为问题在于您使用keybaord.is_pressed(a),而a是输入的变量。

代码语言:javascript
复制
#if keyboard.is_pressed(a):
if keyboard.is_pressed('a'): #it should be like this
            pyautogui.click(afreezePOS)
            Apause
            pyautogui.mouseDown(button='left')
            Apause
            pyautogui.moveTo(pos)
            Apause
            pyautogui.mouseUp(button='left')
            Apause

对于b和c,您也应该这样做。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70517069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档