本帖最后由 taroxd 于 2015-9-14 20:47 编辑
module Keyboard API = Win32API.new('user32', 'GetAsyncKeyState', 'I', 'I') # 以按键码为键,连续按下的帧数为值的 hash @states = Hash.new { |h, k| h[k] = 0 } def self.update @states.each_key do |key| @states[key] = API.call(key) < 0 ? @states[key] + 1 : 0 end end def self.clear @states.clear end def self.trigger?(key) @states[key] == 1 end end class Scene_Map alias_method :ub_20150914, :update_basic def update_basic ub_20150914 Keyboard.update return unless Keyboard.trigger? 'R'.ord s = $game_switches if s[1] s[1] = false $game_party.members.each { |actor| actor.remove_state 1 } else s[1] = true $game_party.members.each { |actor| actor.add_state 1 } end end end
module Keyboard
API = Win32API.new('user32', 'GetAsyncKeyState', 'I', 'I')
# 以按键码为键,连续按下的帧数为值的 hash
@states = Hash.new { |h, k| h[k] = 0 }
def self.update
@states.each_key do |key|
@states[key] = API.call(key) < 0 ? @states[key] + 1 : 0
end
end
def self.clear
@states.clear
end
def self.trigger?(key)
@states[key] == 1
end
end
class Scene_Map
alias_method :ub_20150914, :update_basic
def update_basic
ub_20150914
Keyboard.update
return unless Keyboard.trigger? 'R'.ord
s = $game_switches
if s[1]
s[1] = false
$game_party.members.each { |actor| actor.remove_state 1 }
else
s[1] = true
$game_party.members.each { |actor| actor.add_state 1 }
end
end
end
|