1、Kboard.press?(key) 同 Input.press?(key) 2、Kboard.repeat?(key) 同 Input.repeat?(key) 3、Kboard.trigger?(key) 同 Input.trigger?(key) module Kboard module_function @R_Key_Hash = {} @R_Key_Repeat = {} GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I') def press?(rkey) return GetKeyState.call(rkey) != 0 end def repeat?(rkey) result = GetKeyState.call(rkey) if result != 0 if @R_Key_Repeat[rkey].nil? @R_Key_Repeat[rkey] = 0 return true end @R_Key_Repeat[rkey] += 1 else @R_Key_Repeat[rkey] = nil @R_Key_Hash[rkey] = 0 end if !@R_Key_Repeat[rkey].nil? and @R_Key_Repeat[rkey] > 4 # 4乃准确数字 @R_Key_Repeat[rkey] = 0 return true else return false end end def 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 |