Home  >  Q&A  >  body text

python - Use pyhook to monitor keystrokes and delete specified characters, but an error will be reported the second time you run it. What is the reason?

#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()
習慣沉默習慣沉默2712 days ago485

reply all(1)I'll reply

  • 某草草

    某草草2017-05-18 10:52:39

    The error message was not posted and no one answered you

    reply
    0
  • Cancelreply