赞 | 1 |
VIP | 2 |
好人卡 | 3 |
积分 | 10 |
经验 | 38159 |
最后登录 | 2024-4-24 |
在线时间 | 749 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 1034
- 在线时间
- 749 小时
- 注册时间
- 2013-2-15
- 帖子
- 116
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
夏娜到的完美输入法怎么创建域 怎么把输入的文字代入到角色名字啊! 求教!求范例!
完美输入法:
=begin
脚本:【完美输入法修正】
功能:输入法。
说明: 直接用Type_Field创建输入域即可进行输入,在此可根据Type_Field域对象
的活动标记active来自定义刷新等,在Type_Field中需要自己处理特殊按键
的处理方法。具体不明白之处请参考范例工程。
作者:灼眼的夏娜
补充: 至于以前那个版本也许很多人都注意到那个烦人的问题了吧,按Enter和Tab那
些会出现不爽的声音,这个版本解决了那个问题,并简化添加了Type_Field类
来方便创建输入域。
=end
#==============================================================================
# ■ RInput
#------------------------------------------------------------------------------
# 全键盘处理的模块。
#==============================================================================
module RInput
#--------------------------------------------------------------------------
# ● 常量定义
#--------------------------------------------------------------------------
ENTER = 0x0D
SPACE = 0x20
UP = 0x26
DOWN = 0x28
LEFT = 0x25
RIGHT = 0x27
LCTRL = 0xA2
LALT = 0xA4
#--------------------------------------------------------------------------
# ● 临时Hash
#--------------------------------------------------------------------------
@R_Key_Hash = {}
@R_Key_Repeat = {}
#--------------------------------------------------------------------------
# ● 唯一API
#--------------------------------------------------------------------------
GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
#--------------------------------------------------------------------------
# ● 单键处理
#--------------------------------------------------------------------------
def self.trigger?(rkey)
result = GetKeyState.call(rkey)
if @R_Key_Hash[rkey] == 1 and result != 0
return false
end
if result != 0
@R_Key_Hash[rkey] = 1
return true
else
@R_Key_Hash[rkey] = 0
return false
end
end
end
#==============================================================================
# ■ EasyConv
#------------------------------------------------------------------------------
# 转码模块。
#==============================================================================
module EasyConv
#--------------------------------------------------------------------------
# ● 常量定义
#--------------------------------------------------------------------------
CP_ACP = 0
CP_UTF8 = 65001
#--------------------------------------------------------------------------
# ● 模块函数
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
# ● 转码
#--------------------------------------------------------------------------
def s2u(text)
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
len = m2w.call(CP_ACP, 0, text, -1, nil, 0)
buf = "\0" * (len*2)
m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2)
len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil)
ret = "\0" * len
w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil)
ret[-1] = ""
return ret
end
#--------------------------------------------------------------------------
# ● 转码
#--------------------------------------------------------------------------
def u2s(text)
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
len = m2w.call(CP_UTF8, 0, text, -1, nil, 0)
buf = "\0" * (len*2)
m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2)
len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
ret = "\0" * len
w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
return ret
end
end
#==============================================================================
# ■ TypeAPI
#------------------------------------------------------------------------------
# 输入法相关API模块。
#==============================================================================
module TypeAPI
#--------------------------------------------------------------------------
# ● API定义
#--------------------------------------------------------------------------
GPPS = Win32API.new("kernel32","GetPrivateProfileString",'pppplp','l')
FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
CreateWindow = Win32API.new("NetGame","CreatWnd",'l','l')
SetHK = Win32API.new("NetGame","SetHK",'v','v')
GetText = Win32API.new("NetGame","GetWndText",'l','p')
SetFocus = Win32API.new("user32","SetFocus",'l','l')
IfBack = Win32API.new("NetGame","If_Back",'v','i')
StartType = Win32API.new("NetGame","StartType",'v','v')
EndType = Win32API.new("NetGame","EndType",'v','v')
GetKeyInfos = Win32API.new("NetGame","GetKeyInfo",'v','i')
#--------------------------------------------------------------------------
# ● 模块函数
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
# ● 获取参数
#--------------------------------------------------------------------------
def getParam
val = "\0" * 256
GPPS.call("Game","Title","",val,256,"./Game.ini")
val.delete!("\0")
return val
end
#--------------------------------------------------------------------------
# ● 获取窗口
#--------------------------------------------------------------------------
def findWindow
return FindWindow.call("RGSS Player",self.getParam)
end
#--------------------------------------------------------------------------
# ● 创建窗口
#--------------------------------------------------------------------------
def createWindow(hwnd)
return CreateWindow.call(hwnd)
end
#--------------------------------------------------------------------------
# ● 设置HK
#--------------------------------------------------------------------------
def setHK
SetHK.call
end
#--------------------------------------------------------------------------
# ● 获取文字
#--------------------------------------------------------------------------
def getText
return EasyConv.s2u(GetText.call(@subhwnd))
end
#--------------------------------------------------------------------------
# ● 设置焦点
#--------------------------------------------------------------------------
def setFocus
SetFocus.call(@subhwnd)
end
#--------------------------------------------------------------------------
# ● 转换焦点
#--------------------------------------------------------------------------
def lostFocus
SetFocus.call(@hwnd)
end
#--------------------------------------------------------------------------
# ● 退格判定
#--------------------------------------------------------------------------
def ifBack
return IfBack.call
end
#--------------------------------------------------------------------------
# ● 开始输入
#--------------------------------------------------------------------------
def startType
StartType.call
end
#--------------------------------------------------------------------------
# ● 结束输入
#--------------------------------------------------------------------------
def endType
EndType.call
end
#--------------------------------------------------------------------------
# ● 输入中特殊按键处理
#--------------------------------------------------------------------------
def getKeyInfos
return GetKeyInfos.call
end
#--------------------------------------------------------------------------
# ● 获取句柄
#--------------------------------------------------------------------------
@hwnd = self.findWindow
@subhwnd = self.createWindow(@hwnd)
#--------------------------------------------------------------------------
# ● 设置HK应用
#--------------------------------------------------------------------------
self.setHK
end
#==============================================================================
# ■ Type_Field
#------------------------------------------------------------------------------
# 处理输入域的类。
#==============================================================================
class Type_Field
# 属性设置 ###
BGC_COLOR = Color.new(255, 255, 255, 255) # 输入框底色
SBGC_COLOR = Color.new(0, 50, 200, 255) # 选中文字时的底色
MOUSE_FRAME = 10 # 鼠标双击最大间隔帧数
###
attr_reader :visible
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr(:active)
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize(rect,default_text = "",default_careth = nil,default_fonts = 32,\
default_fontc = Color.new(0,0,0))
# active
@active = false
@visible = true
# 视口
#rect = v.rect
@v = Viewport.new(rect)
@w = rect.width
@h = rect.height
@v.z = 300 ###
# 属性
@caret_h = default_careth.nil? ? @h : [@h,default_careth].min
@caret_y = rect.y + (@h - @caret_h) / 2
@font_size = [default_fonts,@h].min
# 描绘底色 ###
@bgc = Sprite.new(@v)
@bgc.bitmap = Bitmap.new(rect.width, rect.height)
@bgc.bitmap.fill_rect(0, 0, rect.width, rect.height, BGC_COLOR)
@bgc.z = 1
# 描绘文字选中时的底色 ###
@sbgc = Sprite.new(@v)
@sbgc.bitmap = Bitmap.new(rect.width, rect.height)
y = rect.height / 20
height = rect.height * 0.9
@sbgc.bitmap.fill_rect(0, y, 1, height, SBGC_COLOR)
@sbgc.z = 5
@sbgc.visible = false
# 描绘contents
@cts = Sprite.new(@v)
@cts.bitmap = Bitmap.new(@w - 3,@h)
@cts.bitmap.font.size = @font_size
@cts.bitmap.font.color = default_fontc
@cts.z = 10 ###
# 辅助属性
@mouse_frame = 0 ### 鼠标双击间隔帧数
@bk_count = 0
@text = default_text.scan(/./)
@max_width = @w - 3
@caret_pos = @text.size
@save_pos = @caret_pos
# 光标Caret
@v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
@v1.z = 300 ###
@caret_sp = Sprite.new(@v1)
@caret_bitmap = Bitmap.new(3,@caret_h)
@caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,180))
@caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
@caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
@caret_sp.bitmap = @caret_bitmap
@caret_sp.x = self.get_width(@text[0,@caret_pos].to_s)
@caret_sp.y = 0
@caret_sp.visible = false
@caret_flash_count = 0
@caret_pos_o = @caret_pos ### 选中文字时的起始位
@caret_pos_ox = @caret_sp.x ### 选中文字时起始位的x坐标
@text_caret = [@caret_pos, 0] ### 选中文字的首位及长度
# 刷新
refresh
# 设置焦点
TypeAPI.setFocus
# 开始输入
TypeAPI.startType
end
########################################
# 设置可见标记
##########################################
def visible=(value)
if value != true and value != false
return
end
@visible = value
@v.visible = @visible
@v1.visible = @visible
end
##########################################
# 数字限定
##########################################
def number?(text)
return ["1","2","3","4","5","6","7","8","9","0","-"].include?(text)
end
#########################################
# 鼠标左键确定光标位置
##########################################
def set_mouse_caret
rect = @v.rect
return unless Mouse.in_rect?(rect.x, rect.y, rect.width, rect.height)
mouse_x, mouse_y = Mouse.get_mouse_pos
@caret_pos = @text.size
update_caret
loop do
if mouse_x - rect.x + 5 > @caret_sp.x || @caret_pos < 1
return
else
@caret_pos -= 1
update_caret
end
end
end
######################## |
|