コード例 #1
0
    def process_event(self):
        try:
            # Need the timeout so that thread terminates properly when exiting.
            (process_name, image_data, username,
             event) = self.q.get(timeout=0.05)

            # LOG STUFF
            eventlisttmp = [
                # Date
                to_unicode(time.strftime('%Y%m%d')),
                # Time
                to_unicode(time.strftime('%H%M')),
                # Process Name
                # (full path on windows, just name on linux)
                to_unicode(process_name).replace(self.field_sep, '[sep_key]'),
                # Window Handle
                to_unicode(event.Window),
                # Username
                to_unicode(username).replace(self.field_sep, '[sep_key]'),
                # Window Title
                to_unicode(event.WindowName).replace(self.field_sep,
                                                     '[sep_key]'),
                # Window Resolution
                to_unicode(resolution)
            ]
            limit = self.subsettings['General']['Limit Keylog Field Size']
            eventlisttmp.append(
                to_unicode(
                    self.parse_event_value(process_name, username, event)))
            if (self.eventlist[:IEVENTLISTSIZE - 1]
                    == eventlisttmp[:IEVENTLISTSIZE -
                                    1]) and (limit == 0 or
                                             (len(self.eventlist[-1]) +
                                              len(eventlisttmp[-1])) < limit):

                # Append char to log.
                self.eventlist[-1] = self.eventlist[-1] + eventlisttmp[-1]
            else:
                self.write_to_logfile()
                self.eventlist = eventlisttmp

            # IMAGE STUFF
            process_name = self.filter.sub(r'__', process_name)
            savefilename = os.path.join(
                self.settings['General']['Log Directory'],
                self.subsettings['General']['Log Subdirectory'],
                self.last_image_name)
            qualitysetting = self.subsettings['General']['Click Image Quality']
            image_data.save(savefilename, quality=qualitysetting)
        except Empty:
            # Check if the minute has rolled over, if so, write it out.
            if self.eventlist[:2] != range(2) and \
                self.eventlist[:2] != [to_unicode(time.strftime('%Y%m%d')),
                                       to_unicode(time.strftime('%H%M'))]:
                self.write_to_logfile()
                self.eventlist = IELIST  # Blank it out after writing.
        except:
            self.logger.debug('Error writing image to file', exc_info=True)
コード例 #2
0
    def process_event(self):
        try:
            # Need the timeout so that thread terminates properly when exiting.
            (process_name, image_data, username, event) = self.q.get(
                timeout=0.05)

            # LOG STUFF
            eventlisttmp = [
                # Date
                to_unicode(time.strftime('%Y%m%d')),
                # Time
                to_unicode(time.strftime('%H%M')),
                # Process Name
                # (full path on windows, just name on linux)
                to_unicode(process_name).replace(self.field_sep,
                                                 '[sep_key]'),
                # Window Handle
                to_unicode(event.Window),
                # Username
                to_unicode(username).replace(self.field_sep,
                                             '[sep_key]'),
                # Window Title
                to_unicode(event.WindowName).replace(self.field_sep, '[sep_key]'),
                # Window Resolution
                to_unicode(resolution)]
            limit = self.subsettings['General']['Limit Keylog Field Size']
            eventlisttmp.append(to_unicode(self.parse_event_value(process_name,
                                                                  username,
                                                                  event)))
            if (self.eventlist[:IEVENTLISTSIZE-1] == eventlisttmp[:IEVENTLISTSIZE-1]) and (limit == 0 or (len(self.eventlist[-1]) + len(eventlisttmp[-1])) < limit):

                # Append char to log.
                self.eventlist[-1] = self.eventlist[-1] + eventlisttmp[-1]
            else:
                self.write_to_logfile()
                self.eventlist = eventlisttmp

            # IMAGE STUFF
            process_name = self.filter.sub(r'__', process_name)
            savefilename = os.path.join(
                self.settings['General']['Log Directory'],
                self.subsettings['General']['Log Subdirectory'],
                self.last_image_name)
            qualitysetting = self.subsettings['General']['Click Image Quality']
            image_data.save(savefilename, quality=qualitysetting)
        except Empty:
            # Check if the minute has rolled over, if so, write it out.
            if self.eventlist[:2] != range(2) and \
                self.eventlist[:2] != [to_unicode(time.strftime('%Y%m%d')),
                                       to_unicode(time.strftime('%H%M'))]:
                self.write_to_logfile()
                self.eventlist = IELIST  # Blank it out after writing.
        except:
            self.logger.debug('Error writing image to file',
                              exc_info=True)
