[Ruby] 纯文本查看 复制代码
#==============================================================================
# ■ Console
# By QQEat
#------------------------------------------------------------------------------
# 高仿VA控制台。
# puts:控制台打印
#==============================================================================
if $TEST or $DEBUG
Win32API.new("kernel32", "AllocConsole", "v", "i").call #创建
#~ Win32API.new("kernel32", "FreeConsole", "v", "i").call #释放
Win32API.new("kernel32", "SetConsoleTitle", "p", "i").call("RGSS Console") #setTitle
GetStdHandle = Win32API.new("kernel32", "GetStdHandle", "i", "i") #I/O_hWnd
WriteConsole = Win32API.new("kernel32", "WriteConsole", "ipiii", "i") #WriteConsole
GetStringLength = Win32API.new("kernel32", "lstrlenA", "p", "i") #getStringLength
def puts(*args)
str = ""
args.each{|a| str << (a.is_a?(String) ? "\"" << a.to_s << "\"" : a.inspect) << "\n" }
#处理编码
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
len = m2w.call(0xFDE9,0,str,-1,nil,0)
buf = "\0" * (len*2)
m2w.call(0xFDE9,0,str,-1,buf,buf.size/2)
len = w2m.call(0,0,buf,-1,nil,0,nil,nil)
ret = "\0" * len
w2m.call(0,0,buf,-1,ret,ret.size,nil,nil)
str = ret.delete!("\0")
WriteConsole.call(GetStdHandle.call(-12), str, GetStringLength.call(str), 0, 0)
end
else
def puts(*args);end
end
HWnd = Win32API.new('user32','FindWindowEx','llpp','i')
Win32API.new('user32','SetForegroundWindow','i','i').call(HWnd.call(0, 0, 'RGSS Player', 0)) if $TEST or $DEBUG #获取焦点置前台