Project1

标题: 用了这个输入法就不能全屏,晕,求新输入法! [打印本页]

作者: 妖娆成殇    时间: 2010-10-26 19:34
标题: 用了这个输入法就不能全屏,晕,求新输入法!
本帖最后由 妖娆成殇 于 2010-10-26 20:22 编辑
  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(255,255,255),size = 8)
  249.     # active
  250.     @active = true
  251.     # 视口
  252.     rect = v.rect
  253.     @v = Viewport.new(rect.x,rect.y,rect.width,rect.height)
  254.     @v.z = 10000
  255.     @w = rect.width
  256.     @h = rect.height
  257.     # 属性
  258.     @caret_h = default_careth.nil? ? @h : [@h,default_careth].min
  259.     @caret_y = rect.y + (@h - @caret_h) / 2
  260.     @font_size = [default_fonts,@h].min
  261.     # 描绘contents
  262.     @cts = Sprite.new(@v)
  263.     @cts.bitmap = Bitmap.new(@w - 3,@h)
  264.     @cts.bitmap.font.size = @font_size
  265.     @cts.bitmap.font.color = default_fontc
  266.     # 辅助属性
  267.     @bk_count = 0
  268.     @text = default_text.scan(/./)
  269.     @max_size = size
  270.     @caret_pos = @text.size
  271.     @save_pos = @caret_pos
  272.     # 光标Caret
  273.     @v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
  274.     @v1.z = 99999
  275.     @caret_sp = Sprite.new(@v1)
  276.     @caret_bitmap = Bitmap.new(3,@caret_h)
  277.     @caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,255))
  278.     @caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
  279.     @caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
  280.     @caret_sp.bitmap = @caret_bitmap
  281.     @caret_sp.x = self.get_width(@text[0,@caret_pos].to_s) + 87
  282.     @caret_sp.y = 0
  283.     @caret_sp.visible = false
  284.     @caret_flash_count = 0
  285.     # 刷新
  286.     refresh
  287.     # 设置焦点
  288.     TypeAPI.setFocus
  289.     # 开始输入
  290.     TypeAPI.startType
  291.   end
  292.   
  293.   #--------------------------------------------------------------------------
  294.   # ● 设置活动标记
  295.   #--------------------------------------------------------------------------
  296.   def active=(value)
  297.     if value != true and value != false
  298.       return
  299.     end
  300.     @active = value
  301.     @caret_sp.visible = @active
  302.   end
  303.   
  304.   #--------------------------------------------------------------------------
  305.   # ● 释放
  306.   #--------------------------------------------------------------------------
  307.   def dispose
  308.     @caret_bitmap.dispose
  309.     @caret_sp.bitmap.dispose
  310.     @caret_sp.dispose
  311.     @cts.bitmap.dispose
  312.     @cts.dispose
  313.     @v.dispose
  314.     @v1.dispose
  315.   end

  316.   #--------------------------------------------------------------------------
  317.   # ● 刷新
  318.   #--------------------------------------------------------------------------
  319.   def refresh
  320.     @cts.bitmap.clear
  321.     @cts.bitmap.draw_text(85,0,@w,@h,@text.to_s)
  322.   end

  323.   #--------------------------------------------------------------------------
  324.   # ● 获取文字
  325.   #--------------------------------------------------------------------------
  326.   def get_text
  327.     return @text.to_s
  328.   end

  329.   #--------------------------------------------------------------------------
  330.   # ● 取得字符宽度
  331.   #--------------------------------------------------------------------------
  332.   def get_width(str)
  333.     return @cts.bitmap.text_size(str).width
  334.   end
  335.   
  336.   #--------------------------------------------------------------------------
  337.   # ● 更新
  338.   #--------------------------------------------------------------------------
  339.   def update
  340.     @caret_sp.visible = @active
  341.     # 非激活状态则返回
  342.     unless @active
  343.       return
  344.     end
  345.     # 获取按键信息
  346.     key_info = TypeAPI.getKeyInfos
  347.     case key_info
  348.     when 0x09 # Tab
  349.       # 按下 Tab 键的情况自己定义怎么处理
  350.       return
  351.     when 0x0d # Enter
  352.       # 按下 Enter 键的情况自己定义怎么处理
  353.       return
  354.     when 0x1B # Esc
  355.       # 按下 Esc 键的情况自己定义怎么处理
  356.       return
  357.     end
  358.     self.update_text
  359.     self.update_lrb
  360.     self.update_back
  361.     self.update_caret
  362.   end

  363.   #--------------------------------------------------------------------------
  364.   # ● 更新文字
  365.   #--------------------------------------------------------------------------
  366.   def update_text
  367.     # 文字刷新
  368.     TypeAPI.setFocus
  369.     text = TypeAPI.getText
  370.     if text != ""
  371.       for char in text.scan(/./)
  372.         if self.get_text.size <= @max_size
  373.           @text[@caret_pos,0] = char
  374.           @caret_pos += 1
  375.         else
  376.           break
  377.         end
  378.       end
  379.       refresh
  380.     end
  381.   end
  382.   
  383.   #--------------------------------------------------------------------------
  384.   # ● 更新左右按键
  385.   #--------------------------------------------------------------------------
  386.   def update_lrb
  387.     if RInput.trigger?(RInput::LEFT) and @caret_pos > 0
  388.       @caret_pos -= 1
  389.       return
  390.     end
  391.     if RInput.trigger?(RInput::RIGHT) and @caret_pos < @text.size
  392.       @caret_pos += 1
  393.       return
  394.     end
  395.   end
  396.   
  397.   #--------------------------------------------------------------------------
  398.   # ● 更新退格
  399.   #--------------------------------------------------------------------------
  400.   def update_back
  401.     # 前退格处理
  402.     @bk_count += TypeAPI.ifBack
  403.     if @bk_count > 0
  404.       @bk_count -= 1
  405.       if @caret_pos > 0
  406.         @text.delete_at(@caret_pos - 1);@caret_pos -= 1;refresh
  407.       end
  408.     end
  409.   end
  410.   
  411.   #--------------------------------------------------------------------------
  412.   # ● 更新光标闪烁
  413.   #--------------------------------------------------------------------------
  414.   def update_caret
  415.     # 闪烁计时
  416.     @caret_flash_count += 1
  417.     if @caret_flash_count == 20
  418.       @caret_sp.visible = !@caret_sp.visible
  419.       @caret_flash_count = 0
  420.     end
  421.     # Caret位置刷新
  422.     if @save_pos != @caret_pos
  423.       @save_pos = @caret_pos
  424.       @caret_sp.x = self.get_width(@text[0,@save_pos].to_s) + 87
  425.     end
  426.   end
  427.   
  428. end
  429.   
  430.   
复制代码

作者: 壬穹雷光    时间: 2010-10-26 19:36
脚本应该用代码发...
作者: 灼眼的夏娜    时间: 2010-10-27 09:06
这个输入法会和全屏冲突 故屏蔽掉了全部~~ 要在全屏下使用 建议采用思思的内部输入法·
作者: goahead    时间: 2010-10-27 09:53
提示: 作者被禁止或删除 内容自动屏蔽




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