Project1

标题: 关于数值输入的问题 [打印本页]

作者: banbianzhang    时间: 2013-10-1 08:55
标题: 关于数值输入的问题
本帖最后由 myownroc 于 2013-10-1 08:59 编辑

有没有单独的数值输入脚本可以改成键盘输入?夏娜的太难用了。
或者教教我怎么用夏娜的脚本吧……多谢大侠
以下是夏娜的脚本  @Person
  1. =begin
  2. 脚本:【完美输入法修正】
  3.   
  4. 功能:输入法。
  5.   
  6. 说明: 直接用Type_Field创建输入域即可进行输入,在此可根据Type_Field域对象
  7.   
  8.        的活动标记active来自定义刷新等,在Type_Field中需要自己处理特殊按键
  9.         
  10.        的处理方法。具体不明白之处请参考范例工程。
  11. 作者:灼眼的夏娜
  12.   
  13. 补充: 至于以前那个版本也许很多人都注意到那个烦人的问题了吧,按Enter和Tab那
  14.   
  15.        些会出现不爽的声音,这个版本解决了那个问题,并简化添加了Type_Field类
  16.         
  17.        来方便创建输入域。
  18. =end
  19. #==============================================================================
  20. # ■ RInput
  21. #------------------------------------------------------------------------------
  22. #  全键盘处理的模块。
  23. #==============================================================================
  24. module RInput
  25.   
  26. #--------------------------------------------------------------------------
  27. # ● 常量定义
  28. #--------------------------------------------------------------------------
  29. ENTER             = 0x0D
  30. SPACE             = 0x20
  31. UP                = 0x26
  32. DOWN              = 0x28
  33. LEFT              = 0x25
  34. RIGHT             = 0x27
  35.   
  36. LCTRL             = 0xA2
  37. LALT              = 0xA4
  38. #--------------------------------------------------------------------------
  39. # ● 临时Hash
  40. #--------------------------------------------------------------------------
  41. @R_Key_Hash = {}
  42. @R_Key_Repeat = {}
  43.   
  44. #--------------------------------------------------------------------------
  45. # ● 唯一API
  46. #--------------------------------------------------------------------------
  47. GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
  48. #--------------------------------------------------------------------------
  49. # ● 单键处理
  50. #--------------------------------------------------------------------------
  51. def self.trigger?(rkey)
  52.    result = GetKeyState.call(rkey)
  53.    if @R_Key_Hash[rkey] == 1 and result != 0
  54.      return false
  55.    end
  56.    if result != 0
  57.      @R_Key_Hash[rkey] = 1
  58.      return true
  59.    else
  60.      @R_Key_Hash[rkey] = 0
  61.      return false
  62.    end
  63. end
  64. end
  65. #==============================================================================
  66. # ■ EasyConv
  67. #------------------------------------------------------------------------------
  68. #  转码模块。
  69. #==============================================================================
  70. module EasyConv
  71. #--------------------------------------------------------------------------
  72. # ● 常量定义
  73. #--------------------------------------------------------------------------
  74. CP_ACP = 0
  75. CP_UTF8 = 65001
  76. #--------------------------------------------------------------------------
  77. # ● 模块函数
  78. #--------------------------------------------------------------------------
  79. module_function
  80.   
  81. #--------------------------------------------------------------------------
  82. # ● 转码
  83. #--------------------------------------------------------------------------
  84. def s2u(text)
  85.    m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  86.    w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  87.    len = m2w.call(CP_ACP, 0, text, -1, nil, 0)
  88.    buf = "\0" * (len*2)
  89.    m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2)
  90.    len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil)
  91.    ret = "\0" * len
  92.    w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil)
  93.    ret[-1] = ""
  94.    
  95.    return ret
  96. end
  97. #--------------------------------------------------------------------------
  98. # ● 转码
  99. #--------------------------------------------------------------------------
  100. def u2s(text)
  101.    
  102.    m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  103.    w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  104.    len = m2w.call(CP_UTF8, 0, text, -1, nil, 0)
  105.    buf = "\0" * (len*2)
  106.    m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2)
  107.    len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
  108.    ret = "\0" * len
  109.    w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
  110.    
  111.    return ret
  112. end
  113. end
  114. #==============================================================================
  115. # ■ TypeAPI
  116. #------------------------------------------------------------------------------
  117. #  输入法相关API模块。
  118. #==============================================================================
  119. module TypeAPI
  120.   
  121. #--------------------------------------------------------------------------
  122. # ● API定义
  123. #--------------------------------------------------------------------------
  124. GPPS         = Win32API.new("kernel32","GetPrivateProfileString",'pppplp','l')
  125. FindWindow   = Win32API.new("user32", "FindWindow", 'pp', 'i')
  126. CreateWindow = Win32API.new("NetGame","CreatWnd",'l','l')
  127. SetHK        = Win32API.new("NetGame","SetHK",'v','v')
  128. GetText      = Win32API.new("NetGame","GetWndText",'l','p')
  129. SetFocus     = Win32API.new("user32","SetFocus",'l','l')
  130. IfBack       = Win32API.new("NetGame","If_Back",'v','i')
  131. StartType    = Win32API.new("NetGame","StartType",'v','v')
  132. EndType      = Win32API.new("NetGame","EndType",'v','v')
  133. GetKeyInfos  = Win32API.new("NetGame","GetKeyInfo",'v','i')
  134.   
  135. #--------------------------------------------------------------------------
  136. # ● 模块函数
  137. #--------------------------------------------------------------------------
  138. module_function
  139.   
  140. #--------------------------------------------------------------------------
  141. # ● 获取参数
  142. #--------------------------------------------------------------------------
  143. def getParam
  144.    val = "\0" * 256
  145.    GPPS.call("Game","Title","",val,256,"./Game.ini")
  146.    val.delete!("\0")
  147.    return val
  148. end
  149.   
  150. #--------------------------------------------------------------------------
  151. # ● 获取窗口
  152. #--------------------------------------------------------------------------
  153. def findWindow
  154.    return FindWindow.call("RGSS Player",self.getParam)
  155. end
  156.   
  157. #--------------------------------------------------------------------------
  158. # ● 创建窗口
  159. #--------------------------------------------------------------------------
  160. def createWindow(hwnd)
  161.    return CreateWindow.call(hwnd)
  162. end
  163.   
  164. #--------------------------------------------------------------------------
  165. # ● 设置HK
  166. #--------------------------------------------------------------------------
  167. def setHK
  168.    SetHK.call
  169. end
  170.   
  171. #--------------------------------------------------------------------------
  172. # ● 获取文字
  173. #--------------------------------------------------------------------------
  174. def getText
  175.    return EasyConv.s2u(GetText.call(@subhwnd))
  176. end
  177.   
  178. #--------------------------------------------------------------------------
  179. # ● 设置焦点
  180. #--------------------------------------------------------------------------
  181. def setFocus
  182.    SetFocus.call(@subhwnd)
  183. end
  184.   
  185. #--------------------------------------------------------------------------
  186. # ● 转换焦点
  187. #--------------------------------------------------------------------------
  188. def lostFocus
  189.    SetFocus.call(@hwnd)
  190. end
  191.   
  192. #--------------------------------------------------------------------------
  193. # ● 退格判定
  194. #--------------------------------------------------------------------------
  195. def ifBack
  196.    return IfBack.call
  197. end
  198.   
  199. #--------------------------------------------------------------------------
  200. # ● 开始输入
  201. #--------------------------------------------------------------------------
  202. def startType
  203.    StartType.call
  204. end
  205.   
  206. #--------------------------------------------------------------------------
  207. # ● 结束输入
  208. #--------------------------------------------------------------------------
  209. def endType
  210.    EndType.call
  211. end
  212.   
  213. #--------------------------------------------------------------------------
  214. # ● 输入中特殊按键处理
  215. #--------------------------------------------------------------------------
  216. def getKeyInfos
  217.    return GetKeyInfos.call
  218. end
  219.   
  220. #--------------------------------------------------------------------------
  221. # ● 获取句柄
  222. #--------------------------------------------------------------------------
  223. @hwnd    = self.findWindow
  224.   
  225. @subhwnd = self.createWindow(@hwnd)
  226. #--------------------------------------------------------------------------
  227. # ● 设置HK应用
  228. #--------------------------------------------------------------------------
  229. self.setHK
  230.   
  231. end
  232. #==============================================================================
  233. # ■ Type_Field
  234. #------------------------------------------------------------------------------
  235. #  处理输入域的类。
  236. #==============================================================================
  237. class Type_Field
  238.   
  239. #--------------------------------------------------------------------------
  240. # ● 定义实例变量
  241. #--------------------------------------------------------------------------
  242. attr(:active)
  243.   
  244. #--------------------------------------------------------------------------
  245. # ● 初始化
  246. #--------------------------------------------------------------------------
  247. def initialize(v,default_text = "",default_careth = nil,default_fonts = 16,\
  248.    default_fontc = Color.new(0,0,0))
  249.    # active
  250.    @active = true
  251.    # 视口
  252.    rect = v.rect
  253.    @v = Viewport.new(rect.x,rect.y,rect.width,rect.height)
  254.    [url=home.php?mod=space&uid=133944]@w[/url] = rect.width
  255.    @h = rect.height
  256.    # 属性
  257.    @caret_h = default_careth.nil? ? @h : [@h,default_careth].min
  258.    @caret_y = rect.y + (@h - @caret_h) / 2
  259.    @font_size = [default_fonts,@h].min
  260.    # 描绘contents
  261.    @cts = Sprite.new(@v)
  262.    @cts.bitmap = Bitmap.new([url=home.php?mod=space&uid=133944]@w[/url] - 3,@h)
  263.    @cts.bitmap.font.size = @font_size
  264.    @cts.bitmap.font.color = default_fontc
  265.    # 辅助属性
  266.    @bk_count = 0
  267.    @text = default_text.scan(/./)
  268.    @max_width = @w - 3
  269.    @caret_pos = @text.size
  270.    @save_pos = @caret_pos
  271.    # 光标Caret
  272.    @v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
  273.    @caret_sp = Sprite.new(@v1)
  274.    @caret_bitmap = Bitmap.new(3,@caret_h)
  275.    @caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,180))
  276.    @caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
  277.    @caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
  278.    @caret_sp.bitmap = @caret_bitmap
  279.    @caret_sp.x = self.get_width(@text[0,@caret_pos].to_s)
  280.    @caret_sp.y = 0
  281.    @caret_sp.visible = false
  282.    @caret_flash_count = 0
  283.    # 刷新
  284.    refresh
  285.    # 设置焦点
  286.    TypeAPI.setFocus
  287.    # 开始输入
  288.    TypeAPI.startType
  289. end
  290.   
  291. #--------------------------------------------------------------------------
  292. # ● 设置活动标记
  293. #--------------------------------------------------------------------------
  294. def active=(value)
  295.    if value != true and value != false
  296.      return
  297.    end
  298.    @active = value
  299.    @caret_sp.visible = @active
  300. end
  301.   
  302. #--------------------------------------------------------------------------
  303. # ● 释放
  304. #--------------------------------------------------------------------------
  305. def dispose
  306.    @caret_bitmap.dispose
  307.    @caret_sp.bitmap.dispose
  308.    @caret_sp.dispose
  309.    @cts.bitmap.dispose
  310.    @cts.dispose
  311.    @v.dispose
  312.    @v1.dispose
  313. end
  314. #--------------------------------------------------------------------------
  315. # ● 刷新
  316. #--------------------------------------------------------------------------
  317. def refresh
  318.    @cts.bitmap.clear
  319.    @cts.bitmap.draw_text(0,0,@w,@h,@text.to_s)
  320. end
  321. #--------------------------------------------------------------------------
  322. # ● 获取文字
  323. #--------------------------------------------------------------------------
  324. def get_text
  325.    return @text.to_s
  326. end
  327. #--------------------------------------------------------------------------
  328. # ● 取得字符宽度
  329. #--------------------------------------------------------------------------
  330. def get_width(str)
  331.    return @cts.bitmap.text_size(str).width
  332. end
  333.   
  334. #--------------------------------------------------------------------------
  335. # ● 更新
  336. #--------------------------------------------------------------------------
  337. def update
  338.    # 非激活状态则返回
  339.    unless @active
  340.      return
  341.    end
  342.    # 获取按键信息
  343.    key_info = TypeAPI.getKeyInfos
  344.    case key_info
  345.    when 0x09 # Tab
  346.      # 按下 Tab 键的情况自己定义怎么处理
  347.      return
  348.    when 0x0d # Enter
  349.      # 按下 Enter 键的情况自己定义怎么处理
  350.      return
  351.    when 0x1B # Esc
  352.      # 按下 Esc 键的情况自己定义怎么处理
  353.      return
  354.    end
  355.    self.update_text
  356.    self.update_lrb
  357.    self.update_back
  358.    self.update_caret
  359. end
  360. #--------------------------------------------------------------------------
  361. # ● 更新文字
  362. #--------------------------------------------------------------------------
  363. def update_text
  364.    # 文字刷新
  365.    TypeAPI.setFocus
  366.    text = TypeAPI.getText
  367.    if text != ""
  368.      for char in text.scan(/./)
  369.        if self.get_width(@text.to_s + char) <= @max_width
  370.          @text[@caret_pos,0] = char
  371.          @caret_pos += 1
  372.        else
  373.          break
  374.        end
  375.      end
  376.      refresh
  377.    end
  378. end
  379.   
  380. #--------------------------------------------------------------------------
  381. # ● 更新左右按键
  382. #--------------------------------------------------------------------------
  383. def update_lrb
  384.    if RInput.trigger?(RInput::LEFT) and @caret_pos > 0
  385.      @caret_pos -= 1
  386.      return
  387.    end
  388.    if RInput.trigger?(RInput::RIGHT) and @caret_pos < @text.size
  389.      @caret_pos += 1
  390.      return
  391.    end
  392. end
  393.   
  394. #--------------------------------------------------------------------------
  395. # ● 更新退格
  396. #--------------------------------------------------------------------------
  397. def update_back
  398.    # 前退格处理
  399.    @bk_count += TypeAPI.ifBack
  400.    if @bk_count > 0
  401.      @bk_count -= 1
  402.      if @caret_pos > 0
  403.        @text.delete_at(@caret_pos - 1);@caret_pos -= 1;refresh
  404.      end
  405.    end
  406. end
  407.   
  408. #--------------------------------------------------------------------------
  409. # ● 更新光标闪烁
  410. #--------------------------------------------------------------------------
  411. def update_caret
  412.    # 闪烁计时
  413.    @caret_flash_count += 1
  414.    if @caret_flash_count == 20
  415.      @caret_sp.visible = !@caret_sp.visible
  416.      @caret_flash_count = 0
  417.    end
  418.    # Caret位置刷新
  419.    if @save_pos != @caret_pos
  420.      @save_pos = @caret_pos
  421.      @caret_sp.x = self.get_width(@text[0,@save_pos].to_s)
  422.    end
  423. end
  424.   
  425. end
