By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

unable to execute pyhook script from windows service.

P: 1
im calling pyhook related script from python windows service its not getting execute but for normal execution and debug its working fine.
Expand|Select|Wrap|Line Numbers
  1. import pythoncom,pyHook , sys
  2. import datetime
  3. import win32api
  4. import ctypes
  5. last_event = ''
  6. def info(idle_time) :
  7.   try :
  8.     fo = open("testschd.txt", "a+")
  9.   except :
  10.     fo = open("testschd.txt", "wb")
  11.   fo.write(str(idle_time))
  12. def OnMouseEvent1(event) :    
  13.     global last_event 
  14.     if last_event :
  15.         before = (datetime.datetime.now() - last_event)
  16.         print before.seconds
  17.         if before.seconds > 60 :
  18.             info(before.seconds)
  19.     last_event = datetime.datetime.now()
  20.     return True
  21. def OnKeyboardEvent(event) :
  22.     global last_event
  23.     if last_event :
  24.         before = (datetime.datetime.now() - last_event)
  25.         if before.seconds > 60 :
  26.             info(before.seconds)
  27.     last_event = datetime.datetime.now()
  28.     return True
  29. def test() :
  30.     hm = pyHook.HookManager()
  31.     hm.KeyDown = OnKeyboardEvent
  32.     hm.SubscribeMouseAllButtonsDown(OnMouseEvent1)
  33.     hm.MouseDown = OnMouseEvent1
  34.     hm.HookKeyboard()
  35.     hm.HookMouse()
  36.     pythoncom.PumpMessages()
  37.  
can anyone help me what is wrong here.
Thanks in Advance.
Jul 12 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.