Heim > Fragen und Antworten > Hauptteil
#coding=utf-8
import pyHook
import pythoncom
list = [4,0,5,0,6,4,0]
def del_zero(array):
for i in array:
if i == 0:
array.remove(i)
array.append(int(0))
return array
def onKeyboardEvent(event):
# 监听键盘事件
lit = []
if event.Key == "Down":
lit = del_zero(list)
print lit
return (event.Key)
def main():
# 创建一个“钩子”管理对象
hm = pyHook.HookManager()
# 监听所有键盘事件
hm.KeyDown = onKeyboardEvent
# 设置键盘“钩子”
hm.HookKeyboard()
# 监听所有鼠标事件
pythoncom.PumpMessages()
if __name__ == "__main__":
main()