复制代码

作者: 紫英晓狼1130    时间: 2013-10-1 11:01
这里有一个输入法脚本
http://rpg.blue/forum.php?mod=viewthread&tid=243422
作者: 张咚咚    时间: 2013-10-1 11:44
仿网游 输入法.rar (243.12 KB, 下载次数: 33)
作者: 张咚咚    时间: 2013-10-1 11:45
仿网游 输入法.rar (243.12 KB, 下载次数: 22)
作者: chd114    时间: 2013-10-1 11:49
  1. #==============================================================================
  2. # ■ Kernel
  3. #------------------------------------------------------------------------------
  4. #  该模块中定义了可供所有类使用的方法。Object 类中包含了该模块。
  5. #==============================================================================
  6. module Kernel
  7.   #--------------------------------------------------------------------------
  8.   # ● 需要的 Windows API 函数
  9.   #--------------------------------------------------------------------------
  10.   GetWindowThreadProcessId = Win32API.new("user32", "GetWindowThreadProcessId", "LP", "L")
  11.   GetWindow = Win32API.new("user32", "GetWindow", "LL", "L")
  12.   GetClassName = Win32API.new("user32", "GetClassName", "LPL", "L")
  13.   GetCurrentThreadId = Win32API.new("kernel32", "GetCurrentThreadId", "V", "L")
  14.   GetForegroundWindow = Win32API.new("user32", "GetForegroundWindow", "V", "L")
  15.   #--------------------------------------------------------------------------
  16.   # ● 获取窗口句柄
  17.   #--------------------------------------------------------------------------
  18.   def get_hWnd
  19.     # 获取调用线程(RM 的主线程)的进程标识
  20.     threadID = GetCurrentThreadId.call
  21.     # 获取 Z 次序中最靠前的窗口
  22.     hWnd = GetWindow.call(GetForegroundWindow.call, 0)
  23.     # 枚举所有窗口
  24.     while hWnd != 0
  25.       # 如果创建该窗口的线程标识匹配本线程标识
  26.       if threadID == GetWindowThreadProcessId.call(hWnd, 0)
  27.         # 分配一个 11 个字节的缓冲区
  28.         className = " " * 11
  29.         # 获取该窗口的类名
  30.         GetClassName.call(hWnd, className, 12)
  31.         # 如果匹配 RGSS Player 则跳出循环
  32.         break if className == "RGSS Player"
  33.       end
  34.       # 获取下一个窗口
  35.       hWnd = GetWindow.call(hWnd, 2)
  36.     end
  37.     return hWnd
  38.   end
  39. end
