I found Tim Golden's artical "See if my workstation is locked" http://timgolden.me.uk/python/win32_how_do_i/see_if_my_workstation_is_locked.html which got me most of the way to where I need to be, I want to detect both logout and login events, with some changes to the script provided above I ended up with 2 problems 1) I was able to detect the logout but not the login 2) it was a resource hog at 50% cpu usage (presumably because of the while 1:) here is what I have now:
import time, ctypes, Skype4Py
skype = Skype4Py.Skype()
def restoreMessages(messages):
   #for now lets just deal with skype, we'll add the others later
   skype.Profile('MOOD_TEXT', messages['skype'])
def setMessages(message):
   #for now lets just deal with skype, we'll add the others later
   skype.Profile('MOOD_TEXT', message)
user32 = ctypes.windll.User32
OpenDesktop = user32.OpenDesktopA
SwitchDesktop = user32.SwitchDesktop
DESKTOP_SWITCHDESKTOP = 0x0100
locked = False
try:
   while 1:
     hDesktop = OpenDesktop ("default", 0, False, DESKTOP_SWITCHDESKTOP)
     result = SwitchDesktop (hDesktop)
     if result:
       if locked:
           locked = False
           restoreMessages(messages)
     else:
       locked = True
       messages = {'skype':skype.Profile('MOOD_TEXT')}
       setMessages('AFK - Away From Keyboard')
       time.sleep(2)
except:
   pass

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to