Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have implemented a script using pyhook to track mouse and keyboard event, and calling this from the python windows service its not calling OnMouseEvent1 and OnKeyboardEvent but for normal execution and while debugging the service its working fine.
can any one help me to sort out the problem.
below is my code.
import pythoncom,pyHook , sys
import datetime
import win32api
import ctypes
last_event = ''
def info(idle_time) :
  try :
    fo = open("testschd.txt", "a+")
  except :
    fo = open("testschd.txt", "wb")
  fo.write(str(idle_time))
def OnMouseEvent1(event) :    
    global last_event 
    if last_event :
        before = (datetime.datetime.now() - last_event)
        print before.seconds
        if before.seconds > 60 :
            info(before.seconds)
    last_event = datetime.datetime.now()
    return True
def OnKeyboardEvent(event) :
    global last_event
    if last_event :
        before = (datetime.datetime.now() - last_event)
        if before.seconds > 60 :
            info(before.seconds)
    last_event = datetime.datetime.now()
    return True
def test() :
    hm = pyHook.HookManager()
    hm.KeyDown = OnKeyboardEvent
    hm.SubscribeMouseAllButtonsDown(OnMouseEvent1)
    hm.MouseDown = OnMouseEvent1
    hm.HookKeyboard()
    hm.HookMouse()
    pythoncom.PumpMessages()


What I have tried:

In the above script i am calling test() method from python windows service(service implemented by using python).
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900