复制代码
  1. #==============================================================================
  2. # ■ TextBox  by EngShun
  3. #------------------------------------------------------------------------------
  4. #  输入框的类。
  5. #==============================================================================
  6. class TextBox
  7.   #--------------------------------------------------------------------------
  8.   # ● 设置API
  9.   #--------------------------------------------------------------------------
  10.   CreateWindow = Win32API.new('user32','CreateWindowEx','lpplllllllll','l')
  11.   ShowWindow = Win32API.new('user32','ShowWindow','ll','l')
  12.   DestroyWindow = Win32API.new('user32','DestroyWindow','l','l')
  13.   GetWindowText = Win32API.new('user32','GetWindowText','lpl','l')
  14.   SetWindowText = Win32API.new("user32", "SetWindowText", "lp", "l")
  15.   GetWindowTextLength = Win32API.new('user32','GetWindowTextLength','l','l')
  16.   UpdateWindow = Win32API.new('user32','UpdateWindow','l','i')
  17.   SetFocus = Win32API.new('user32','SetFocus','l','l')
  18.   SendMessage = Win32API.new('user32','SendMessage','llll','l')
  19.   MultiByteToWideChar = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  20.   WideCharToMultiByte = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
  21.   GetKeyState = Win32API.new("user32","GetAsyncKeyState",'I','I')
  22.   #--------------------------------------------------------------------------
  23.   # ● 定义实例变量
  24.   #--------------------------------------------------------------------------
  25.   attr_accessor :focus
  26.   #--------------------------------------------------------------------------
  27.   # ● 初始化
  28.   #--------------------------------------------------------------------------
  29.   def initialize(text = "",limit = 8,number=false)
  30.     c = 0x40011000
  31.     c = (c|0x00001000) if number
  32.     [url=home.php?mod=space&uid=37298]@Window[/url] = CreateWindow.call(0, 'EDIT', u2s(text), c, 0, 480-22, 640, 22, get_hWnd, 0, 0, 0)
  33.     SendMessage.call(@window,0xC5,limit,0)
  34.     @focus = true
  35.     @disposed = false
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # ● 释放
  39.   #--------------------------------------------------------------------------
  40.   def dispose
  41.     @disposed = true
  42.     DestroyWindow.call(@window)
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ● 刷新
  46.   #--------------------------------------------------------------------------
  47.   def update
  48.     return if !@focus or @disposed
  49.     UpdateWindow.call(@window)
  50.     SetFocus.call(@window)
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # ● 获取内容
  54.   #--------------------------------------------------------------------------
  55.   def text
  56.     return if @disposed
  57.     l = GetWindowTextLength.call(@window)
  58.     str = "\0" * (l + 1)
  59.     GetWindowText.call(@window, str, l+1)
  60.     return s2u(str.delete("\0"))
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # ● 更改内容
  64.   #--------------------------------------------------------------------------
  65.   def text=(str)
  66.     SetWindowText.call(@window, u2s(str))
  67.     return if @disposed
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # ● 获取光标位置
  71.   #--------------------------------------------------------------------------
  72.   def sel_pos
  73.     return if @disposed
  74.     return (SendMessage.call(@window,0xB0,0,0) % 65535) / 2
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # ● 设置光标位置
  78.   #--------------------------------------------------------------------------
  79.   def sel_pos=(i)
  80.     return if @disposed
  81.     SendMessage.call(@window,0xB1,i,i)
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● 获取光标位置
  85.   #--------------------------------------------------------------------------
  86.   def limit
  87.     return if @disposed
  88.     return SendMessage.call(@window,0xD5,0,0)
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # ● 设置光标位置
  92.   #--------------------------------------------------------------------------
  93.   def limit=(i)
  94.     return if @disposed
  95.     SendMessage.call(@window,0xC5,i,0)
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 是否按下回车键
  99.   #--------------------------------------------------------------------------
  100.   def press_enter?
  101.     return if @disposed
  102.     return (@focus and (GetKeyState.call(13) != 0))
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # ● 转码:系统转UTF-8
  106.   #--------------------------------------------------------------------------
  107.   def s2u(text)
  108.     len = MultiByteToWideChar.call(0, 0, text, -1, nil, 0);
  109.     buf = "\0" * (len*2)
  110.     MultiByteToWideChar.call(0, 0, text, -1, buf, buf.size/2);
  111.     len = WideCharToMultiByte.call(65001, 0, buf, -1, nil, 0, nil, nil);
  112.     ret = "\0" * len
  113.     WideCharToMultiByte.call(65001, 0, buf, -1, ret, ret.size, nil, nil);
  114.     return ret.delete("\000")
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● 转码:UTF-8转系统
  118.   #--------------------------------------------------------------------------
  119.   def u2s(text)
  120.     len = MultiByteToWideChar.call(65001, 0, text, -1, nil, 0);
  121.     buf = "\0" * (len*2)
  122.     MultiByteToWideChar.call(65001, 0, text, -1, buf, buf.size/2);
  123.     len = WideCharToMultiByte.call(0, 0, buf, -1, nil, 0, nil, nil);
  124.     ret = "\0" * len
  125.     WideCharToMultiByte.call(0, 0, buf, -1, ret, ret.size, nil, nil);
  126.     return ret.delete("\000")
  127.   end
  128.   private :u2s ,:s2u # 定义私有功能
  129. end