コード例 #3
0
    def write_to_logfile(self):
        '''Write the latest eventlist to logfile in one delimited line.
        '''

        if self.eventlist[:7] != range(7):
            try:
                line = to_unicode(self.field_sep).join(self.eventlist)
                self.logger.info(line)
            except:
                self.logger.debug(to_unicode(self.eventlist), exc_info=True)
                pass  # keep going, even though this doesn't get logged...
コード例 #4
0
 def write_to_logfile(self):
     '''Write the latest eventlist to logfile in one delimited line.
     '''
     
     if self.eventlist[:7] != range(7):
         try:
             line = to_unicode(self.field_sep).join(self.eventlist)
             self.logger.info(line)
         except:
             self.logger.debug(to_unicode(self.eventlist), 
                 exc_info=True)
             pass # keep going, even though this doesn't get logged...
コード例 #5
0
    def process_event(self):
        try:
            # Need the timeout so that thread terminates properly when exiting
            event = self.q.get(timeout=0.05)
            # Ahora quiero guardar en el log el tiempo en que se aprieta y
            # suelta una tecla.
            process_name = self.get_process_name(event)
            # See if the program is in the no-log list.
            loggable = self.needs_logging(event, process_name)
            if not loggable:
                self.logger.debug("not loggable, we are outta here\n")
                return
            try:
                self.logger.debug("loggable, lets log it. key: %s" %
                                  to_unicode(event.Key))
            except AttributeError:
                # Era un mouse event.
                return

            username = get_username()

            self.sst_q.put((process_name, username, event))

        except Empty:
            pass  # let's keep iterating
        except:
            self.logger.debug("some exception was caught in "
                              "the logwriter loop...\nhere it is:\n",
                              exc_info=True)
            pass  # let's keep iterating
コード例 #6
0
    def capture_image(self, savefilename):

        screensize = self.get_screen_size()

        # The cropbox will take care of making sure our image is within
        # screen boundaries.
        cropbox = CropBox(topleft=Point(0, 0), bottomright=screensize, min=Point(0, 0), max=screensize)

        self.logger.debug(cropbox)

        if os.name == "posix":

            screengrab = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, screensize.x, screensize.y)

            screengrab.get_from_drawable(
                gtk.gdk.get_default_root_window(), gtk.gdk.colormap_get_system(), 0, 0, 0, 0, screensize.x, screensize.y
            )

            save_options_dict = {}
            img_format = self.subsettings["General"]["Screenshot Image Format"]
            img_format.lower()
            img_quality = to_unicode(self.subsettings["General"]["Screenshot Image Quality"])
            if img_format in IMG_SET:
                self.subsettings["General"]["Screenshot Image Format"] = "jpeg"
                save_options_dict = {"quality": img_quality}

            screengrab.save(savefilename, self.subsettings["General"]["Screenshot Image Format"], save_options_dict)

        if os.name == "nt":
            image_data = ImageGrab.grab(
                (cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y)
            )
            image_data.save(savefilename, quality=self.subsettings["General"]["Screenshot Image Quality"])
コード例 #7
0
    def get_process_name(self, event):
        '''
            Acquire the process name from the window handle for use in the log
            filename.
        '''

        if os.name == 'nt':
            hwnd = event.Window
            try:
                threadpid, procpid = win32process.GetWindowThreadProcessId(
                    hwnd)

                # PROCESS_QUERY_INFORMATION (0x0400) or
                # PROCESS_VM_READ (0x0010) or PROCESS_ALL_ACCESS (0x1F0FFF)

                mypyproc = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS,
                                                False, procpid)
                procname = win32process.GetModuleFileNameEx(mypyproc, 0)
                return procname
            except:
                # this happens frequently enough - when the last event caused
                # the closure of the window or program
                # so we just return a nice string and don't worry about it.
                return "noprocname"
        elif os.name == 'posix':
            return to_unicode(event.WindowProcName)
