设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 12362|回复: 19
打印 上一主题 下一主题

[RMVA发布] 免DLL輸入框

[复制链接]

Lv1.梦旅人

梦石
0
星屑
105
在线时间
67 小时
注册时间
2007-12-16
帖子
75
跳转到指定楼层
1
 楼主| 发表于 2013-3-1 18:24:02 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 danny8376 于 2013-5-23 20:39 编辑

虽然这类脚本发过很多了
不过这个应该算最完整了=w=

基本上一般文字输入框的功能都有了
(显示上也是 选取都有做出来了XDD)

不过原本想改成Unicode 这样可以解决编码问题
不过没办法产生支援Unicode的文字框...
不知道有没有啥办法呢=3=

直接显示文字输入框也有做
不过懒得去背景+改文字颜色
有时间再改吧



符号类别扩充 颇喜欢这种WIN32API用法
RUBY 代码复制
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ Symbol
  4. #------------------------------------------------------------------------------
  5. #  。
  6. #==============================================================================
  7. $apicache = {}
  8. class Symbol
  9.   #--------------------------------------------------------------------------
  10.   # ● 轉為Win32API
  11.   #--------------------------------------------------------------------------
  12.   def to_api
  13.     $apicache[self] = Win32API.new(*self.to_s.split("|")) unless $apicache.include? self
  14.     return $apicache[self]
  15.   end
  16.   #--------------------------------------------------------------------------
  17.   # ● 轉為Win32API並呼叫
  18.   #--------------------------------------------------------------------------
  19.   def apicall(*args)
  20.     self.to_api.call(*args)
  21.   end
  22. end