复制代码
  1. #==============================================================================
  2. # ■ Sprite_TextBox  by EngShun
  3. #------------------------------------------------------------------------------
  4. #  显示输入框用的活动块。
  5. #==============================================================================
  6. class Sprite_TextBox < Sprite
  7.   #--------------------------------------------------------------------------
  8.   # ● 设置缓存的类
  9.   #--------------------------------------------------------------------------
  10.   Cache = Struct.new(:bc ,:fc ,:fs ,:text ,:sel_pos)
  11.   #--------------------------------------------------------------------------
  12.   # ● 定义实例变量
  13.   #--------------------------------------------------------------------------
  14.   attr_accessor :textbox
  15.   attr_accessor :back_color
  16.   #--------------------------------------------------------------------------
  17.   # ● 初始化
  18.   #--------------------------------------------------------------------------
  19.   def initialize(x = 0,y = 0,w = 128,h = 32,bc = Color.new(255,255,255),fc = Color.new(0,0,0),tb = TextBox.new)
  20.     super(nil)
  21.     self.x = x
  22.     self.y = y
  23.     self.bitmap = Bitmap.new(w,h)
  24.     self.bitmap.font.color = fc
  25.     @back_color = bc
  26.     @textbox = tb
  27.     [url=home.php?mod=space&uid=341345]@Cache[/url] = Cache.new
  28.     refresh
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # ● 刷新
  32.   #--------------------------------------------------------------------------
  33.   def update
  34.     super
  35.     return unless @textbox.focus
  36.     @textbox.update
  37.     if (self.bitmap.font.color != @cache.fc) or
  38.        (self.bitmap.font.size != @cache.fs) or
  39.        (@textbox.sel_pos != @cache.sel_pos) or
  40.        (@textbox.text != @cache.text) or
  41.        (@back_color != @cache.bc)
  42.       refresh
  43.     end
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # ● 释放
  47.   #--------------------------------------------------------------------------
  48.   def dispose
  49.     self.bitmap.dispose
  50.     @textbox.dispose
  51.     super
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # ● 内容刷新
  55.   #--------------------------------------------------------------------------
  56.   def refresh
  57.     @cache.fc = self.bitmap.font.color
  58.     @cache.fs = self.bitmap.font.size
  59.     @cache.sel_pos = @textbox.sel_pos
  60.     @cache.text = @textbox.text
  61.     @cache.bc = @back_color
  62.     w = self.bitmap.width
  63.     h = self.bitmap.height
  64.     self.bitmap.fill_rect(0,0,w,h,@back_color)
  65.     self.bitmap.draw_text(4,0,w-4,h,@textbox.text)
  66.     t = @textbox.text.scan(/./)[0,@textbox.sel_pos].join("")
  67.     s = self.bitmap.text_size(t).width
  68.     self.bitmap.draw_text((4 + s)-16,0,32,h,"|",1)
  69.   end
  70.   private :refresh # 设置私有功能
  71. end