コード例 #8
0
    def process_event(self):
        try:
            event = self.q.get(
                timeout=0.05
            )  #need the timeout so that thread terminates properly when exiting
            if not event.MessageName.startswith('key down'):
                self.logger.debug('not a useful event')
                return
            process_name = self.get_process_name(event)
            loggable = self.needs_logging(
                event,
                process_name)  # see if the program is in the no-log list.
            if not loggable:
                self.logger.debug("not loggable, we are outta here\n")
                return
            self.logger.debug("loggable, lets log it. key: %s" % \
                to_unicode(event.Key))

            username = self.get_username()

            self.sst_q.put((process_name, username, event))

        except Empty:
            pass  #let's keep iterating
        except:
            self.logger.debug(
                "some exception was caught in "
                "the logwriter loop...\nhere it is:\n",
                exc_info=True)
            pass  #let's keep iterating
コード例 #9
0
    def process_event(self):
        try:
            # Need the timeout so that thread terminates properly when exiting
            event = self.q.get(timeout=0.05)
            # Ahora quiero guardar en el log el tiempo en que se aprieta y
            # suelta una tecla.
            process_name = self.get_process_name(event)
            # See if the program is in the no-log list.
            loggable = self.needs_logging(event, process_name)
            if not loggable:
                self.logger.debug("not loggable, we are outta here\n")
                return
            try:
                self.logger.debug("loggable, lets log it. key: %s" %
                                  to_unicode(event.Key))
            except AttributeError:
                # Era un mouse event.
                return

            username = get_username()

            self.sst_q.put((process_name, username, event))

        except Empty:
            pass  # let's keep iterating
        except:
            self.logger.debug(
                "some exception was caught in "
                "the logwriter loop...\nhere it is:\n",
                exc_info=True)
            pass  # let's keep iterating
コード例 #10
0
    def get_process_name(self, event):
        '''
            Acquire the process name from the window handle for use in the log
            filename.
        '''
        if os.name == 'nt':
            hwnd = event.Window
            try:
                threadpid, procpid = win32process.GetWindowThreadProcessId(
                    hwnd)

                # PROCESS_QUERY_INFORMATION (0x0400) or
                # PROCESS_VM_READ (0x0010) or PROCESS_ALL_ACCESS (0x1F0FFF)

                mypyproc = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS,
                                                False, procpid)
                procname = win32process.GetModuleFileNameEx(mypyproc, 0)
                return procname
            except:
                # this happens frequently enough - when the last event caused
                # the closure of the window or program
                # so we just return a nice string and don't worry about it.
                return "noprocname"
        elif os.name == 'posix':
            return to_unicode(event.WindowProcName)
コード例 #11
0
    def process_event(self):
        try:
            (process_name, username, event) = self.q.get(
                timeout=0.05
            )  #need the timeout so that thread terminates properly when exiting

            eventlisttmp = [
                to_unicode(time.strftime('%Y%m%d')),  # date
                #JA Edit
                #to_unicode(time.strftime('%H%M')), # time
                to_unicode(time.time()),  # time
                to_unicode(process_name).replace(
                    self.field_sep, '[sep_key]'
                ),  # process name (full path on windows, just name on linux)
                to_unicode(event.Window),  # window handle
                to_unicode(username).replace(self.field_sep,
                                             '[sep_key]'),  # username
                to_unicode(event.WindowName).replace(self.field_sep,
                                                     '[sep_key]')
            ]  # window title

            if self.subsettings['General']['Log Key Count'] == True:
                eventlisttmp.append('1')
            eventlisttmp.append(to_unicode(self.parse_event_value(event)))

            if (self.eventlist[:6] == eventlisttmp[:6]) and \
                (self.subsettings['General']['Limit Keylog Field Size'] == 0 or \
                (len(self.eventlist[-1]) + len(eventlisttmp[-1])) < self.settings['General']['Limit Keylog Field Size']):

                #append char to log
                self.eventlist[-1] = self.eventlist[-1] + eventlisttmp[-1]
                # increase stroke count
                if self.subsettings['General']['Log Key Count'] == True:
                    self.eventlist[-2] = str(int(self.eventlist[-2]) + 1)
            else:
                self.write_to_logfile()
                self.eventlist = eventlisttmp
        except Empty:
            # check if the minute has rolled over, if so, write it out
            #JA edit -- may want to change this to buffer more on one line if this becomes a problem
            if self.eventlist[:2] != range(2) and \
                self.eventlist[:2] != [to_unicode(time.strftime('%Y%m%d')),
                to_unicode(time.strftime('%H%M'))]:
                self.write_to_logfile()
                self.eventlist = range(7)  # blank it out after writing

        except:
            self.logger.debug(
                "some exception was caught in the "
                "logwriter loop...\nhere it is:\n",
                exc_info=True)
            pass  #let's keep iterating
