=begin #=============================================================================== Title: Console Window Author: Hime Date: Dec 3, 2013 URL: -------------------------------------------------------------------------------- ** Change log Dec 3, 2013 - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script allows you to attach a console window to your game, if you need one for some reason. Testplay mode comes with one by default, but maybe you want one in a real game. -------------------------------------------------------------------------------- ** Installation This script can be placed anywhere above Main, but you should place this as the first script at the very top. -------------------------------------------------------------------------------- ** Usage Plug and play #=============================================================================== =end $imported = {} if $imported.nil? $imported["TH_ConsoleWindow"] = true #=============================================================================== # * Rest of Script #=============================================================================== module TH module Console_Window def self.attach_console # Get game window text console_w = Win32API.new('user32','GetForegroundWindow', 'V', 'L').call buf_len = Win32API.new('user32','GetWindowTextLength', 'L', 'I').call(console_w) str = ' ' * (buf_len + 1) Win32API.new('user32', 'GetWindowText', 'LPI', 'I').call(console_w , str, str.length) # Initiate console Win32API.new('kernel32.dll', 'AllocConsole', '', '').call Win32API.new('kernel32.dll', 'SetConsoleTitle', 'P', '').call('RGSS Console') $stdout.reopen('CONOUT$') # Sometimes pressing F12 will put the editor in focus first, # so we have to remove the program's name game_title = str.strip game_title.sub! ' - RPG Maker VX Ace', '' # Set game window to be foreground. This is purely for user convenience hwnd = Win32API.new('user32.dll', 'FindWindow', 'PP','N').call(0, game_title) Win32API.new('user32.dll', 'SetForegroundWindow', 'P', '').call(hwnd) end def self.xp? defined?(Hangup) end def self.vx? !xp? && (RUBY_VERSION == '1.8.1') end end end if TH::Console_Window.xp? || TH::Console_Window.vx? module Kernel def p(*args) puts(*args) end end end # Call this at the beginning TH::Console_Window.attach_console