复制代码
  1. #==============================================================================
  2. # ■ Scene_Name
  3. #------------------------------------------------------------------------------
  4. #  处理名称输入画面的类。
  5. #==============================================================================
  6. class Scene_Name
  7.   #--------------------------------------------------------------------------
  8.   # ● 主处理
  9.   #--------------------------------------------------------------------------
  10.   def main
  11.     [url=home.php?mod=space&uid=95897]@actor[/url] = $game_actors[$game_temp.name_actor_id]
  12.     @window = Window_Base.new(0,176,640,128)
  13.     @window.contents = Bitmap.new(576,96)
  14.     @window.draw_actor_graphic(@actor, 64, 80)
  15.     @window.contents.draw_text(128,0,480,32,"请输入名称:")
  16.     @sprite_tb = Sprite_TextBox.new(144,240,464)
  17.     @sprite_tb.z = 500
  18.     @sprite_tb.textbox.limit = $game_temp.name_max_char
  19.     @sprite_tb.textbox.text = @actor.name
  20.     @sprite_tb.textbox.sel_pos = @actor.name.length
  21.     Graphics.transition
  22.     loop do
  23.       Graphics.update
  24.       Input.update
  25.       update
  26.       break if $scene != self
  27.     end
  28.     Graphics.freeze
  29.     @sprite_tb.dispose
  30.     @window.dispose
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # ● 刷新画面
  34.   #--------------------------------------------------------------------------
  35.   def update
  36.     @sprite_tb.update
  37.     if @sprite_tb.textbox.press_enter?
  38.       if @sprite_tb.textbox.text == ""
  39.         $game_system.se_play($data_system.buzzer_se)
  40.         return
  41.       end
  42.       @actor.name = @sprite_tb.textbox.text
  43.       $scene = Scene_Map.new
  44.     end
  45.   end
  46. end