コード例 #12
0
    def process_event(self):
        try:
            # Need the timeout so that thread terminates properly when exiting.
            (process_name, username, event) = self.q.get(timeout=0.05)

            eventlisttmp = [
                # date
                to_unicode(time.strftime('%Y%m%d')),
                # time
                to_unicode(time.strftime('%H%M')),
                # process name
                # (full path on windows, just name on linux)
                to_unicode(process_name).replace(self.field_sep, '[sep_key]'),
                # window handle
                to_unicode(event.Window),
                # username
                to_unicode(username).replace(self.field_sep, '[sep_key]'),
                # window title
                to_unicode(event.WindowName).replace(self.field_sep,
                                                     '[sep_key]')
            ]

            if self.subsettings['General']['Log Key Count'] is True:
                eventlisttmp.append('1')
            eventlisttmp.append(to_unicode(self.parse_event_value(event)))

            eventlists_are_equal = self.eventlist[:EVENTLISTSIZE-1] == \
                eventlisttmp[:EVENTLISTSIZE-1]
            if (self.subsettings['General']['Limit Keylog Field Size'] == 0 or
                    (len(self.eventlist[-1]) + len(eventlisttmp[-1])) <
                    self.settings['General']['Limit Keylog Field Size']) and \
                    eventlists_are_equal:

                # Append char to log.
                self.eventlist[-1] = self.eventlist[-1] + eventlisttmp[-1]
                # increase stroke count
                if self.subsettings['General']['Log Key Count'] is True:
                    self.eventlist[-2] = str(int(self.eventlist[-2]) + 1)
            else:
                self.write_to_logfile()
                self.eventlist = eventlisttmp
        except Empty:
            # Check if the minute has rolled over, if so, write it out
            if self.eventlist[:2] != range(2) and \
                self.eventlist[:2] != [to_unicode(time.strftime('%Y%m%d')),
                                       to_unicode(time.strftime('%H%M'))]:
                self.write_to_logfile()
                self.eventlist = ELIST  # blank it out after writing
        except:
            self.logger.debug(
                "some exception was caught in the logwriter loop...\nhere it is:\n",
                exc_info=True)
コード例 #13
0
    def process_event(self):
        try:
            # Need the timeout so that thread terminates properly when exiting.
            (process_name, username, event) = self.q.get(timeout=0.05)

            eventlisttmp = [
                # date
                to_unicode(time.strftime('%Y%m%d')),
                # time
                to_unicode(time.strftime('%H%M')),
                # process name
                # (full path on windows, just name on linux)
                to_unicode(process_name).replace(self.field_sep,
                                                 '[sep_key]'),
                # window handle
                to_unicode(event.Window),
                # username
                to_unicode(username).replace(self.field_sep,
                                             '[sep_key]'),
                # window title
                to_unicode(event.WindowName).replace(self.field_sep, '[sep_key]')]

            if self.subsettings['General']['Log Key Count'] is True:
                eventlisttmp.append('1')
            eventlisttmp.append(to_unicode(self.parse_event_value(event)))

            eventlists_are_equal = self.eventlist[:EVENTLISTSIZE-1] == \
                eventlisttmp[:EVENTLISTSIZE-1]
            if (self.subsettings['General']['Limit Keylog Field Size'] == 0 or
                    (len(self.eventlist[-1]) + len(eventlisttmp[-1])) <
                    self.settings['General']['Limit Keylog Field Size']) and \
                    eventlists_are_equal:

                # Append char to log.
                self.eventlist[-1] = self.eventlist[-1] + eventlisttmp[-1]
                # increase stroke count
                if self.subsettings['General']['Log Key Count'] is True:
                    self.eventlist[-2] = str(int(self.eventlist[-2]) + 1)
            else:
                self.write_to_logfile()
                self.eventlist = eventlisttmp
        except Empty:
            # Check if the minute has rolled over, if so, write it out
            if self.eventlist[:2] != range(2) and \
                self.eventlist[:2] != [to_unicode(time.strftime('%Y%m%d')),
                                       to_unicode(time.strftime('%H%M'))]:
                self.write_to_logfile()
                self.eventlist = ELIST  # blank it out after writing
        except:
            self.logger.debug("some exception was caught in the logwriter loop...\nhere it is:\n", exc_info=True)
