#==============================================================================# Screenshot Bitmap EX# Author: Soulpour777#------------------------------------------------------------------------------# This is a port and convert version of KGC's old Screen Capture Script.#==============================================================================module Soul module ScreenCapture STRING_BUF_SIZE = 255 # String Buff Size UTF8_UNICODE = 65001 # UTF-8 Unicode SCREENSHOT_KEY = Input::F8 # Screenshot Key USE_CTRL = false# CTRL Key Option Toggle # This toggle allows you to require the CTRL key to be held while pressing # the Screen Capture Key (Default: F8) # true = CTRL must be held. # false = CTRL is not required. USE_ALT = false # ALT Key Option Toggle USE_SHIFT = false # SHIFT Key Option Toggle NAME_FORMAT = "Screenshot{num}.bmp" # Screenshot Filename Format # Screen Capture Sound Effect if $TEST # VX-Only SUCCESS_SE = RPG::SE.new("Chime1", 100, 100) end endend#==============================================================================# ■ TCap#==============================================================================module TCap #-------------------------------------------------------------------------- # ● The TCap.dll version is aquired. # (Example: 1.23 → 123) #-------------------------------------------------------------------------- def self.version begin api = Win32API.new('TCap.dll', 'DllGetVersion', %w(v), 'l') ret = api.call rescue ret = -1 end return ret end #-------------------------------------------------------------------------- # ● Capture Game Screen # filename : output destination (bmp) #-------------------------------------------------------------------------- def self.capture(filename) begin hwnd = Win32API.GetHwnd if hwnd == 0 hwnd = Win32API.GetActiveWindow end if hwnd == 0 ret = -1 else tcap = Win32API.new('TCap.dll', 'CaptureA', %w(l p l l), 'l') ret = tcap.call(hwnd, filename, 1, Soul::ScreenCapture::UTF8_UNICODE) Graphics.frame_reset end rescue ret = -1 end return ret endend#==============================================================================# ■ Input#==============================================================================if ($DEBUG || $TEST) && Soul::ScreenCapture::SCREENSHOT_KEY != nil module Input @@_capture_num = 1 CAPTURE_FILE_NAME = Soul::ScreenCapture::NAME_FORMAT.gsub(/{num}/) { "%03d" } #-------------------------------------------------------------------------- # ● Frame Update #-------------------------------------------------------------------------- unless defined?(update_Soul_ScreenCapture) class << Input alias update_Soul_ScreenCapture update end def self.update update_Soul_ScreenCapture judge_capture end end #-------------------------------------------------------------------------- # ● Capture Execution Judgement #-------------------------------------------------------------------------- def self.judge_capture if trigger?(Soul::ScreenCapture::SCREENSHOT_KEY) && (!Soul::ScreenCapture::USE_CTRL || press?(CTRL)) && (!Soul::ScreenCapture::USE_ALT || press?(ALT)) && (!Soul::ScreenCapture::USE_SHIFT || press?(SHIFT)) result = TCap.capture(sprintf(CAPTURE_FILE_NAME, @@_capture_num)) if result == 0 capture_se = Soul::ScreenCapture::SUCCESS_SE if capture_se != nil $DEBUG ? $game_system.se_play(capture_se) : capture_se.play end @@_capture_num += 1 end end end endendclass Win32API #-------------------------------------------------------------------------- # ● Read INI File # section : Section name # key : Key # default : default value when a key doesn't exist # inifile : Passing of read INI file #-------------------------------------------------------------------------- def self.GetPrivateProfileString(section, key, default, inifile) get_ini = Win32API.new( 'kernel32.dll', 'GetPrivateProfileStringA', %w(p p p p l p), 'l') buf = "\0" * (Soul::ScreenCapture::STRING_BUF_SIZE + 1) get_ini.call(section, key, default, buf, Soul::ScreenCapture::STRING_BUF_SIZE, inifile) return buf.delete!("\0") end #-------------------------------------------------------------------------- # ● Aquire Window # window_class : Window class name # window_title : Title of window #-------------------------------------------------------------------------- def self.FindWindow(window_class, window_title) find_window = Win32API.new('user32.dll', 'FindWindowA', %w(p p), 'l') return find_window.call(window_class, window_title) end #-------------------------------------------------------------------------- # ● Aquire Active Window #-------------------------------------------------------------------------- def self.GetActiveWindow active_window = Win32API.new('user32.dll', 'GetActiveWindow', %w(v), 'l') return active_window.call end #-------------------------------------------------------------------------- # ● Aquire Game Window #-------------------------------------------------------------------------- def self.GetHwnd name = GetPrivateProfileString("Game", "Title", "", "./Game.ini") return FindWindow("RGSS3 Player", name) endend