复制代码
用这个的话你可以做文字+数字符号混合输入密码···按顺序把脚本放入脚本编辑器Main上方就可以了,即插即用
作者: banbianzhang    时间: 2013-10-2 14:33
你们上面的脚本我都看过了,但是你们貌似没搞懂我的意思…………
我想把事件中的“数值输入的处理”改成键盘输入,你们给的脚本不对

我自己搜了一个数值输入的脚本,可以用数字键和方向键输入数字,可不可以把方向键输入给去掉?


#==============================================================================
# ■ 全键盘输入数值 1.1
#   http://orzFly.com/RM/FullKeyboardInputNumber
#------------------------------------------------------------------------------
# 为『输入数值的处理』增加全键盘的支持。
#------------------------------------------------------------------------------
# - 1.1 by orzFly [[email protected]]
#   * 修正 bug:屏蔽小键盘光标移动功能。
#
# - 1.0 by orzFly [[email protected]]
#   * 首个版本
#==============================================================================
module OrzFly
  RM = Game_Temp.method_defined?(:background_bitmap) unless const_defined?(:RM)
  module FullKeyInputNumber
    Keys = {
      # 主键盘区数字 0~9
      0x30 => 0, 0x31 => 1, 0x32 => 2, 0x33 => 3, 0x34 => 4,
      0x35 => 5, 0x36 => 6, 0x37 => 7, 0x38 => 8, 0x39 => 9,
      # 小键盘区数字 Numpad 0, 1, 3, 5, 7, 9
      0x60 => 0, 0x61 => 1, 0x63 => 3, 0x65 => 5, 0x67 => 7, 0x69 => 9,
      #              Numpad 2, 4, 6, 8 较特殊,单独处理
      # 退格 Backspace
      0x08 => -1,
      # 删除 Delete
      0x2E => -2
    }
    GetKeyState = Win32API.new(
      "user32", "GetAsyncKeyState", ['I'], 'I'
    )
  end
