[Win32utils-devel] Screen capture, save to file

Paul Rogers paul.rogers at shaw.ca
Tue Apr 26 15:28:30 EDT 2005


Ok, Ive just tried it, and there is a weird bug I don't understand.
In the Save as dialog, a _ gets changed to a -

c:\watir_bonus>screen_capture.rb
file to use is: c:\watir_bonus\tmp.bmp
after E O
sending c  99
SHIFT
sending :  58
sending \  92
sending w  119
sending a  97
sending t  116
sending i  105
sending r  114
sending _  95   <-- correct char is sent
sending b  98
sending o  111
sending n  110
sending u  117
sending s  115
sending \  92
sending t  116
sending m  109
sending p  112
sending .  46
sending b  98
sending m  109
sending p  112
after filename

c:\watir_bonus>irb
irb(main):001:0> "_".asc
NoMethodError: undefined method `asc' for "_":String
        from (irb):1
irb(main):002:0> 95.chr
=> "_"
irb(main):003:0> "-"[0]
=> 45
irb(main):004:0> 45.chr
=> "-"
irb(main):005:0>


But it shows up in the save as dialog as -

Thanks

Paul


-----Original Message-----
From: win32utils-devel-bounces at rubyforge.org
[mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of Paul Rogers
Sent: 26 April 2005 13:03
To: 'Development and ideas for win32utils projects'
Subject: RE: [Win32utils-devel] Screen capture, save to file


I havent had a chance to try this so far, but Im sure it will be fine.
The reason I wanted this is that Im a developer on Watir (
http://wtr.rubyforge.org/ ) and several people have asked for the
ability to capture screen shots when running tests.

So my question is this - Is it ok for us to redistribute this code with
Watir? I will obviously credit you with writing it.

Thanks

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

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



More information about the win32utils-devel mailing list