コード例 #14
0
ファイル: backends.py プロジェクト: Sdlearn/pyworklogger
 def process_event(self):
     try:
         (process_name, username, event) = self.q.get(timeout=0.05) #need the timeout so that thread terminates properly when exiting
         
         window_id = event.Window
         # only fetch window title if window id has changed:
         if not self.window_id == window_id:
             self.window_id = window_id
             self.window_title = self.get_window_name_from_id(window_id)
             
         eventlisttmp = ['hej',detailedlogwriter.to_unicode(detailedlogwriter.time.strftime('%Y%m%d')), # date
             detailedlogwriter.to_unicode(time.strftime('%H%M')), # time
             detailedlogwriter.to_unicode(process_name).replace(self.field_sep,
                 '[sep_key]'), # process name (full path on windows, just name on linux)
             detailedlogwriter.to_unicode(self.window_id), # window handle
             detailedlogwriter.to_unicode(username).replace(self.field_sep, 
                 '[sep_key]'), # username
             
             detailedlogwriter.to_unicode(self.window_title).replace(self.field_sep, 
                 '[sep_key]')] # window title
                         
         if self.subsettings['General']['Log Key Count'] == True:
             eventlisttmp.append('1')
         eventlisttmp.append(to_unicode(self.parse_event_value(event)))
             
         if (self.eventlist[:6] == eventlisttmp[:6]) and \
             (self.subsettings['General']['Limit Keylog Field Size'] == 0 or \
             (len(self.eventlist[-1]) + len(eventlisttmp[-1])) < self.settings['General']['Limit Keylog Field Size']):
             
             #append char to log
             self.eventlist[-1] = self.eventlist[-1] + eventlisttmp[-1]
             # increase stroke count
             if self.subsettings['General']['Log Key Count'] == True:
                 self.eventlist[-2] = str(int(self.eventlist[-2]) + 1)
         else:
             self.write_to_logfile()
             self.eventlist = eventlisttmp
     except Empty:
         # check if the minute has rolled over, if so, write it out
         if self.eventlist[:2] != range(2) and \
             self.eventlist[:2] != [detailedlogwriter.to_unicode(time.strftime('%Y%m%d')), 
             detailedlogwriter.to_unicode(time.strftime('%H%M'))]:
             self.write_to_logfile()
             self.eventlist = range(7) # blank it out after writing
         
     except:
         self.logger.debug("some exception was caught in the "
             "logwriter loop...\nhere it is:\n", exc_info=True)
         pass #let's keep iterating
