pykeylogger and dual screen

Help
2010-06-03
2013-05-28
  • Hello,

    impossible to have screenshot from a second monitor in dual view. Is there a clue where and what can i modify in source code to ba able to screenshot everywhere?

    thaks

     
  • nanotube
    nanotube
    2010-06-04

    Hi,

    I am assuming you're running windows, since multi-screen setups work fine on linux…

    See this forum thread for possibly-helpful hints:
    https://sourceforge.net/projects/pykeylogger/forums/forum/493190/topic/3478561
    and let me know if any of that actually works. (as i note in that thread, i don't have a dual-screen windows setup to try this on)…

     
  • Yes it is a windows system !

    thanks !

    i've finally found a workaround without PIL for the capture googling. I will post the modification after the week end.

     
  • Here is a fully functional code. Only thing to know is that if one screen is smaller than the other(s) onclick image near to the bottom will have a black part, but to me this is not really a big problem .

    here is two patches

    you might  clean up a little the code, but this work like this, hope you will be able to integrate this waiting a PIL release that never comes with dual screen support.

    --- timedscreenshot.py  2010-06-03 14:17:56.609375000 -0400
    +++ timedscreenshot.py.old      2009-11-17 11:51:34.000000000 -0500
    @@ -34,9 +34,7 @@
     if os.name == 'nt':
         import win32api
    -    import Image, ImageGrab
    -    import win32gui,  win32ui,  win32con, win32api
    -    hwnd = win32gui.GetDesktopWindow()
    +    import ImageGrab
     elif os.name == 'posix':
         import gtk
     else:
    @@ -153,32 +151,7 @@
                         save_options_dict)
             if os.name == 'nt':
    -            #image_data = ImageGrab.grab((cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y))
    -            SM_XVIRTUALSCREEN = 76
    -            SM_YVIRTUALSCREEN = 77
    -            SM_CXVIRTUALSCREEN = 78
    -            SM_CYVIRTUALSCREEN = 79
    -            w = vscreenwidth = win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN)
    -            h = vscreenheigth = win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN)
    -            l = vscreenx = win32api.GetSystemMetrics(SM_XVIRTUALSCREEN)
    -            t = vscreeny = win32api.GetSystemMetrics(SM_YVIRTUALSCREEN)
    -            r = l + w
    -            b = t + h
    -            hwndDC = win32gui.GetWindowDC(hwnd)
    -            mfcDC  = win32ui.CreateDCFromHandle(hwndDC)
    -            saveDC = mfcDC.CreateCompatibleDC()
    -            saveBitMap = win32ui.CreateBitmap()
    -            saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
    -            saveDC.SelectObject(saveBitMap)
    -            saveDC.BitBlt((0, 0), (w, h),  mfcDC,  (l, t),  win32con.SRCCOPY)
    -            bmpinfo = saveBitMap.GetInfo()
    -            #print bmpinfo
    -            #print savefilename
    -            bmpstr = saveBitMap.GetBitmapBits(True)
    -            image_data = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
    +           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'])
    
    --- timedscreenshot.py  2010-06-03 14:17:56.609375000 -0400
    +++ timedscreenshot.py.old      2009-11-17 11:51:34.000000000 -0500
    @@ -34,9 +34,7 @@
     if os.name == 'nt':
         import win32api
    -    import Image, ImageGrab
    -    import win32gui,  win32ui,  win32con, win32api
    -    hwnd = win32gui.GetDesktopWindow()
    +    import ImageGrab
     elif os.name == 'posix':
         import gtk
     else:
    @@ -153,32 +151,7 @@
                         save_options_dict)
             if os.name == 'nt':
    -            #image_data = ImageGrab.grab((cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y))
    -            SM_XVIRTUALSCREEN = 76
    -            SM_YVIRTUALSCREEN = 77
    -            SM_CXVIRTUALSCREEN = 78
    -            SM_CYVIRTUALSCREEN = 79
    -            w = vscreenwidth = win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN)
    -            h = vscreenheigth = win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN)
    -            l = vscreenx = win32api.GetSystemMetrics(SM_XVIRTUALSCREEN)
    -            t = vscreeny = win32api.GetSystemMetrics(SM_YVIRTUALSCREEN)
    -            r = l + w
    -            b = t + h
    -            hwndDC = win32gui.GetWindowDC(hwnd)
    -            mfcDC  = win32ui.CreateDCFromHandle(hwndDC)
    -            saveDC = mfcDC.CreateCompatibleDC()
    -            saveBitMap = win32ui.CreateBitmap()
    -            saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
    -            saveDC.SelectObject(saveBitMap)
    -            saveDC.BitBlt((0, 0), (w, h),  mfcDC,  (l, t),  win32con.SRCCOPY)
    -            bmpinfo = saveBitMap.GetInfo()
    -            #print bmpinfo
    -            #print savefilename
    -            bmpstr = saveBitMap.GetBitmapBits(True)
    -            image_data = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
    +           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'])
    
     
  • nanotube
    nanotube
    2010-06-04

    Hi

    Thanks for the patches! I'll look into it when i have a bit of time.

    A few notes right off the bat, though:

    first, it seems that the two patches are identical…? did you maybe mean to include two distinct ones? :)

    second, it seems that old and new are reversed? but i suppose i can deal with that…

    Thanks!

     
  • Hello,

    yes the patch about the same for the two fles.

    Yes sorry i often reverse the two files when i create a patch but the patch command is slever ;) if you have any problem patching i 'll make new ones ;)

    Thanks to you !

     
  • nanotube
    nanotube
    2010-06-14

    Hi,
    Just to double-check something - have you tested imagegrab from the latest PIL, version 1.1.7, and it still doesn't work?

     
  • Hello i have test only with the last  version available when i first open this thread . which is : PIL-1.1.7.win32-py2.6
    and does not work

     
  • nanotube
    nanotube
    2010-06-15

    ah ok, thanks for the info :)

     
  • CAOffice
    CAOffice
    2012-01-04

    I know I sound silly here, but I was wondering how I should go about applying this patch. I downloaded Patch for windows, but I just can't seem to get it working. I'm not sure if I just messed up the formatting of the file, or if I'm not typing the command correctly or what.
    Thanks!

     
  • Finally i took the time to double check my patch, here are the two files, the patch are very similar but you were right i pasted two time the same file, sorry for that :

    --- onclickimagecapture.py.old  2009-11-17 12:51:34.000000000 -0500
    +++ onclickimagecapture.py      2010-06-03 15:53:22.000000000 -0400
    @@ -36,6 +36,8 @@
     if os.name == 'nt':
         import win32api, win32con, win32process
         import ImageGrab
    +    import win32gui,  win32ui
    +    hwnd = win32gui.GetDesktopWindow()
     elif os.name == 'posix':
         from Xlib import X, XK, display, error
         from Xlib.ext import record
    @@ -121,7 +123,31 @@
                             exc_info = True)
             if os.name == 'nt':
    -            image_data = ImageGrab.grab((cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y))
    +            #image_data = ImageGrab.grab((cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y))
    +            SM_XVIRTUALSCREEN = 76
    +            SM_YVIRTUALSCREEN = 77
    +            SM_CXVIRTUALSCREEN = 78
    +            SM_CYVIRTUALSCREEN = 79
    +            w = vscreenwidth = win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN)
    +            h = vscreenheigth = win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN)
    +            l = vscreenx = win32api.GetSystemMetrics(SM_XVIRTUALSCREEN)
    +            t = vscreeny = win32api.GetSystemMetrics(SM_YVIRTUALSCREEN)
    +            r = l + w
    +            b = t + h
    +            hwndDC = win32gui.GetWindowDC(hwnd)
    +            mfcDC  = win32ui.CreateDCFromHandle(hwndDC)
    +            saveDC = mfcDC.CreateCompatibleDC()
    +            saveBitMap = win32ui.CreateBitmap()
    +            saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
    +            saveDC.SelectObject(saveBitMap)
    +            saveDC.BitBlt((0, 0), (w, h),  mfcDC,  (l, t),  win32con.SRCCOPY)
    +            bmpinfo = saveBitMap.GetInfo()
    +            #print bmpinfo
    +            #print savefilename
    +            bmpstr = saveBitMap.GetBitmapBits(True)
    +#            image_data = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
    +            image_data = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
    +            image_data = image_data.crop((cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y))
                 return image_data
         def get_screen_size(self):
    @@ -133,8 +159,22 @@
                 return Point(self.rootwin.get_geometry().width,
                              self.rootwin.get_geometry().height)
             if os.name == 'nt':
    -            return Point(win32api.GetSystemMetrics(0),
    -                         win32api.GetSystemMetrics(1))
    +            #jpp
    +            SM_XVIRTUALSCREEN = 76
    +            SM_YVIRTUALSCREEN = 77
    +            SM_CXVIRTUALSCREEN = 78
    +            SM_CYVIRTUALSCREEN = 79
    +            w = vscreenwidth = win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN)
    +            h = vscreenheigth = win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN)
    +            l = vscreenx = win32api.GetSystemMetrics(SM_XVIRTUALSCREEN)
    +            t = vscreeny = win32api.GetSystemMetrics(SM_YVIRTUALSCREEN)
    +            r = l + w
    +            b = t + h
    +#            return Point(win32api.GetSystemMetrics(0),
    +#                         win32api.GetSystemMetrics(1))
    +            return Point(r,
    +                         b)
    +
         def get_username(self):
             '''Try a few different environment vars to get the username.'''
    
    --- timedscreenshot.py.old      2009-11-17 12:51:34.000000000 -0500
    +++ timedscreenshot.py  2010-06-03 15:17:56.000000000 -0400
    @@ -34,7 +34,9 @@
     if os.name == 'nt':
         import win32api
    -    import ImageGrab
    +    import Image, ImageGrab
    +    import win32gui,  win32ui,  win32con, win32api
    +    hwnd = win32gui.GetDesktopWindow()
     elif os.name == 'posix':
         import gtk
     else:
    @@ -151,7 +153,32 @@
                         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 = ImageGrab.grab((cropbox.topleft.x, cropbox.topleft.y, cropbox.bottomright.x, cropbox.bottomright.y))
    +            #ajout JPP
    +            SM_XVIRTUALSCREEN = 76
    +            SM_YVIRTUALSCREEN = 77
    +            SM_CXVIRTUALSCREEN = 78
    +            SM_CYVIRTUALSCREEN = 79
    +            w = vscreenwidth = win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN)
    +            h = vscreenheigth = win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN)
    +            l = vscreenx = win32api.GetSystemMetrics(SM_XVIRTUALSCREEN)
    +            t = vscreeny = win32api.GetSystemMetrics(SM_YVIRTUALSCREEN)
    +            r = l + w
    +            b = t + h
    +            hwndDC = win32gui.GetWindowDC(hwnd)
    +            mfcDC  = win32ui.CreateDCFromHandle(hwndDC)
    +            saveDC = mfcDC.CreateCompatibleDC()
    +            saveBitMap = win32ui.CreateBitmap()
    +            saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
    +            saveDC.SelectObject(saveBitMap)
    +            saveDC.BitBlt((0, 0), (w, h),  mfcDC,  (l, t),  win32con.SRCCOPY)
    +            bmpinfo = saveBitMap.GetInfo()
    +            #print bmpinfo
    +            #print savefilename
    +            bmpstr = saveBitMap.GetBitmapBits(True)
    +            image_data = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
    +            # fin ajout JPP
    +            #image_data = saveBitMap
                 image_data.save(savefilename,
                         quality=self.subsettings['General']['Screenshot Image Quality'])
    

    to answer to ca office to apply a patch on a source code : 
    under linux : http://jungels.net/articles/diff-patch-ten-minutes.html
    under windows if you have no linux available : http://docs.moodle.org/dev/How_to_apply_a_patch

    a search engine might allow you to find alternatives