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

Project1

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

[已经解决] 完美输入法问题

[复制链接]

Lv1.梦旅人

梦石
0
星屑
75
在线时间
26 小时
注册时间
2009-11-27
帖子
156
跳转到指定楼层
1
发表于 2010-10-20 20:22:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
我用了完美输入法,但是按空格时会有蹬~~瞪的响声,一下是脚本,谁能帮我解决
  1. #==============================================================================
  2. # ■ RInput
  3. #------------------------------------------------------------------------------
  4. #  全键盘处理的模块。
  5. #==============================================================================
  6. module RInput
  7. #--------------------------------------------------------------------------
  8. # ● 常量定义
  9. #--------------------------------------------------------------------------
  10. ENTER = 0x0D
  11. SPACE = 0x20
  12. UP = 0x26
  13. DOWN = 0x28
  14. LEFT = 0x25
  15. RIGHT = 0x27
  16. LCTRL = 0xA2
  17. #--------------------------------------------------------------------------
  18. # ● 临时Hash
  19. #--------------------------------------------------------------------------
  20. @R_Key_Hash = {}
  21. @R_Key_Repeat = {}

  22. #--------------------------------------------------------------------------
  23. # ● 唯一API
  24. #--------------------------------------------------------------------------
  25. GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
  26. #--------------------------------------------------------------------------
  27. # ● 单键处理
  28. #--------------------------------------------------------------------------
  29. def self.trigger?(rkey)
  30. result = GetKeyState.call(rkey)
  31. if @R_Key_Hash[rkey] == 1 and result != 0
  32. return false
  33. end
  34. if result != 0
  35. @R_Key_Hash[rkey] = 1
  36. return true
  37. else
  38. @R_Key_Hash[rkey] = 0
  39. return false
  40. end
  41. end
  42. end

  43. #==============================================================================
  44. # ■ EasyConv
  45. #------------------------------------------------------------------------------
  46. #  转码模块。
  47. #==============================================================================
  48. module EasyConv

  49. #--------------------------------------------------------------------------
  50. # ● 常量定义
  51. #--------------------------------------------------------------------------
  52. CP_ACP = 0
  53. CP_UTF8 = 65001

  54. #--------------------------------------------------------------------------
  55. # ● 模块函数
  56. #--------------------------------------------------------------------------
  57. module_function

  58. #--------------------------------------------------------------------------
  59. # ● 转码
  60. #--------------------------------------------------------------------------
  61. def s2u(text)

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

  64. len = m2w.call(CP_ACP, 0, text, -1, nil, 0)
  65. buf = "\0" * (len*2)
  66. m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2)

  67. len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil)
  68. ret = "\0" * len
  69. w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil)
  70. ret[-1] = ""

  71. return ret
  72. end

  73. #--------------------------------------------------------------------------
  74. # ● 转码
  75. #--------------------------------------------------------------------------
  76. def u2s(text)

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

  79. len = m2w.call(CP_UTF8, 0, text, -1, nil, 0)
  80. buf = "\0" * (len*2)
  81. m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2)

  82. len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
  83. ret = "\0" * len
  84. w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)

  85. return ret
  86. end

  87. end

  88. #==============================================================================
  89. # ■ TypeAPI
  90. #------------------------------------------------------------------------------
  91. #  输入法相关API模块。
  92. #==============================================================================
  93. module TypeAPI

  94. #--------------------------------------------------------------------------
  95. # ● API定义
  96. #--------------------------------------------------------------------------
  97. GPPS = Win32API.new("kernel32","GetPrivateProfileString",'pppplp','l')
  98. FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  99. CreateWindow = Win32API.new("NetGame","CreatWnd",'l','l')
  100. SetHK = Win32API.new("NetGame","SetHK",'v','v')
  101. GetText = Win32API.new("NetGame","GetWndText",'l','p')
  102. SetFocus = Win32API.new("user32","SetFocus",'l','l')
  103. IfBack = Win32API.new("NetGame","If_Back",'v','i')
  104. StartType = Win32API.new("NetGame","StartType",'v','v')
  105. EndType = Win32API.new("NetGame","EndType",'v','v')
  106. GetKeyInfos = Win32API.new("NetGame","GetKeyInfo",'v','i')


  107. #--------------------------------------------------------------------------
  108. # ● 模块函数
  109. #--------------------------------------------------------------------------
  110. module_function

  111. #--------------------------------------------------------------------------
  112. # ● 获取参数
  113. #--------------------------------------------------------------------------
  114. def getParam
  115. val = "\0" * 256
  116. GPPS.call("Game","Title","",val,256,"./Game.ini")
  117. val.delete!("\0")
  118. return val
  119. end

  120. #--------------------------------------------------------------------------
  121. # ● 获取窗口
  122. #--------------------------------------------------------------------------
  123. def findWindow
  124. return FindWindow.call("RGSS Player",self.getParam)
  125. end

  126. #--------------------------------------------------------------------------
  127. # ● 创建窗口
  128. #--------------------------------------------------------------------------
  129. def createWindow(hwnd)
  130. return CreateWindow.call(hwnd)
  131. end

  132. #--------------------------------------------------------------------------
  133. # ● 设置HK
  134. #--------------------------------------------------------------------------
  135. def setHK
  136. SetHK.call
  137. end

  138. #--------------------------------------------------------------------------
  139. # ● 获取文字
  140. #--------------------------------------------------------------------------
  141. def getText
  142. return EasyConv.s2u(GetText.call(@subhwnd))
  143. end

  144. #--------------------------------------------------------------------------
  145. # ● 设置焦点
  146. #--------------------------------------------------------------------------
  147. def setFocus
  148. SetFocus.call(@subhwnd)
  149. end

  150. #--------------------------------------------------------------------------
  151. # ● 转换焦点
  152. #--------------------------------------------------------------------------
  153. def lostFocus
  154. SetFocus.call(@hwnd)
  155. end

  156. #--------------------------------------------------------------------------
  157. # ● 退格判定
  158. #--------------------------------------------------------------------------
  159. def ifBack
  160. return IfBack.call
  161. end

  162. #--------------------------------------------------------------------------
  163. # ● 开始输入
  164. #--------------------------------------------------------------------------
  165. def startType
  166. StartType.call
  167. end

  168. #--------------------------------------------------------------------------
  169. # ● 结束输入
  170. #--------------------------------------------------------------------------
  171. def endType
  172. EndType.call
  173. end

  174. #--------------------------------------------------------------------------
  175. # ● 输入中特殊按键处理
  176. #--------------------------------------------------------------------------
  177. def getKeyInfos
  178. return GetKeyInfos.call
  179. end

  180. #--------------------------------------------------------------------------
  181. # ● 获取句柄
  182. #--------------------------------------------------------------------------
  183. @hwnd = self.findWindow

  184. @subhwnd = self.createWindow(@hwnd)

  185. #--------------------------------------------------------------------------
  186. # ● 设置HK应用
  187. #--------------------------------------------------------------------------
  188. self.setHK
  189. end

  190. #==============================================================================
  191. # ■ Type_Field
  192. #------------------------------------------------------------------------------
  193. #  处理输入域的类。
  194. #==============================================================================
  195. class Type_Field

  196. #--------------------------------------------------------------------------
  197. # ● 定义实例变量
  198. #--------------------------------------------------------------------------
  199. attr(:active)

  200. #--------------------------------------------------------------------------
  201. # ● 初始化
  202. #--------------------------------------------------------------------------
  203. def initialize(v,default_text = "",default_careth = nil,default_fonts = 16,\
  204. default_fontc = Color.new(255,255,255),size = 8)
  205. # active
  206. @active = true
  207. # 视口
  208. rect = v.rect
  209. @v = Viewport.new(rect.x,rect.y,rect.width,rect.height)
  210. @v.z = 10000
  211. @w = rect.width
  212. @h = rect.height
  213. # 属性
  214. @caret_h = default_careth.nil? ? @h : [@h,default_careth].min
  215. @caret_y = rect.y + (@h - @caret_h) / 2
  216. @font_size = [default_fonts,@h].min
  217. # 描绘contents
  218. @cts = Sprite.new(@v)
  219. @cts.bitmap = Bitmap.new(@w - 3,@h)
  220. @cts.bitmap.font.size = @font_size
  221. @cts.bitmap.font.color = default_fontc
  222. # 辅助属性
  223. @bk_count = 0
  224. @text = default_text.scan(/./)
  225. @max_size = size
  226. @caret_pos = @text.size
  227. @save_pos = @caret_pos
  228. # 光标Caret
  229. @v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
  230. @v1.z = 99999
  231. @caret_sp = Sprite.new(@v1)
  232. @caret_bitmap = Bitmap.new(3,@caret_h)
  233. @caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,255))
  234. @caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
  235. @caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
  236. @caret_sp.bitmap = @caret_bitmap
  237. @caret_sp.x = self.get_width(@text[0,@caret_pos].to_s) + 87
  238. @caret_sp.y = 0
  239. @caret_sp.visible = false
  240. @caret_flash_count = 0
  241. # 刷新
  242. refresh
  243. # 设置焦点
  244. TypeAPI.setFocus
  245. # 开始输入
  246. TypeAPI.startType
  247. end

  248. #--------------------------------------------------------------------------
  249. # ● 设置活动标记
  250. #--------------------------------------------------------------------------
  251. def active=(value)
  252. if value != true and value != false
  253. return
  254. end
  255. @active = value
  256. @caret_sp.visible = @active
  257. end

  258. #--------------------------------------------------------------------------
  259. # ● 释放
  260. #--------------------------------------------------------------------------
  261. def dispose
  262. @caret_bitmap.dispose
  263. @caret_sp.bitmap.dispose
  264. @caret_sp.dispose
  265. @cts.bitmap.dispose
  266. @cts.dispose
  267. @v.dispose
  268. @v1.dispose
  269. end

  270. #--------------------------------------------------------------------------
  271. # ● 刷新
  272. #--------------------------------------------------------------------------
  273. def refresh
  274. @cts.bitmap.clear
  275. @cts.bitmap.draw_text(85,0,@w,@h,@text.to_s)
  276. end

  277. #--------------------------------------------------------------------------
  278. # ● 获取文字
  279. #--------------------------------------------------------------------------
  280. def get_text
  281. return @text.to_s
  282. end

  283. #--------------------------------------------------------------------------
  284. # ● 取得字符宽度
  285. #--------------------------------------------------------------------------
  286. def get_width(str)
  287. return @cts.bitmap.text_size(str).width
  288. end

  289. #--------------------------------------------------------------------------
  290. # ● 更新
  291. #--------------------------------------------------------------------------
  292. def update
  293. @caret_sp.visible = @active
  294. # 非激活状态则返回
  295. unless @active
  296. return
  297. end
  298. # 获取按键信息
  299. key_info = TypeAPI.getKeyInfos
  300. case key_info
  301. when 0x09 # Tab
  302. # 按下 Tab 键的情况自己定义怎么处理
  303. return
  304. #when 0x0d # Enter
  305. # 按下 Enter 键的情况自己定义怎么处理
  306. # return
  307. when 0x1B # Esc
  308. # 按下 Esc 键的情况自己定义怎么处理
  309. return
  310. end
  311. self.update_text
  312. self.update_lrb
  313. self.update_back
  314. self.update_caret
  315. end

  316. #--------------------------------------------------------------------------
  317. # ● 更新文字
  318. #--------------------------------------------------------------------------
  319. def update_text
  320. # 文字刷新
  321. TypeAPI.setFocus
  322. text = TypeAPI.getText
  323. if text != ""
  324. for char in text.scan(/./)
  325. if self.get_text.size <= @max_size
  326. @text[@caret_pos,0] = char
  327. @caret_pos += 1
  328. else
  329. break
  330. end
  331. end
  332. refresh
  333. end
  334. end

  335. #--------------------------------------------------------------------------
  336. # ● 更新左右按键
  337. #--------------------------------------------------------------------------
  338. def update_lrb
  339. if RInput.trigger?(RInput::LEFT) and @caret_pos > 0
  340. @caret_pos -= 1
  341. return
  342. end
  343. if RInput.trigger?(RInput::RIGHT) and @caret_pos < @text.size
  344. @caret_pos += 1
  345. return
  346. end
  347. end

  348. #--------------------------------------------------------------------------
  349. # ● 更新退格
  350. #--------------------------------------------------------------------------
  351. def update_back
  352. # 前退格处理
  353. @bk_count += TypeAPI.ifBack
  354. if @bk_count > 0
  355. @bk_count -= 1
  356. if @caret_pos > 0
  357. @text.delete_at(@caret_pos - 1);@caret_pos -= 1;refresh
  358. end
  359. end
  360. end

  361. #--------------------------------------------------------------------------
  362. # ● 更新光标闪烁
  363. #--------------------------------------------------------------------------
  364. def update_caret
  365. # 闪烁计时
  366. @caret_flash_count += 1
  367. if @caret_flash_count == 20
  368. @caret_sp.visible = !@caret_sp.visible
  369. @caret_flash_count = 0
  370. end
  371. # Caret位置刷新
  372. if @save_pos != @caret_pos
  373. @save_pos = @caret_pos
  374. @caret_sp.x = self.get_width(@text[0,@save_pos].to_s) + 87
  375. end
  376. end
  377. end