end

#==============================================================================
# ■ Window_InputNumber (XP) / Window_InputNumber (VX) 追加定义
#------------------------------------------------------------------------------
#  信息窗口内部使用、输入数值的窗口。
#==============================================================================
(OrzFly::RM ? Window_NumberInput : Window_InputNumber).class_eval {
  def update
    super
    if active
      catch(:loop) {
        OrzFly::FullKeyInputNumber::Keys.keys.each { |key|
          if OrzFly::FullKeyInputNumber::GetKeyState.call(key) & 1 != 0
            OrzFly::RM ? Sound.play_cursor                          \
                       : $game_system.se_play($data_system.cursor_se)
            process_key(OrzFly::FullKeyInputNumber::Keys[key])
            throw(:loop)
          end
        }
      }
      if Input.repeat?(Input::UP)or Input.repeat?(Input::DOWN)
        if OrzFly::FullKeyInputNumber::GetKeyState.call(0x68) != 0
          process_key(8)
        elsif OrzFly::FullKeyInputNumber::GetKeyState.call(0x62) != 0
          process_key(2)
        else
          OrzFly::RM ? Sound.play_cursor                          \
                     : $game_system.se_play($data_system.cursor_se)
          place = 10 ** (@digits_max - 1 - @index)
          n = @Number / place % 10
          @number -= n * place
          n = (n + 1) % 10 if Input.repeat?(Input::UP)
          n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
          @number += n * place
          refresh
        end
      end
      if Input.repeat?(Input::RIGHT)
        if OrzFly::FullKeyInputNumber::GetKeyState.call(0x66) != 0
          process_key(6)
        else
          OrzFly::RM ? Sound.play_cursor                          \
                     : $game_system.se_play($data_system.cursor_se)
          if @Index < @digits_max - 1 or Input.trigger?(Input::RIGHT)
            @index = (@index + 1) % @digits_max
          end
        end
      end
      if Input.repeat?(Input::LEFT)
        if OrzFly::FullKeyInputNumber::GetKeyState.call(0x64) != 0
          process_key(4)
        else
          OrzFly::RM ? Sound.play_cursor                          \
                     : $game_system.se_play($data_system.cursor_se)
          if @index > 0 or Input.trigger?(Input::LEFT)
            @index = (@index + @digits_max - 1) % @digits_max
          end
        end
      end
      OrzFly::RM ? update_cursor    \
                 : update_cursor_rect
    end
  end
  def process_key(result)
    if result >= 0 and result <= 9
      place = 10 ** (@digits_max - 1 - @index)
      @number = @number - (@number / place % 10) * place \
                        + result * place
      refresh
      if @digits_max >= 2
        @index = (@index + 1) % @digits_max
      end
    elsif result == -1
      if @digits_max >= 2 and @index >= 1
        @index = (@index + @digits_max - 1) % @digits_max
      end
      place = 10 ** (@digits_max - 1 - @index)
      @number = @number -  (@number / place % 10) * place
      refresh
    elsif result == -2
      place = 10 ** (@digits_max - 1 - @index)
      @number = @number -  (@number / place % 10) * place
      refresh
    end
  end
}
作者: chd114    时间: 2013-10-19 14:30
banbianzhang 发表于 2013-10-2 14:33
你们上面的脚本我都看过了,但是你们貌似没搞懂我的意思…………
我想把事件中的“数值输入的处理”改成键 ...

你确定是这个脚本吗···最后那个大括号哪里来的?




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1