コード例 #15
0
ファイル: timedscreenshot.py プロジェクト: magsilva/glimpse
    def capture_image(self, savefilename):
        
        screensize = self.get_screen_size()

        # The cropbox will take care of making sure our image is within
        # screen boundaries.
        cropbox = CropBox(topleft=Point(0,0),
                          bottomright=screensize,
                          min=Point(0,0),
                          max=screensize)
        
        self.logger.debug(cropbox)
                
        if os.name == 'posix':
            
            screengrab = gtk.gdk.Pixbuf(
                gtk.gdk.COLORSPACE_RGB,
                False,
                8,
                screensize.x,
                screensize.y)
            
            screenshot = screengrab.get_from_drawable(
                gtk.gdk.get_default_root_window(),
                gtk.gdk.colormap_get_system(),
                0, 0, 0, 0,
                screensize.x,
                screensize.y)
            
            if (screenshot != None):
               save_options_dict = {}
               if self.subsettings['General']['Screenshot Image Format'].lower() in ['jpg','jpeg']:
                   self.subsettings['General']['Screenshot Image Format'] = 'jpeg'
                   save_options_dict = {'quality':to_unicode(self.subsettings['General']['Screenshot Image Quality'])}
            
               screenshot.save(savefilename, 
                    self.subsettings['General']['Screenshot Image Format'],
                    save_options_dict)
            else
               print "Unable to get screenshot"

        if os.name == 'nt':
            image_data = ImageGrab.grab((cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y))
            if (image_data != None):
                 image_data.save(savefilename, 
                      quality=self.subsettings['General']['Screenshot Image Quality'])
            else
                 print "Unable to get screenshot"
コード例 #16
0
ファイル: timedscreenshot.py プロジェクト: jedagda/eceld
    def capture_image(self, savefilename):

        screensize = self.get_screen_size()

        # The cropbox will take care of making sure our image is within
        # screen boundaries.
        cropbox = CropBox(topleft=Point(0, 0),
                          bottomright=screensize,
                          min=Point(0, 0),
                          max=screensize)

        self.logger.debug(cropbox)

        if os.name == 'posix':

            screengrab = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
                                        screensize.x, screensize.y)

            screengrab.get_from_drawable(gtk.gdk.get_default_root_window(),
                                         gtk.gdk.colormap_get_system(), 0, 0,
                                         0, 0, screensize.x, screensize.y)

            save_options_dict = {}
            if self.subsettings['General']['Screenshot Image Format'].lower(
            ) in ['jpg', 'jpeg']:
                self.subsettings['General']['Screenshot Image Format'] = 'jpeg'
                save_options_dict = {
                    'quality':
                    to_unicode(self.subsettings['General']
                               ['Screenshot Image Quality'])
                }

            screengrab.save(
                savefilename,
                self.subsettings['General']['Screenshot Image Format'],
                save_options_dict)

        if os.name == 'nt':
            image_data = ImageGrab.grab(
                (cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x,
                 cropbox.bottomright.y))
            image_data.save(savefilename,
                            quality=self.subsettings['General']
                            ['Screenshot Image Quality'])
コード例 #17
0
 def print_event(self, event):
     '''
         Prints the event.
         We need this because pyhook's event don't have a default __str__
         method, so we check for os type, and make it work on windows.
     '''
     if os.name == 'posix':
         return to_unicode(event)
     if os.name == 'nt':
         str_tpl = "Window: %s\n" + \
                   "Window Handle: %s\n" + \
                   "Window's Process Name: %s\n" + \
                   "Position: %s\n" + \
                   "MessageName: %s\n"
         return str_tpl % (
             to_unicode(event.Window), to_unicode(event.WindowName),
             to_unicode(self.get_process_name(event)),
             to_unicode(event.Position), to_unicode(event.MessageName))
コード例 #18
0
    def process_event(self):
        try:
            event = self.q.get(
                timeout=0.05
            )  #need the timeout so that thread terminates properly when exiting
            print("HERE: GOT AN EVENT!: " + event.MessageName)
            if not event.MessageName.startswith('key down'):
                print("HERE: NOT USEFUL!")
                self.logger.debug('not a useful event')
                return
            print("HERE: AFTER GOT EVENT")
            process_name = self.get_process_name(event)
            print("HERE: AFTER PROCESS NAME: " + str(process_name))
            loggable = self.needs_logging(
                event,
                process_name)  # see if the program is in the no-log list.
            print("HERE: AFTER NEEDS LOGGING" + str(loggable))
            if not loggable:
                print("HERE: NOT LOGGABLE!")
                self.logger.debug("not loggable, we are outta here\n")
                return
            print("HERE: LET'S LOG IT KEY: " + event.Key)
            self.logger.debug("loggable, lets log it. key: %s" % \
                to_unicode(event.Key))

            username = self.get_username()

            self.sst_q.put((process_name, username, event))

        except Empty:
            pass  #let's keep iterating
        except:
            self.logger.debug(
                "some exception was caught in "
                "the logwriter loop...\nhere it is:\n",
                exc_info=True)
            pass  #let's keep iterating
