[Win32utils-devel] Screen capture, save to file

Paul Rogers paul.rogers at shaw.ca
Sun Apr 24 19:14:46 EDT 2005


Thanks! I'll settle for simple and annoying for now!

Paul

-----Original Message-----
From: win32utils-devel-bounces at rubyforge.org
[mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of Park Heesob
Sent: 23 April 2005 17:20
To: Development and ideas for win32utils projects
Subject: Re: [Win32utils-devel] Screen capture, save to file


Hi,
----- Original Message ----- 
From: "Paul Rogers" <paul.rogers at shaw.ca>
To: <win32utils-devel at rubyforge.org>
Sent: Friday, April 22, 2005 5:28 AM
Subject: [Win32utils-devel] Screen capture, save to file


> 
> 
> Is there anything in the utils to capture a screen ( or maybe just a
> window) and save to a file.
> 
> I have this, but I have no idea where it came from, but it gives a 
> corrupted image
> 
> Paul
> 

I have made another simple and annoying solution 
using Print Screen,Clipboard and MSPaint.exe.

Regards,

Park Heesob

=================================================
require 'Win32API'

KEYEVENTF_KEYUP = 0x2
SW_HIDE         = 0
SW_SHOW         = 5
SW_SHOWNORMAL   = 1
VK_CONTROL      = 0x11
VK_F4           = 0x73
VK_MENU         = 0x12
VK_RETURN       = 0x0D
VK_SHIFT        = 0x10
VK_SNAPSHOT     = 0x2C
VK_TAB      = 0x09

def screenCapture(filename = "tmp.bmp")

  keybd_event = Win32API.new("user32", "keybd_event", ['I','I','L','L'],
'V')
  vkKeyScan = Win32API.new("user32", "VkKeyScan", ['I'], 'I')
  winExec = Win32API.new("kernel32", "WinExec", ['P','L'], 'L')
 
  filename = Dir.getwd.tr('/','\\') + '\\' + filename unless
filename.index('\\')

  keybd_event.Call(VK_SNAPSHOT,0,0,0)   # Print Screen
  # keybd_event.Call(VK_SNAPSHOT,1,0,0) # Alt+Print Screen 

  winExec.Call('mspaint.exe', SW_SHOW)
  sleep(1)
  
  # Ctrl + V  : Paste
  keybd_event.Call(VK_CONTROL, 1, 0, 0)
  keybd_event.Call(vkKeyScan.Call(?V), 1, 0, 0)
  keybd_event.Call(vkKeyScan.Call(?V), 1, KEYEVENTF_KEYUP, 0)
  keybd_event.Call(VK_CONTROL, 1, KEYEVENTF_KEYUP, 0)

  # Alt E + O : Save Selected Image
  keybd_event.Call(VK_MENU, 1, 0, 0)
  keybd_event.Call(vkKeyScan.Call(?E), 1, 0, 0)
  keybd_event.Call(vkKeyScan.Call(?E), 1, KEYEVENTF_KEYUP, 0)
  keybd_event.Call(VK_MENU, 1, KEYEVENTF_KEYUP, 0)
  keybd_event.Call(vkKeyScan.Call(?O), 1, 0, 0)
  keybd_event.Call(vkKeyScan.Call(?O), 1, KEYEVENTF_KEYUP, 0)
  sleep(1)
  
  # Enter filename
  filename.each_byte { |ch|      
     keybd_event.Call(VK_SHIFT, 1, 0, 0) if ch==?:
   keybd_event.Call(vkKeyScan.Call(ch), 1, 0, 0)
   keybd_event.Call(vkKeyScan.Call(ch), 1, KEYEVENTF_KEYUP, 0)
   keybd_event.Call(VK_SHIFT, 1, KEYEVENTF_KEYUP, 0) if ch==?:  
  }
  keybd_event.Call(VK_RETURN, 1, 0, 0)
  keybd_event.Call(VK_RETURN, 1, KEYEVENTF_KEYUP, 0)
  sleep(1)
  
  # Y
  keybd_event.Call(vkKeyScan.Call(?Y), 1, 0, 0)
  keybd_event.Call(vkKeyScan.Call(?Y), 1, KEYEVENTF_KEYUP, 0)
  sleep(1)
  
  # Alt + F4 : Exit
  keybd_event.Call(VK_MENU, 1, 0, 0)
  keybd_event.Call(VK_F4, 1, 0, 0)
  keybd_event.Call(VK_F4, 1, KEYEVENTF_KEYUP, 0)
  keybd_event.Call(VK_MENU, 1, KEYEVENTF_KEYUP, 0)
  sleep(1)  
  
  # N
  keybd_event.Call(vkKeyScan.Call(?N), 1, 0, 0)
  keybd_event.Call(vkKeyScan.Call(?N), 1, KEYEVENTF_KEYUP, 0)
  
end

screenCapture


_______________________________________________
win32utils-devel mailing list
win32utils-devel at rubyforge.org
http://rubyforge.org/mailman/listinfo/win32utils-devel



More information about the win32utils-devel mailing list