下方是修改过的晴兰的纯脚本不使用DLL就读取窗口消息
主要是产生消息函数给文字框用
RUBY 代码复制
  1. #encoding:utf-8
  2. # 纯脚本不使用DLL就读取窗口消息
  3. # By 晴兰 form 66RPG
  4. # 功能擴充 By AAM@_@
  5. #==============================================================================
  6. # ■ MainWindow
  7. #------------------------------------------------------------------------------
  8. #  。
  9. #==============================================================================
  10.  
  11. module MainWindow
  12.   #--------------------------------------------------------------------------
  13.   # ● 部分Windows消息定义
  14.   #--------------------------------------------------------------------------
  15.   WM_CREATE                       = 0x0001
  16.   WM_DESTROY                      = 0x0002
  17.   WM_MOVE                         = 0x0003
  18.   WM_SIZE                         = 0x0005
  19.  
  20.   WM_ACTIVATE                     = 0x0006
  21.   WM_ACTIVATEAPP                  = 0x001C
  22.  
  23.   WM_GETTEXT                      = 0x000D
  24.   WM_GETTEXTLENGTH                = 0x000E
  25.   WM_PAINT                        = 0x000F
  26.   WM_CLOSE                        = 0x0010
  27.   WM_QUERYENDSESSION              = 0x0011
  28.   WM_QUIT                         = 0x0012
  29.  
  30.   WM_KEYDOWN                      = 0x0100
  31.   WM_KEYUP                        = 0x0101
  32.   WM_CHAR                         = 0x0102
  33.  
  34.   WM_SYSKEYDOWN                   = 0x0104
  35.   WM_SYSKEYUP                     = 0x0105
  36.   WM_SYSCHAR                      = 0x0106
  37.  
  38.   WM_COMMAND                      = 0x0111
  39.   WM_SYSCOMMAND                   = 0x0112
  40.   WM_TIMER                        = 0x0113
  41.  
  42.   WM_MOUSEMOVE                    = 0x0200
  43.   WM_LBUTTONDOWN                  = 0x0201
  44.   WM_LBUTTONUP                    = 0x0202
  45.   WM_LBUTTONDBLCLK                = 0x0203
  46.   WM_RBUTTONDOWN                  = 0x0204
  47.   WM_RBUTTONUP                    = 0x0205
  48.   WM_RBUTTONDBLCLK                = 0x0206
  49.   WM_MBUTTONDOWN                  = 0x0207
  50.   WM_MBUTTONUP                    = 0x0208
  51.   WM_MBUTTONDBLCLK                = 0x0209
  52.  
  53.   WM_MOUSEWHEEL                   = 0x020A
  54.  
  55.   RM_F1MENU_OPEN                  = 0x0112
  56.   RM_F1MENU_CLOSE                 = 0x0125
  57.   #--------------------------------------------------------------------------
  58.   # ● 其他常量定义
  59.   #--------------------------------------------------------------------------
  60.   WA_INACTIVE                     = 0
  61.   WA_ACTIVE                       = 1
  62.   WA_CLICKACTIVE                  = 2
  63.   #--------------------------------------------------------------------------
  64.   # ●
  65.   #--------------------------------------------------------------------------
  66.   @@ShowCursor = :"user32|ShowCursor|i|l".to_api
  67.   @@handle = false # 禁用默认窗口过程
  68.   @@procs = {}
  69.   @@child_procs = {}
  70.   @@child_callback = {}
  71.   @@child_def_procs = {}
  72.   #--------------------------------------------------------------------------
  73.   # ● 窗口过程函数 ※ 该名字切勿更改
  74.   #--------------------------------------------------------------------------
  75.   def self.wnd_proc(hwnd,msg,wparam,lparam)
  76.     # 消息分歧
  77.     case msg
  78.     when WM_CREATE
  79.     when WM_MOVE
  80.     when WM_ACTIVATEAPP
  81.     else
  82.     end
  83.     # 調用其他外插的視窗訊息
  84.     if !@@procs.empty?
  85.       @@procs.each_value do |i|
  86.         begin
  87.           i.call(hwnd,msg,wparam,lparam)
  88.         rescue
  89.         end
  90.       end
  91.     end
  92.     # 调用默认窗口过程
  93.     self.use_rm_proc(hwnd,msg,wparam,lparam)
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # ●
  97.   #--------------------------------------------------------------------------
  98.   def self.add_proc(symbol, method)
  99.     @@procs[symbol] = method
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ●
  103.   #--------------------------------------------------------------------------
  104.   def self.remove_proc(symbol)
  105.     @@procs.delete(symbol)
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ●
  109.   #--------------------------------------------------------------------------
  110.   def self.use_rm_proc(hwnd, msg, wp, lp)
  111.     return :"user32|CallWindowProc|iiiii|i".apicall(@@oHandle, hwnd, msg, wp, lp) if !@@handle
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # ●
  115.   #--------------------------------------------------------------------------
  116.   def self.disable_rm_proc
  117.     @@handle = true
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ●
  121.   #--------------------------------------------------------------------------
  122.   def self.enable_rm_proc
  123.     @@handle = false
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # ●
  127.   #--------------------------------------------------------------------------
  128.   def self.child_def_proc(symbol, hwnd, msg, wp, lp)
  129.     return :"user32|CallWindowProc|iiiii|i".apicall(@@child_def_procs[hwnd], hwnd, msg, wp, lp)
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # ● ??? ※ 该名字切勿更改
  133.   #--------------------------------------------------------------------------
  134.   def self.child_wnd_proc(symbol, hwnd, msg, wparam, lparam)
  135.     begin
  136.       @@child_procs[symbol].call(hwnd,msg,wparam,lparam)
  137.     rescue
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ●
  142.   #--------------------------------------------------------------------------
  143.   def self.disableChildWndProc(hwnd)
  144.     :"user32|SetWindowLong|iii|i".apicall(hwnd, -4, @@child_def_procs[hwnd])
  145.     @@child_def_procs.delete(hwnd)
  146.     :"msvcrt|free|i|i".apicall(@@child_callback[hwnd])
  147.     @@child_callback.delete(hwnd)
  148.     @@child_procs.delete(hwnd)
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # ●
  152.   #--------------------------------------------------------------------------
  153.   def self.enableChildWndProc(hwnd, proc)
  154.     @@child_procs[hwnd] = proc
  155.  
  156.     @malloc = :"msvcrt|malloc|i|i"
  157.     @memcpy = :"msvcrt|memcpy|ipi|v"
  158.  
  159.     sprintf    = self.findProc("msvcrt", "sprintf")
  160.     rgsseval   = self.findProc("RGSS300", "RGSSGetInt")
  161.     oHandle  = :"user32|GetWindowLong|ll|l".apicall(hwnd, -4)
  162.     buf        = @malloc.apicall(1024)
  163.     fmt        = @malloc.apicall(2048)
  164.     sprintfvar = @malloc.apicall(8)
  165.     rgssevalvar= @malloc.apicall(8)
  166.     oldvar     = @malloc.apicall(8)
  167.     fmtvar     = @malloc.apicall(8)
  168.     bufvar     = @malloc.apicall(8)
  169.     defvar     = @malloc.apicall(8)
  170.  
  171.     @@child_def_procs[hwnd] = oHandle
  172.  
  173.     :"msvcrt|strcpy|pp|p".apicall(fmt, "MainWindow.child_wnd_proc(#{hwnd},%d,%d,%d,%d)")
  174.  
  175.     @memcpy.apicall(sprintfvar, [sprintf].pack("i"),   4)
  176.     @memcpy.apicall(rgssevalvar,[rgsseval].pack("i"),  4)
  177.     @memcpy.apicall(oldvar,     [@@oHandle].pack("i"), 4)
  178.     @memcpy.apicall(fmtvar,     [fmt].pack("i"),       4)
  179.     @memcpy.apicall(bufvar,     [buf].pack("i"),       4)
  180.     @memcpy.apicall(defvar,     [oHandle].pack("i"), 4)
  181.  
  182.     code = [0x55,0x89,0xe5,0xff,0x75,0x14,
  183.              0xff,0x75,0x10,0xff,0x75,0x0c,
  184.              0xff,0x75,0x08,0xff,0x35].pack('C*')
  185.     code << [fmtvar].pack('l') << [0xff, 0x35].pack('C*')
  186.     code << [bufvar].pack('l') << [0xff, 0x15].pack('C*')
  187.     code << [sprintfvar].pack("l")
  188.     code << [0xff, 0x15].pack('C*')
  189.     code << [rgssevalvar].pack("l")
  190.     code << [0x83,0xc4,0x18].pack('C*')
  191.     code << [0xc9,0xc2,0x10,0x00].pack('C*')
  192.     #0xD1, 0xE8
  193.     shellcode = @malloc.apicall(2048)
  194.     @memcpy.apicall(shellcode, code, code.size)
  195.     :"user32|SetWindowLong|iii|i".apicall(hwnd, -4, shellcode)
  196.     @@child_callback[hwnd] = shellcode
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # ●
  200.   #--------------------------------------------------------------------------
  201.   def self.enable
  202.     MainWindow.instance_eval do
  203.       # 清空 enable 方法(避免重複呼叫)
  204.       def self.enable
  205.       end
  206.       # 取得 HWND
  207.       @msg = "\0" * 24
  208.       @hwnd = 0
  209.       while @hwnd == 0
  210.         :"user32|GetMessage|piii|v".apicall(@msg, 0, 0, 0)
  211.         @kmsg = @msg
  212.         :"user32|TranslateMessage|p|v".apicall(@kmsg)
  213.         :"user32|DispatchMessage|p|v".apicall(@kmsg)
  214.         @hwnd = @msg.unpack("i*")[0]
  215.       end
  216.       @hdc = :"user32|GetDC|i|i".apicall(@hwnd)
  217.       # 方法:取得HWND
  218.       def self.hwnd
  219.         return @hwnd
  220.       end
  221.       # 方法:取得HDC
  222.       def self.hdc
  223.         return @hdc
  224.       end
  225.       # 方法:取得HWNDProc
  226.       def self.findProc(l, n)
  227.         lib = :"kernel32|LoadLibrary|p|i".apicall(l)
  228.         ret = :"kernel32|GetProcAddress|ip|l".apicall(lib, n)
  229.         :"kernel32|FreeLibrary|l|v".apicall(lib)
  230.         return ret
  231.       end
  232.       # 方法:Hook HWNDProc
  233.       def self.enableWndProc
  234.         # 清空 enableWndProc 方法(避免重複呼叫)
  235.         MainWindow.instance_eval do
  236.           def self.enableWndProc
  237.           end
  238.         end
  239.         @malloc = :"msvcrt|malloc|i|i"
  240.         @memcpy = :"msvcrt|memcpy|ipi|v"
  241.  
  242.         sprintf    = self.findProc("msvcrt", "sprintf")
  243.         rgsseval   = self.findProc("RGSS300", "RGSSGetInt")
  244.         @@oHandle  = :"user32|GetWindowLong|ll|l".apicall(@hwnd, -4)
  245.         buf        = @malloc.apicall(1024)
  246.         fmt        = @malloc.apicall(2048)
  247.         sprintfvar = @malloc.apicall(8)
  248.         rgssevalvar= @malloc.apicall(8)
  249.         oldvar     = @malloc.apicall(8)
  250.         fmtvar     = @malloc.apicall(8)
  251.         bufvar     = @malloc.apicall(8)
  252.         defvar     = @malloc.apicall(8)
  253.  
  254.         :"msvcrt|strcpy|pp|p".apicall(fmt, "MainWindow.wnd_proc(%d,%d,%d,%d)")
  255.  
  256.         @memcpy.apicall(sprintfvar, [sprintf].pack("i"),   4)
  257.         @memcpy.apicall(rgssevalvar,[rgsseval].pack("i"),  4)
  258.         @memcpy.apicall(oldvar,     [@@oHandle].pack("i"), 4)
  259.         @memcpy.apicall(fmtvar,     [fmt].pack("i"),       4)
  260.         @memcpy.apicall(bufvar,     [buf].pack("i"),       4)
  261.         @memcpy.apicall(defvar,     [self.findProc("user32", "DefWindowProcA")].pack("i"), 4)
  262.  
  263.         @code= [0x55,0x89,0xe5,0xff,0x75,0x14,
  264.                  0xff,0x75,0x10,0xff,0x75,0x0c,
  265.                  0xff,0x75,0x08,0xff,0x35].pack('C*')
  266.         @code<< [fmtvar].pack('l') << [0xff, 0x35].pack('C*')
  267.         @code<< [bufvar].pack('l') << [0xff, 0x15].pack('C*')
  268.         @code<< [sprintfvar].pack("l")
  269.         @code<< [0xff, 0x15].pack('C*')
  270.         @code<< [rgssevalvar].pack("l")
  271.         @code<< [0x83,0xc4,0x18].pack('C*')
  272.         @code<< [0xc9,0xc2,0x10,0x00].pack('C*')
  273.         #0xD1, 0xE8
  274.         @shellcode = @malloc.apicall(2048)
  275.         @memcpy.apicall(@shellcode, @code, @code.size)
  276.         :"user32|SetWindowLong|iii|i".apicall(@hwnd, -4, @shellcode)
  277.       end
  278.     end
  279.   end
  280. end
  281.  
  282.  
  283. MainWindow.enable
  284. MainWindow.enableWndProc



