Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function pyhook:按特定键时调用函数(与其他键分开)_Function_Python 2.7_Keystroke_Pyhook - Fatal编程技术网

Function pyhook:按特定键时调用函数(与其他键分开)

Function pyhook:按特定键时调用函数(与其他键分开),function,python-2.7,keystroke,pyhook,Function,Python 2.7,Keystroke,Pyhook,我开始使用pyHook是因为我希望在用户按下特定键时调用函数。这是我的代码: def on_keyboard_event(event): if event.KeyID == 79: # ID 79 = 'o' key next_query() # this is a function I created return True 然而,这意味着每次用户按下“o”键时,函数都会被调用,即使用户只是在写“hello”或“oh!”。

我开始使用pyHook是因为我希望在用户按下特定键时调用函数。这是我的代码:

def on_keyboard_event(event):
    if event.KeyID == 79:        # ID 79 = 'o' key
        next_query()             # this is a function I created
    return True
然而,这意味着每次用户按下“o”键时,函数都会被调用,即使用户只是在写“hello”或“oh!”。 因此,我想知道是否有可能告诉python,我希望它只在单独按下该键时才运行该函数,而只在用户按下“o”而不按下其他键时才运行

提前谢谢