复制代码

Lv1.梦旅人

炎发灼眼的讨伐者

梦石
0
星屑
50
在线时间
1707 小时
注册时间
2007-8-4
帖子
904
2
发表于 2010-10-21 12:25:41 | 只看该作者
版本不正确 最新版本不存在这个问题~~

点评

前段?后段……?= =b  发表于 2010-10-21 12:29
夏娜大人的签名好激动人心……  发表于 2010-10-21 12:28
RMXP&amp;RMVX通用Web化完成- -|||
回复 支持 反对

使用道具 举报

Lv3.寻梦者

宛若

梦石
0
星屑
1558
在线时间
526 小时
注册时间
2007-8-19
帖子
1493

极短24参与开拓者

3
发表于 2010-10-21 15:58:27 | 只看该作者
http://www.diyrpg.net/bbs/viewth ... D%CF%A6%CD%ED%BB%E1
其实我是搬运工- -
第五楼参考

评分

参与人数 1星屑 +332 收起 理由
fux2 + 332 认可答案

查看全部评分

[url=http://rpg.blue/thread-219730-1-1.html]http://unhero.sinaapp.com/wi.php[/url]
[color=Red]如你所见这是个死坑,没错这就是打我的脸用的[/color]
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
75
在线时间
26 小时
注册时间
2009-11-27
帖子
156
4
 楼主| 发表于 2010-10-22 16:44:58 | 只看该作者
最新版本不知怎么,用不起,谁帮我在这上面改
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-3 14:31

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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