文字编码
RUBY 代码复制
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ String
  4. #------------------------------------------------------------------------------
  5. #  字符串类。可处理任意长度的字节串。 (追加编码转换的定义)
  6. #==============================================================================
  7.  
  8. class String
  9.   #--------------------------------------------------------------------------
  10.   # ●
  11.   #--------------------------------------------------------------------------
  12.   CP_ACP = 0
  13.   CP_UTF8 = 65001
  14.   CP_UTF16 = 1200
  15.   #--------------------------------------------------------------------------
  16.   # ●
  17.   #--------------------------------------------------------------------------
  18.   def u2s
  19.     m2w = :"kernel32|MultiByteToWideChar|ilpipi|i".to_api
  20.     w2m = :"kernel32|WideCharToMultiByte|ilpipipp|i".to_api
  21.  
  22.     len = m2w.call(CP_UTF8, 0, self, -1, nil, 0)
  23.     buf = "\0" * (len*2)
  24.     m2w.call(CP_UTF8, 0, self, -1, buf, buf.size/2)
  25.  
  26.     len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
  27.     ret = "\0" * len
  28.     w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
  29.  
  30.     return ret
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # ●
  34.   #--------------------------------------------------------------------------
  35.   def s2u
  36.     m2w = :"kernel32|MultiByteToWideChar|ilpipi|i".to_api
  37.     w2m = :"kernel32|WideCharToMultiByte|ilpipipp|i".to_api
  38.  
  39.     len = m2w.call(CP_ACP, 0, self, -1, nil, 0);
  40.     buf = "\0" * (len*2)
  41.     m2w.call(CP_ACP, 0, self, -1, buf, buf.size/2);
  42.  
  43.     len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);
  44.     ret = "\0" * len
  45.     w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);
  46.  
  47.     return ret
  48.   end
  49.   #--------------------------------------------------------------------------
  50.   # ●
  51.   #--------------------------------------------------------------------------
  52.   def u2w
  53.     m2w = :"kernel32|MultiByteToWideChar|ilpipi|i".to_api
  54.  
  55.     len = m2w.call(CP_UTF8, 0, self, -1, nil, 0)
  56.     buf = "\0" * (len*2)
  57.     m2w.call(CP_UTF8, 0, self, -1, buf, len)
  58.  
  59.     return buf
  60.   end
  61.   #--------------------------------------------------------------------------
  62.   # ●
  63.   #--------------------------------------------------------------------------
  64.   def w2u
  65.     w2m = :"kernel32|WideCharToMultiByte|ilpipipp|i".to_api
  66.  
  67.     len = w2m.call(CP_UTF8, 0, self, -1, nil, 0, nil, nil)
  68.     buf = "\0" * len
  69.     w2m.call(CP_UTF8, 0, self, -1, buf, len, nil, nil)
  70.  
  71.     return buf
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # ●
  75.   #--------------------------------------------------------------------------
  76.   def s2u!
  77.     self[0, length] = s2u
  78.   end  
  79.   #--------------------------------------------------------------------------
  80.   # ●
  81.   #--------------------------------------------------------------------------
  82.   def u2s!
  83.     self[0, length] = u2s
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # ●
  87.   #--------------------------------------------------------------------------
  88.   def u2w!
  89.     self[0, length] = u2u16
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ●
  93.   #--------------------------------------------------------------------------
  94.   def w2u!
  95.     self[0, length] = u162u
  96.   end
  97. end




