全键盘输入数值 1.1
#==============================================================================
# ■ 全键盘输入数值 1.1
# http://orzFly.com/RM/FullKeyboardInputNumber
#------------------------------------------------------------------------------
# 为『输入数值的处理』增加全键盘的支持。
#------------------------------------------------------------------------------
# - 1.1 by orzFly [[email protected]]
# * 修正 bug:屏蔽小键盘光标移动功能。
#
# - 1.0 by orzFly [[email protected]]
# * 首个版本
#==============================================================================
module OrzFly
RM = Game_Temp.method_defined?(:background_bitmap) unless const_defined?(:RM)
module FullKeyInputNumber
Keys = {
# 主键盘区数字 0~9
0x30 => 0, 0x31 => 1, 0x32 => 2, 0x33 => 3, 0x34 => 4,
0x35 => 5, 0x36 => 6, 0x37 => 7, 0x38 => 8, 0x39 => 9,
# 小键盘区数字 Numpad 0, 1, 3, 5, 7, 9
0x60 => 0, 0x61 => 1, 0x63 => 3, 0x65 => 5, 0x67 => 7, 0x69 => 9,
# Numpad 2, 4, 6, 8 较特殊,单独处理
# 退格 Backspace
0x08 => -1,
# 删除 Delete
0x2E => -2
}
GetKeyState = Win32API.new(
"user32", "GetAsyncKeyState", ['I'], 'I'
)
end
end
#==============================================================================
# ■ Window_InputNumber (XP) / Window_InputNumber (VX) 追加定义
#------------------------------------------------------------------------------
# 信息窗口内部使用、输入数值的窗口。
#==============================================================================
(OrzFly::RM ? Window_NumberInput : Window_InputNumber).class_eval {
def update
super
if active
catch(:loop) {
OrzFly::FullKeyInputNumber::Keys.keys.each { |key|
if OrzFly::FullKeyInputNumber::GetKeyState.call(key) & 1 != 0
OrzFly::RM ? Sound.play_cursor \
: $game_system.se_play($data_system.cursor_se)
process_key(OrzFly::FullKeyInputNumber::Keys[key])
throw(:loop)
end
}
}
if Input.repeat?(Input::UP)or Input.repeat?(Input::DOWN)
if OrzFly::FullKeyInputNumber::GetKeyState.call(0x68) != 0
process_key(8)
elsif OrzFly::FullKeyInputNumber::GetKeyState.call(0x62) != 0
process_key(2)
else
OrzFly::RM ? Sound.play_cursor \
: $game_system.se_play($data_system.cursor_se)
place = 10 ** (@digits_max - 1 - @index)
n = @number / place % 10
@number -= n * place
n = (n + 1) % 10 if Input.repeat?(Input::UP)
n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
@number += n * place
refresh
end
end
if Input.repeat?(Input::RIGHT)
if OrzFly::FullKeyInputNumber::GetKeyState.call(0x66) != 0
process_key(6)
else
OrzFly::RM ? Sound.play_cursor \
: $game_system.se_play($data_system.cursor_se)
if @index < @digits_max - 1 or Input.trigger?(Input::RIGHT)
@index = (@index + 1) % @digits_max
end
end
end
if Input.repeat?(Input::LEFT)
if OrzFly::FullKeyInputNumber::GetKeyState.call(0x64) != 0
process_key(4)
else
OrzFly::RM ? Sound.play_cursor \
: $game_system.se_play($data_system.cursor_se)
if @index > 0 or Input.trigger?(Input::LEFT)
@index = (@index + @digits_max - 1) % @digits_max
end
end
end
OrzFly::RM ? update_cursor \
: update_cursor_rect
end
end
def process_key(result)
if result >= 0 and result <= 9
place = 10 ** (@digits_max - 1 - @index)
@number = @number - (@number / place % 10) * place \
+ result * place
refresh
if @digits_max >= 2
@index = (@index + 1) % @digits_max
end
elsif result == -1
if @digits_max >= 2 and @index >= 1
@index = (@index + @digits_max - 1) % @digits_max
end
place = 10 ** (@digits_max - 1 - @index)
@number = @number - (@number / place % 10) * place
refresh
elsif result == -2
place = 10 ** (@digits_max - 1 - @index)
@number = @number - (@number / place % 10) * place
refresh
end
end
}