Project1

标题: 全键盘脚本不能全屏 [打印本页]

作者: 英顺的马甲    时间: 2011-2-15 14:31
标题: 全键盘脚本不能全屏
我用了全键盘脚本后,竟然无法全屏,连自动全屏也不行。

补充一下,我用的是这个脚本:
  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.   TAB               = 0x09
  36.   LCTRL             = 0xA2
  37.   LALT              = 0xA4
  38.   ESC               = 0x1B
  39.   #--------------------------------------------------------------------------
  40.   # ● 临时Hash
  41.   #--------------------------------------------------------------------------
  42.   @R_Key_Hash = {}
  43.   @R_Key_Repeat = {}
  44.   
  45.   #--------------------------------------------------------------------------
  46.   # ● 唯一API
  47.   #--------------------------------------------------------------------------
  48.   GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')

  49.   #--------------------------------------------------------------------------
  50.   # ● 单键处理
  51.   #--------------------------------------------------------------------------
  52.   def self.trigger?(rkey)
  53.     result = GetKeyState.call(rkey)
  54.     if @R_Key_Hash[rkey] == 1 and result != 0
  55.       return false
  56.     end
  57.     if result != 0
  58.       @R_Key_Hash[rkey] = 1
  59.       return true
  60.     else
  61.       @R_Key_Hash[rkey] = 0
  62.       return false
  63.     end
  64.   end

  65. end

  66. #==============================================================================
  67. # ■ EasyConv
  68. #------------------------------------------------------------------------------
  69. #  转码模块。
  70. #==============================================================================
  71. module EasyConv

  72.   #--------------------------------------------------------------------------
  73.   # ● 常量定义
  74.   #--------------------------------------------------------------------------
  75.   CP_ACP = 0
  76.   CP_UTF8 = 65001

  77.   #--------------------------------------------------------------------------
  78.   # ● 模块函数
  79.   #--------------------------------------------------------------------------
  80.   module_function
  81.   
  82.   #--------------------------------------------------------------------------
  83.   # ● 转码
  84.   #--------------------------------------------------------------------------
  85.   def s2u(text)

  86.     m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  87.     w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

  88.     len = m2w.call(CP_ACP, 0, text, -1, nil, 0)
  89.     buf = "\0" * (len*2)
  90.     m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2)

  91.     len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil)
  92.     ret = "\0" * len
  93.     w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil)
  94.     ret[-1] = ""
  95.    
  96.     return ret
  97.   end

  98.   #--------------------------------------------------------------------------
  99.   # ● 转码
  100.   #--------------------------------------------------------------------------
  101.   def u2s(text)
  102.    
  103.     m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  104.     w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

  105.     len = m2w.call(CP_UTF8, 0, text, -1, nil, 0)
  106.     buf = "\0" * (len*2)
  107.     m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2)

  108.     len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
  109.     ret = "\0" * len
  110.     w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
  111.    
  112.     return ret
  113.   end

  114. end

  115. #==============================================================================
  116. # ■ TypeAPI
  117. #------------------------------------------------------------------------------
  118. #  输入法相关API模块。
  119. #==============================================================================
  120. module TypeAPI
  121.   
  122.   #--------------------------------------------------------------------------
  123.   # ● API定义
  124.   #--------------------------------------------------------------------------
  125.   GPPS         = Win32API.new("kernel32","GetPrivateProfileString",'pppplp','l')
  126.   FindWindow   = Win32API.new("user32", "FindWindow", 'pp', 'i')
  127.   CreateWindow = Win32API.new("NetGame","CreatWnd",'l','l')
  128.   SetHK        = Win32API.new("NetGame","SetHK",'v','v')
  129.   GetText      = Win32API.new("NetGame","GetWndText",'l','p')
  130.   SetFocus     = Win32API.new("user32","SetFocus",'l','l')
  131.   IfBack       = Win32API.new("NetGame","If_Back",'v','i')
  132.   StartType    = Win32API.new("NetGame","StartType",'v','v')
  133.   EndType      = Win32API.new("NetGame","EndType",'v','v')
  134.   GetKeyInfos  = Win32API.new("NetGame","GetKeyInfo",'v','i')
  135.   
  136.   #--------------------------------------------------------------------------
  137.   # ● 模块函数
  138.   #--------------------------------------------------------------------------
  139.   module_function
  140.   
  141.   #--------------------------------------------------------------------------
  142.   # ● 获取参数
  143.   #--------------------------------------------------------------------------
  144.   def getParam
  145.     val = "\0" * 256
  146.     GPPS.call("Game","Title","",val,256,"./Game.ini")
  147.     val.delete!("\0")
  148.     return val
  149.   end
  150.   
  151.   #--------------------------------------------------------------------------
  152.   # ● 获取窗口
  153.   #--------------------------------------------------------------------------
  154.   def findWindow
  155.     return FindWindow.call("RGSS Player",self.getParam)
  156.   end
  157.   
  158.   #--------------------------------------------------------------------------
  159.   # ● 创建窗口
  160.   #--------------------------------------------------------------------------
  161.   def createWindow(hwnd)
  162.     return CreateWindow.call(hwnd)
  163.   end
  164.   
  165.   #--------------------------------------------------------------------------
  166.   # ● 设置HK
  167.   #--------------------------------------------------------------------------
  168.   def setHK
  169.     SetHK.call
  170.   end
  171.   
  172.   #--------------------------------------------------------------------------
  173.   # ● 获取文字
  174.   #--------------------------------------------------------------------------
  175.   def getText
  176.     return EasyConv.s2u(GetText.call(@subhwnd))
  177.   end
  178.   
  179.   #--------------------------------------------------------------------------
  180.   # ● 设置焦点
  181.   #--------------------------------------------------------------------------
  182.   def setFocus
  183.     SetFocus.call(@subhwnd)
  184.   end
  185.   
  186.   #--------------------------------------------------------------------------
  187.   # ● 转换焦点
  188.   #--------------------------------------------------------------------------
  189.   def lostFocus
  190.     SetFocus.call(@hwnd)
  191.   end
  192.   
  193.   #--------------------------------------------------------------------------
  194.   # ● 退格判定
  195.   #--------------------------------------------------------------------------
  196.   def ifBack
  197.     return IfBack.call
  198.   end
  199.   
  200.   #--------------------------------------------------------------------------
  201.   # ● 开始输入
  202.   #--------------------------------------------------------------------------
  203.   def startType
  204.     StartType.call
  205.   end
  206.   
  207.   #--------------------------------------------------------------------------
  208.   # ● 结束输入
  209.   #--------------------------------------------------------------------------
  210.   def endType
  211.     EndType.call
  212.   end
  213.   
  214.   #--------------------------------------------------------------------------
  215.   # ● 输入中特殊按键处理
  216.   #--------------------------------------------------------------------------
  217.   def getKeyInfos
  218.     return GetKeyInfos.call
  219.   end
  220.   
  221.   #--------------------------------------------------------------------------
  222.   # ● 获取句柄
  223.   #--------------------------------------------------------------------------
  224.   @hwnd    = self.findWindow
  225.   
  226.   @subhwnd = self.createWindow(@hwnd)

  227.   #--------------------------------------------------------------------------
  228.   # ● 设置HK应用
  229.   #--------------------------------------------------------------------------
  230.   self.setHK
  231.   
  232. end

  233. #==============================================================================
  234. # ■ Type_Field
  235. #------------------------------------------------------------------------------
  236. #  处理输入域的类。
  237. #==============================================================================
  238. class Type_Field
  239.   
  240.   #--------------------------------------------------------------------------
  241.   # ● 定义实例变量
  242.   #--------------------------------------------------------------------------
  243.   attr(:active)
  244.   
  245.   #--------------------------------------------------------------------------
  246.   # ● 初始化
  247.   #--------------------------------------------------------------------------
  248.   def initialize(v,default_text = "",default_careth = nil,default_fonts = 16,\
  249.     default_fontc = Color.new(255,255,255),size = 8)
  250.     # active
  251.     @active = true
  252.     # 视口
  253.     rect = v.rect
  254.     @v = Viewport.new(rect.x,rect.y,rect.width,rect.height)
  255.     @v.z = 10000
  256.     @w = rect.width
  257.     @h = rect.height
  258.     # 属性
  259.     @caret_h = default_careth.nil? ? @h : [@h,default_careth].min
  260.     @caret_y = rect.y + (@h - @caret_h) / 2
  261.     @font_size = [default_fonts,@h].min
  262.     # 描绘contents
  263.     @cts = Sprite.new(@v)
  264.     @cts.bitmap = Bitmap.new(@w - 3,@h)
  265.     @cts.bitmap.font.size = @font_size
  266.     @cts.bitmap.font.color = default_fontc
  267.     # 辅助属性
  268.     @bk_count = 0
  269.     @text = []#default_text.scan(/./)
  270.     @max_size = size
  271.     @caret_pos = @text.size
  272.     @save_pos = @caret_pos
  273.     # 光标Caret
  274.     @v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
  275.     @v1.z = 99999
  276.     @caret_sp = Sprite.new(@v1)
  277.     @caret_bitmap = Bitmap.new(3,@caret_h)
  278.     @caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,255))
  279.     @caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
  280.     @caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
  281.     @caret_sp.bitmap = @caret_bitmap
  282.     @caret_sp.x = self.get_width(@text[0,@caret_pos].to_s) + 87
  283.     @caret_sp.y = 0
  284.     @caret_sp.visible = false
  285.     @caret_flash_count = 0
  286.     # 刷新
  287.     refresh
  288.     # 设置焦点
  289.     TypeAPI.setFocus
  290.     # 开始输入
  291.     TypeAPI.startType
  292.     @test = []
  293.   end
  294.   
  295.   #--------------------------------------------------------------------------
  296.   # ● 设置活动标记
  297.   #--------------------------------------------------------------------------
  298.   def active=(value)
  299.     if value != true and value != false
  300.       return
  301.     end
  302.     @active = value
  303.     @caret_sp.visible = @active
  304.   end
  305.   
  306.   #--------------------------------------------------------------------------
  307.   # ● 释放
  308.   #--------------------------------------------------------------------------
  309.   def dispose
  310.     @caret_bitmap.dispose
  311.     @caret_sp.bitmap.dispose
  312.     @caret_sp.dispose
  313.     @cts.bitmap.dispose
  314.     @cts.dispose
  315.     @v.dispose
  316.     @v1.dispose
  317.     TypeAPI.endType
  318.   end

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

  326.   #--------------------------------------------------------------------------
  327.   # ● 获取文字
  328.   #--------------------------------------------------------------------------
  329.   def get_text
  330.     return @text.to_s
  331.   end

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

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




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