主要负责处理文字框的 TextBox
RUBY 代码复制
  1. #==============================================================================
  2. # ■ TextBox By AAM@_@
  3. #------------------------------------------------------------------------------
  4. #  输入框的类。
  5. #==============================================================================
  6. class TextBox
  7.   #--------------------------------------------------------------------------
  8.   # ● 设置API
  9.   #--------------------------------------------------------------------------
  10.   @@CreateWindow = :"user32|CreateWindowEx|lpplllllllll|l".to_api
  11.   @@ShowWindow = :"user32|ShowWindow|ll|l".to_api
  12.   @@DestroyWindow = :"user32|DestroyWindow|l|l".to_api
  13.   @@SetWindowPos = :"user32|SetWindowPos|lllllll|l".to_api
  14.   @@GetWindowRect = :"user32|GetWindowRect|ll|l".to_api
  15.   @@GetWindowText = :"user32|GetWindowText|lpl|l".to_api
  16.   @@GetWindowTextLength = :"user32|GetWindowTextLength|l|l".to_api
  17.   @@SetWindowText = :"user32|SetWindowText|lp|l".to_api
  18.   @@UpdateWindow = :"user32|UpdateWindow|l|i".to_api
  19.   @@SetFocus = :"user32|SetFocus|l|l".to_api
  20.   @@SendMessage = :"user32|SendMessage|llll|l".to_api
  21.   @@SendMessage_Pos = :"user32|SendMessage|llpp|l".to_api
  22.   @@CreateFont = :"gdi32|CreateFont|lllllllllllllp|l".to_api
  23.   #--------------------------------------------------------------------------
  24.   # ● 定义实例变量
  25.   #--------------------------------------------------------------------------
  26.   attr_accessor :focus
  27.   attr_reader   :font_name
  28.   attr_reader   :font_size
  29.   attr_reader   :password
  30.   #--------------------------------------------------------------------------
  31.   # ●
  32.   #--------------------------------------------------------------------------
  33.   def default_font_name
  34.     return Font.default_name if Font.default_name.is_a?(String)
  35.     for i in Font.default_name
  36.       return i if Font.exist?(i)
  37.     end
  38.     return ""
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # ●
  42.   #--------------------------------------------------------------------------
  43.   def font_name=(f)
  44.     @font_name = f
  45.     update_font
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # ●
  49.   #--------------------------------------------------------------------------
  50.   def font_size=(s)
  51.     @font_size = s * 0.9
  52.     update_font
  53.     # Fix window height
  54.     rect = "\0" * 16
  55.     @@GetWindowRect.call(@window, rect)
  56.     rect = rect.unpack("l*")
  57.     @@SetWindowPos.call(@window, 0, rect[0], rect[1], @width, @font_size, 0)
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # ●
  61.   #--------------------------------------------------------------------------
  62.   def update_font
  63.     hFont = @@CreateFont.call(@font_size,@font_size/2,0,0,0,0,0,0,0,0,0,0,0,@font_name.u2s)
  64.     @@SendMessage.call(@window, 0x30, hFont, 0) # WM_SETFONT
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # ● 初始化
  68.   #--------------------------------------------------------------------------
  69.   def initialize(text = "", limit = 8, password = false, width = 160, direct_show = false, font_name = default_font_name, font_size = Font.default_size)
  70.     @password = password
  71.     @width = width
  72.     @direct_show = direct_show
  73.     @font_name = font_name
  74.     @font_size = font_size * 0.9
  75.     c = 0x40000000
  76.     c |= 0x00000020 if password # ES_PASSWORD
  77.     @window=@@CreateWindow.call(0, 'EDIT', text.u2s, c, 0, 0, @width, @font_size, MainWindow.hwnd, 0, 0, 0)
  78.     if @direct_show
  79.        mc = :"user32|GetWindowLong|ll|l".apicall(MainWindow.hwnd, -16) # GWL_STYLE
  80.        mc |= 0x02000000 # WS_CLIPCHILDREN
  81.        :"user32|SetWindowLong|lll|l".apicall(MainWindow.hwnd, -16, mc) # GWL_STYLE
  82.      end
  83.     @@ShowWindow.call(@window, 5) if @direct_show
  84.     @@SendMessage.call(@window, 0xC5, limit, 0) # WM_SETLIMITTEXT
  85.     update_font
  86.     MainWindow.enableChildWndProc(@window, method(:wnd_proc))
  87.     @enter_pressed = false
  88.     @focus = true
  89.     @disposed = false
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ● 窗口过程函数
  93.   #--------------------------------------------------------------------------
  94.   def wnd_proc(hwnd, msg, wp, lp)
  95.     if hwnd == @window&&msg == MainWindow::WM_CHAR and wp == 0x0D # Enter
  96.       @enter_pressed = true
  97.     end
  98.     MainWindow.child_def_proc(@window, hwnd, msg, wp, lp)
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # ● 释放
  102.   #--------------------------------------------------------------------------
  103.   def dispose
  104.     @disposed = true
  105.     MainWindow.disableChildWndProc(@window)
  106.     @@DestroyWindow.call(@window)
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # ● 刷新
  110.   #--------------------------------------------------------------------------
  111.   def update
  112.     return if !@focus or @disposed
  113.     if @direct_show
  114.       @@UpdateWindow.call(@window)
  115.     else
  116.       @@SendMessage.call(@window, 0xB1, sel_spos, sel_epos)
  117.     end
  118.     @@SetFocus.call(@window)
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # ●
  122.   #--------------------------------------------------------------------------
  123.   def set_pos(x, y)
  124.     @@SetWindowPos.call(@window, 0, x, y, @width, @font_size, 0)
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # ● 获取内容
  128.   #--------------------------------------------------------------------------
  129.   def text
  130.     return if @disposed
  131.     l = @@GetWindowTextLength.call(@window) + 1
  132.     str = "\0" * l
  133.     @@GetWindowText.call(@window, str, l)
  134.     return str.s2u.strip!
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # ● 更改内容
  138.   #--------------------------------------------------------------------------
  139.   def text=(str)
  140.     return if @disposed
  141.     @@SetWindowText.call(@window, str.u2s)
  142.     self.sel_pos = str.u2s.size - 1
  143.     str
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ● 获取起始光标位置
  147.   #--------------------------------------------------------------------------
  148.   def sel_spos
  149.     return if @disposed
  150.     #return @@SendMessage.call(@window, 0xB0, 0, 0) & 0xFFFF
  151.     spos = "\0" * 4
  152.     @@SendMessage_Pos.call(@window, 0xB0, spos, 0)
  153.     return spos.unpack("l")[0]
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # ● 获取結束光标位置
  157.   #--------------------------------------------------------------------------
  158.   def sel_epos
  159.     return if @disposed
  160.     #return @@SendMessage.call(@window, 0xB0, 0, 0) >> 16
  161.     epos = "\0" * 4
  162.     @@SendMessage_Pos.call(@window, 0xB0, 0, epos)
  163.     return epos.unpack("l")[0]
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # ● 设置光标位置
  167.   #--------------------------------------------------------------------------
  168.   def sel_spos=(i)
  169.     return if @disposed
  170.     @@SendMessage.call(@window, 0xB1, i, sel_epos)
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # ● 设置光标位置
  174.   #--------------------------------------------------------------------------
  175.   def sel_epos=(i)
  176.     return if @disposed
  177.     @@SendMessage.call(@window, 0xB1, sel_spos, i)
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # ● 设置光标位置
  181.   #--------------------------------------------------------------------------
  182.   def sel_pos=(i)
  183.     return if @disposed
  184.     @@SendMessage.call(@window, 0xB1, i, i)
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # ● 获取字數限制
  188.   #--------------------------------------------------------------------------
  189.   def limit
  190.     return if @disposed
  191.     return @@SendMessage.call(@window, 0xD5, 0, 0)
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # ● 设置字數限制
  195.   #--------------------------------------------------------------------------
  196.   def limit=(i)
  197.     return if @disposed
  198.     @@SendMessage.call(@window, 0xC5, i, 0)
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ● 是否按下回车键(0x0D => Enter, 0x1B => ESC)
  202.   #--------------------------------------------------------------------------
  203.   def press_enter?
  204.     return !(@enter_pressed = false) if @enter_pressed
  205.     return false
  206.   end
  207. end





