Python 调用时未执行execute()函数
我正在尝试制作一个键映射,使我的键盘不使用微软无用的Python 调用时未执行execute()函数,python,arrays,keyboard,keyevent,Python,Arrays,Keyboard,Keyevent,我正在尝试制作一个键映射,使我的键盘不使用微软无用的输入法键盘。 所以我用pynput编写了这个python代码 但它似乎不执行我的execute()函数 execute()具有当前值,但您从未将此类变量传递给函数,因此您不进行任何比较。您的函数应该如下所示 def execute(current) : if current == "q": print("q") 如果将curren
输入法键盘
。
所以我用pynput
编写了这个python
代码
但它似乎不执行我的execute()
函数
execute()具有当前值
,但您从未将此类变量传递给函数,因此您不进行任何比较。您的函数应该如下所示
def execute(current) :
if current == "q":
print("q")
如果将
current
传递给该功能,它将立即按下所有键,并使用loop或If条件检查按下键中的键。如果只需按最后一个键,则只需按键即可
def on_press(key) :
if any([key in COMBO for COMBO in COMBINATIONS]):
current.add(key)
if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
execute(current)
def execute(current_key_set) :
for key in current_key_set:
print(key)
或
在考虑了乔奎因的“集合到字符串”理论后,我将我的集合
转换为字符串
它成功了
Thnx Joaqín
def execute(current_key) :
s = str(current_key)
for i in s :
if i == "q" :
print("q")
#print("\bㅂ") I tested it with a language and it types the normal text too so I prefer adding\b before the letter/word/sentence
我试过了,但不起作用。在if(if any)(all(k-in-current表示k-in-COMBO)表示组合中的组合)中,您正在调用execute()
,但函数也是空的,请传递您要检查的变量,然后按(key)def(key):if any([key-in-COMBO表示组合中的组合]):current.add(key)if any(all(k in current for k in COMBO)for COMBO in compositions):execute(current)def execute(word):if word==“q”:print(“q”)
即使我将if
条件放在当前写入的on\u press
函数中execute()
它也不起作用,如果在if语句中将current
作为变量传递,它将不起作用,因为您传递的是一个集合而不是一个字符串。我得到的是一个错误,它工作于nx。只需将参数从current更改为其他值即可检查更新后的答案。但是,当集合有两个以上的键时,它会抛出一个错误修复答案
def on_press(key) :
if any([key in COMBO for COMBO in COMBINATIONS]):
current.add(key)
if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
execute(current)
def execute(current_key_set) :
for key in current_key_set:
print(key)
def on_press(key) :
if any([key in COMBO for COMBO in COMBINATIONS]):
current.add(key)
if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
execute(key)
def execute(current_key) :
print(current_key)
def execute(current_key) :
s = str(current_key)
for i in s :
if i == "q" :
print("q")
#print("\bㅂ") I tested it with a language and it types the normal text too so I prefer adding\b before the letter/word/sentence