コード例 #19
0
 def process_event(self):
     try:
         event = self.q.get(timeout=0.05) #need the timeout so that thread terminates properly when exiting
         if not event.MessageName.startswith('key down'):
             self.logger.debug('not a useful event')
             return
         process_name = self.get_process_name(event)
         loggable = self.needs_logging(event, process_name)  # see if the program is in the no-log list.
         if not loggable:
             self.logger.debug("not loggable, we are outta here\n")
             return
         self.logger.debug("loggable, lets log it. key: %s" % \
             to_unicode(event.Key))
         
         username = self.get_username()
         
         self.sst_q.put((process_name, username, event))
         
     except Empty:
         pass #let's keep iterating
     except:
         self.logger.debug("some exception was caught in "
             "the logwriter loop...\nhere it is:\n", exc_info=True)
         pass #let's keep iterating
コード例 #20
0
 def print_event(self, event):
     '''
         Prints the event.
         We need this because pyhook's event don't have a default __str__
         method, so we check for os type, and make it work on windows.
     '''
     if os.name == 'posix':
         return to_unicode(event)
     if os.name == 'nt':
         str_tpl = "Window: %s\n" + \
                   "Window Handle: %s\n" + \
                   "Window's Process Name: %s\n" + \
                   "Position: %s\n" + \
                   "MessageName: %s\n"
         return str_tpl % (to_unicode(event.Window),
                           to_unicode(event.WindowName),
                           to_unicode(self.get_process_name(event)),
                           to_unicode(event.Position),
                           to_unicode(event.MessageName))
コード例 #21
0
    def capture_image(self, savefilename):
        try:
            screensize = self.get_screen_size()

            # The cropbox will take care of making sure our image is within
            # screen boundaries.
            cropbox = CropBox(topleft=Point(0, 0),
                              bottomright=screensize,
                              min=Point(0, 0),
                              max=screensize)

            self.logger.debug(cropbox)

            if os.name == 'posix':
                AllPlanes = 0xFFFFFFFF
                # JA: we want to capture the entire screen
                # we can't use PIL imagegrab because it's win/mac
                # we can't use gtk because it's out of date
                # so we use PIL get_image instead
                # however, this requires xhost +  because we grab the display using xlib
                cropbox = CropBox(topleft=Point(0, 0),
                                  bottomright=screensize,
                                  min=Point(0, 0),
                                  max=screensize)
                raw = self.rootwin.get_image(cropbox.topleft.x,
                                             cropbox.topleft.y, cropbox.size.x,
                                             cropbox.size.y, X.ZPixmap,
                                             AllPlanes)
                image_data = Image.frombytes("RGBX",
                                             (cropbox.size.x, cropbox.size.y),
                                             raw.data, "raw",
                                             "BGRX").convert("RGB")

                save_options_dict = {}
                if self.subsettings['General'][
                        'Screenshot Image Format'].lower() in ['jpg', 'jpeg']:
                    self.subsettings['General'][
                        'Screenshot Image Format'] = 'jpeg'
                    save_options_dict = {
                        'quality':
                        to_unicode(self.subsettings['General']
                                   ['Screenshot Image Quality'])
                    }

                image_data.save(
                    savefilename,
                    self.subsettings['General']['Screenshot Image Format'])

            if os.name == 'nt':
                image_data = ImageGrab.grab(
                    (cropbox.topleft.x, cropbox.topleft.y,
                     cropbox.bottomright.x, cropbox.bottomright.y))
                image_data.save(savefilename,
                                quality=self.subsettings['General']
                                ['Screenshot Image Quality'])

        except error.BadDrawable:
            self.logger.error(
                "bad drawable when attempting to get an image!  Closed the window?"
            )
        except error.BadMatch:
            self.logger.error(
                "bad match when attempting to get an image! probably specified an area outside the window (too big?)"
            )
        except error.BadValue:
            self.logger.error(
                "getimage: bad value error - tell me about this one, I've not managed to make it happen yet"
            )
        except Exception:
            self.logger.error('Error writing image to file', exc_info=True)