实际上显示用的窗口 Window_TextBox
RUBY 代码复制
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ Window_TextBox By AAM@_@
  4. #------------------------------------------------------------------------------
  5. #  显示输入框用的窗口。
  6. #==============================================================================
  7. class Window_TextBox < Window_Base
  8.   #--------------------------------------------------------------------------
  9.   # ● 设置缓存的类
  10.   #--------------------------------------------------------------------------
  11.   TextBoxMem = Struct.new(:text, :sel_spos, :sel_epos)
  12.   #--------------------------------------------------------------------------
  13.   # ● 定义实例变量
  14.   #--------------------------------------------------------------------------
  15.   attr_reader   :textbox
  16.   attr_reader   :sel_pos
  17.   #--------------------------------------------------------------------------
  18.   # ● 初始化
  19.   #--------------------------------------------------------------------------
  20.   def initialize(x, y, width = 160, password = false)
  21.     super(x, y, width, window_height)
  22.     @handler = nil
  23.     @textbox = TextBox.new("", 8, password, width - standard_padding * 2)
  24.     @textbox.set_pos(self.x + standard_padding, self.y + standard_padding)
  25.     @tbmem = TextBoxMem.new
  26.     @curcor = Sprite.new
  27.     @curcor.bitmap = Bitmap.new(2, line_height)
  28.     @curcor.bitmap.fill_rect(@curcor.bitmap.rect, system_color)
  29.     @curcor.visible = false
  30.     @curcor.x = self.x + standard_padding
  31.     @curcor.y = self.y + standard_padding
  32.     @curcor.z = self.z + 1
  33.     @selection_color = system_color.clone
  34.     @selection_color.alpha = 128
  35.     refresh
  36.     activate
  37.   end
  38.   #--------------------------------------------------------------------------
  39.   # ● 获取窗口的高度
  40.   #--------------------------------------------------------------------------
  41.   def window_height
  42.     fitting_height(1)
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ●
  46.   #--------------------------------------------------------------------------
  47.   def x=(x)
  48.     super
  49.     @textbox.set_pos(self.x + standard_padding, self.y + standard_padding)
  50.     update_cursor_pos
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # ●
  54.   #--------------------------------------------------------------------------
  55.   def y=(y)
  56.     super
  57.     @textbox.set_pos(self.x + standard_padding, self.y + standard_padding)
  58.     @curcor.y = y + standard_padding
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ●
  62.   #--------------------------------------------------------------------------
  63.   def z=(z)
  64.     super
  65.     @curcor.z = z + 1
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # ●
  69.   #--------------------------------------------------------------------------
  70.   def viewport=(viewport)
  71.     super
  72.     @curcor.viewport = viewport
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # ● 刷新
  76.   #--------------------------------------------------------------------------
  77.   def update
  78.     super
  79.     if !@textbox.focus
  80.       @curcor.visible = false
  81.       return
  82.     end
  83.     @textbox.update
  84.     refresh if @textbox.sel_spos != @tbmem.sel_spos or @textbox.sel_epos != @tbmem.sel_epos or @textbox.text != @tbmem.text
  85.     update_cursor
  86.     process_handling
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ● 刷新游標
  90.   #--------------------------------------------------------------------------
  91.   def update_cursor
  92.     @curcor.visible = !@curcor.visible if Graphics.frame_count % 30 == 0
  93.   end
  94.   #--------------------------------------------------------------------------
  95.   # ● 刷新游標位置
  96.   #--------------------------------------------------------------------------
  97.   def update_cursor_pos
  98.     if @tbmem.sel_spos == @textbox.sel_spos
  99.       @sel_pos = @textbox.sel_epos
  100.     else
  101.       @sel_pos = @textbox.sel_spos
  102.     end
  103.     t = @textbox.text[0, @sel_pos]
  104.     s = contents.text_size(t).width
  105.     @curcor.x = x + standard_padding + s
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # ● 選取繪製
  109.   #--------------------------------------------------------------------------
  110.   def fill_selection(spos, epos)
  111.     return if spos == epos
  112.     rect = contents.rect.clone
  113.     t = @textbox.text[0, spos]
  114.     rect.x = contents.text_size(t).width
  115.     t = @textbox.text[spos, epos - spos]
  116.     rect.width = contents.text_size(t).width
  117.     contents.fill_rect(rect, @selection_color)
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ● 释放
  121.   #--------------------------------------------------------------------------
  122.   def dispose
  123.     @textbox.dispose
  124.     @curcor.bitmap.dispose
  125.     @curcor.dispose
  126.     super
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # ● 内容刷新
  130.   #--------------------------------------------------------------------------
  131.   def refresh
  132.     contents.clear
  133.     fill_selection(@textbox.sel_spos, @textbox.sel_epos)
  134.     change_color(normal_color)
  135.     txt = @textbox.password ? ("*" * @textbox.text.size) : @textbox.text
  136.     draw_text(contents.rect, txt)
  137.     update_cursor_pos
  138.     @tbmem.sel_spos = @textbox.sel_spos
  139.     @tbmem.sel_epos = @textbox.sel_epos
  140.     @tbmem.text = @textbox.text
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # ● 设置动作对应的处理方法
  144.   #--------------------------------------------------------------------------
  145.   def set_ok_handler(method)
  146.     @handler = method
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   # ● 调用处理方法
  150.   #--------------------------------------------------------------------------
  151.   def call_handler(symbol)
  152.     @handler[symbol].call if handle?(symbol)
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # ● “确定”和“取消”的处理
  156.   #--------------------------------------------------------------------------
  157.   def process_handling
  158.     return unless open? && active
  159.     return process_ok if ok_enabled? && @textbox.press_enter?
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # ● 获取确定处理的有效状态
  163.   #--------------------------------------------------------------------------
  164.   def ok_enabled?
  165.     return !@handler.nil?
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # ● 按下确定键时的处理
  169.   #--------------------------------------------------------------------------
  170.   def process_ok
  171.     Sound.play_ok
  172.     Input.update
  173.     deactivate
  174.     call_ok_handler
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 调用“确定”的处理方法
  178.   #--------------------------------------------------------------------------
  179.   def call_ok_handler
  180.     @handler.call if ok_enabled?
  181.   end
  182. end






