python hook禁止结束进程,pyHook停止(随机)接收按键事件吗?

博主遇到一个使用pyHook库实现的键盘监听程序在运行一段时间后突然停止接收按键触发的问题。程序会执行一系列点击操作,但会在随机时间点停止响应。尽管程序在计算机上仍然活跃,即使通过IDE停止也无法解决。问题可能与pyHook的稳定性有关,但具体原因尚不清楚。解决方案尚未提供。
摘要由CSDN通过智能技术生成

I have a program that captures all key presses using pyHook, then runs a few functions.

I notice that after a while (of random duration), the program was stop receiving key triggers, even though I am pressing keys?

Is pyHook unstable?

I'm not changing what keys are pressed or pressing them prematurely or anything like that.

Here's my code:

import time

import win32api

import win32con

import pythoncom

import pyHook

import os

import ctypes

def Click(x,y):

win32api.SetCursorPos((x,y))

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

def DeleteRun(event):

if event.Ascii == 96:

BreakHook()

return False

Click(1250, 741)

time.sleep(0.2)

Click(649,261)

time.sleep(0.2)

Click(651, 348)

time.sleep(0.2)

Click(800, 442)

time.sleep(0.2)

Click(865, 612)

time.sleep(0.2)

Click(25, 744)

time.sleep(3)

Click(25, 744)

time.sleep(1.5)

Click(1112,297)

Click(145,392)

return True

def BreakHook():

ctypes.windll.user32.PostQuitMessage(0)

KeyGrabber = pyHook.HookManager()

KeyGrabber.KeyDown = DeleteRun

KeyGrabber.HookKeyboard()

pythoncom.PumpMessages()

Why does is suddenly stop working?

It's very frustrating as the process remains active on my computer, even if I stop the program through the IDE.

Specs:

python 2.7.2

Windows 7 (32)

解决方案

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值