附上范例和预览图


AdvanceInput.zip (326.79 KB, 下载次数: 888)      

点评

在下的用户名好像躺枪了……OTZ  发表于 2013-3-1 21:10

评分

参与人数 1星屑 +45 收起 理由
英顺的马甲 + 45 写得比我还完整==

查看全部评分

Lv1.梦旅人

梦石
0
星屑
50
在线时间
75 小时
注册时间
2011-6-14
帖子
19
2
发表于 2013-3-1 20:08:46 | 只看该作者
哈,今天刚想着这个就看到了好开森。
话说这个系统可以做成做成聊天吗?我本来是想用条件分歧判断当某角色的名字为“你好”时NPC回“大家好才是真的好”,某角色的名字为“你真丑”时NPC回“你更丑”之类的,但是这样对输入的符合程度要求很高,有办法判断关键字的吗?比如我只要输入带有“你,好”的字样,NPC就回“你好”?
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
105
在线时间
67 小时
注册时间
2007-12-16
帖子
75
3
 楼主| 发表于 2013-3-1 20:31:35 | 只看该作者
shellingford57 发表于 2013-3-1 20:08
哈,今天刚想着这个就看到了好开森。
话说这个系统可以做成做成聊天吗?我本来是想用条件分歧判断当某角色 ...

用正则表示式匹配?

/(你|好)/.match("你好")
/(你|好)/.match("你是?")
/(你|好)/.match("不好")
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
75 小时
注册时间
2011-6-14
帖子
19
4
发表于 2013-3-1 20:43:30 | 只看该作者
danny8376 发表于 2013-3-1 20:31
用正则表示式匹配?

/(你|好)/.match("你好")

一脸呆滞看。正则表达式是什么好吃么……

是在事件-脚本里使用么?
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
105
在线时间
67 小时
注册时间
2007-12-16
帖子
75
5
 楼主| 发表于 2013-3-1 21:14:34 | 只看该作者
shellingford57 发表于 2013-3-1 20:43
一脸呆滞看。正则表达式是什么好吃么……

是在事件-脚本里使用么?

匹配角色名的话
在条件分歧的脚本输入
/(你|好)/.match($game_actors[角色ID].name)
可以查一下怎用正则表示式
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
75 小时
注册时间
2011-6-14
帖子
19
6
发表于 2013-3-1 21:29:35 | 只看该作者
好的谢谢!
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1249
在线时间
669 小时
注册时间
2009-11-11
帖子
2787
7
发表于 2013-3-8 04:24:42 | 只看该作者
{:2_256:}顶下LZ
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
75 小时
注册时间
2011-6-14
帖子
19
8
发表于 2013-3-9 18:11:38 | 只看该作者
加入这个输入框脚本之后,走走路容易出现game map的脚本报错……是脚本冲突了么请问?
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
96 小时
注册时间
2009-7-6
帖子
18
9
发表于 2013-3-15 21:04:20 | 只看该作者
RMVA1.01a表示测试失败
窗体直接停止工作……
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
25 小时
注册时间
2013-3-23
帖子
7
10
发表于 2013-4-10 19:23:57 | 只看该作者
求助啊!我的复制进来之后,第一次还能输入,以后就怎么按键盘都不会动了,而且没有办法输入中文啊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-2 09:13

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表