#
# initial module settings - Created by OriginalWij and Yanfly
#
GetKeyState = Win32API.new("user32", "GetAsyncKeyState", "i", "i")
GetCapState = Win32API.new("user32", "GetKeyState", "i", "i")
KeyRepeatCounter = {}
module_function
#
# alias method: update - Created by OriginalWij
#
class <<self; alias input_update_debug update; end
def self.update
input_update_debug
for key in KeyRepeatCounter.keys
if (GetKeyState.call(key).abs & 0x8000 == 0x8000)
KeyRepeatCounter[key] += 1
else
KeyRepeatCounter.delete(key)
end
end
end
#
# alias method: press? - Created by OriginalWij
#
class <<self; alias input_press_debug press?; end
def self.press?(key)
return input_press_debug(key) if default_key?(key)
adjusted_key = adjust_key(key)
return true unless KeyRepeatCounter[adjusted_key].nil?
return key_pressed?(adjusted_key)
end
#
# alias method: trigger? - Created by OriginalWij
#
class <<self; alias input_trigger_debug trigger?; end
def self.trigger?(key)
return input_trigger_debug(key) if default_key?(key)
adjusted_key = adjust_key(key)
count = KeyRepeatCounter[adjusted_key]
return ((count == 0) || (count.nil? ? key_pressed?(adjusted_key) : false))
end
#
# alias method: repeat? - Created by OriginalWij
#
class <<self; alias input_repeat_debug repeat?; end
def self.repeat?(key)
return input_repeat_debug(key) if default_key?(key)
adjusted_key = adjust_key(key)
count = KeyRepeatCounter[adjusted_key]
return true if count == 0
if count.nil?
return key_pressed?(adjusted_key)
else
return (count >= 23 && (count - 23) % 6 == 0)
end
end
#
# new method: default_key? - Created by Yanfly
#
def self.default_key?(key)
return true if key.is_a?(Integer) && key < 30
return DEFAULT.include?(key)
end
#
# new method: adjust_key - Created by OriginalWij
#
def self.adjust_key(key)
key -= 130 if key.between?(130, 158)
return key
end
#
# new method: key_pressed? - Created by OriginalWij
#
def self.key_pressed?(key)
if (GetKeyState.call(key).abs & 0x8000 == 0x8000)
KeyRepeatCounter[key] = 0
return true
end
return false
end
#
# new method: typing? - Created by Yanfly
#
def self.typing?
return true if repeat?(SPACE)
for i in 'A'..'Z'
return true if repeat?(LETTERS)
end
for i in 0...NUMBERS.size
return true if repeat?(NUMBERS)
return true if repeat?(NUMPAD)
end
for key in Extras
return true if repeat?(key)
end
return false
end
#
# new method: key_type - Created by Yanfly
#
def self.key_type
return " " if repeat?(SPACE)
for i in 'A'..'Z'
next unless repeat?(LETTERS)
return upcase? ? i.upcase : i.downcase
end
for i in 0...NUMBERS.size
return i.to_s if repeat?(NUMPAD)
if !press?(SHIFT)
return i.to_s if repeat?(NUMBERS)
elsif repeat?(NUMBERS)
case i
when 1; return "!"
when 2; return "@"
when 3; return "#"
when 4; return "$"
when 5; return "%"
when 6; return "^"
when 7; return "&"
when 8; return "*"
when 9; return "("
when 0; return ")"
end
end
end
for key in Extras
next unless repeat?(key)
case key
when USCORE; return press?(SHIFT) ? "_" : "-"
when EQUALS; return press?(SHIFT) ? "+" : "="
when LBRACE; return press?(SHIFT) ? "{" : "["
when RBRACE; return press?(SHIFT) ? "}" : "]"
when BSLASH; return press?(SHIFT) ? "|" : "\\"
when SCOLON; return press?(SHIFT) ? ":" : ";"
when QUOTE; return press?(SHIFT) ? '"' : "'"
when COMMA; return press?(SHIFT) ? "<" : ","
when PERIOD; return press?(SHIFT) ? ">" : "."
when SLASH; return press?(SHIFT) ? "?" : "/"
when NMUL; return "*"
when NPLUS; return "+"
when NSEP; return ","
when NMINUS; return "-"
when NDECI; return "."
when NDIV; return "/"
end
end
return ""
end
#
# new method: upcase? - Created by Yanfly
#
def self.upcase?
return !press?(SHIFT) if GetCapState.call(CAPS) == 1
return true if press?(SHIFT)
return false
end
end # Input[/php]
Ko được , cái này được 1 thằng chế nhưng lỗi thì phải
Chưa tìm thấy ...
[php]#===============================================================================
# ** Extended Input System - Scripter's TOOL
#
# Author Ramiro
# Version 1.0
# Usage Level Hard for non scripters
# Requeriments None
#
# Instructions of use:
#
# 1 About Keyboard:
#
# 1.1 Keyboard Normal methods:
# you have the options to choose the original inputs:
#
# Keyboard.trigger?(sym[, sym, ...])
# Keyboard.press?(sym[, sym, ...])
# Keyboard.repeat?(sym[, sym, ...])
# Keyboard.release?(sym[, sym, ...])
#
# If you put more than 1 symbol or key id, you will get true if any of the
# keys choosed are selected.
# Examples of key symbols are:
# :CTRL (Control key), :LEFT_SHIFT (Left Shift), :ARROW_UP ( arrow up)
# :FN (with N from 1 to 12) to function keys
# You can check the ASCII_SYM table to view all the other Symbols.
# You can also use the number key eg: 65, means "A key". Check an ASCII table
# if you wish to know more about.
#
# You can check insthead of any of the pressed keys, all of the pressed keys.
#
# Keyboard.all_trigger?(sym[, sym, ...])
# Keyboard.all_press?(sym[, sym, ...])
# Keyboard.all_repeat?(sym[, sym, ...])
# Keyboard.all_release?(sym[, sym, ...])
#
# 1.2 How each method works:
#
# trigger is activated on the first frame the key was pressed, and not again
# until you release the key.
#
# press will give true each time the key is pressed, even on consecutive frames.
#
# repeat is a special case, it will check between frames, alternating between
# true and false if the key is pressed. its more convenient to use it if you want
# a slower version of 'press'
#
# Finally release, will be set to true, when you release the key. but only the
# first frame.
#
# 1.3 Keyboard's input character:
#
# You can get the keyboard's input character using the next function:
#
# Keyboard.character
#
# This system supports custom Keyboard layauts with api calls, you yes,
# you'll never have to configure each Keyboard version or use the "Only English"
# keyboard.
#
# 2.1 About the mouse.
#
# The Mouse has great influence on modern pcs, or at least when touchscreens
# were expensive and were hard to manufacture.
#
# It doesn't matter anyway, because touchscreens still acts like a Mouse
# sometimes.
#
# 2.2 Mouse position
#
# If you use a Mouse, you can use this next functions:
#
# Mouse.screen_x
# Mouse.screen_y
# Mouse.x
# Mouse.y
#
# if you want to know the real position (in the OS) use screen_x and screen_y
# functions.
#
# to get the relative positions (the position in the game) of the Mouse, use x,
# and y.
#
# 2.3 Mouse keys
#
# You have this same functions from the Keyboard, with some differences:
#
# Mouse.trigger?([sym])
# Mouse.press?([sym])
# Mouse.repeat?([sym])
# Mouse.release?([sym])
#
# sym has to be: :PRIMARY, :SECONDARY, :MIDDLE, :MOUSE4 or :MOUSE5
#
# Each one refered to a key of the mouse, it supports left handed mouses,
# primary, means the principal key, not the left key, and the same for the
# secondary.
#
# if you don't use ANY of the symbols, it will be :PRIMARY by default.
#
# 2.4 Getting areas of mouse:
#
# you can check if the mouse is inside a rect with the next commands:
#
# Mouse.in_area?(x, y, width, height)
# Mouse.in_area?(rect)
#
# both returns true if the mouse is INSIDE the rect and false if the mouse is
# OUTSIDE.
#
# 3.1 About Gamepad
#
# Gamepad works quite different like all the other Inputs, well not really.
# to use it just call this:
#
# Gamepad[index].method(args)
#
# Where index is a number from 1 to the supported numbers of gamepad by
# the system.
#
# On windows 2k it can only support 2 Gamepads
# On windows XP and newer it can support up to 16 Gamepads at least
#
# You can always get the max number of joypads by using the function:
#
# Gamepad.pugged_joypads
#
# 3.2 Getting Gamepad input
#
# The functions are te same of the Keyboard:
#
# Gamepad[id].trigger?(sym[, sym, ...])
# Gamepad[id].press?(sym[, sym, ...])
# Gamepad[id].repeat?(sym[, sym, ...])
# Gamepad[id].release?(sym[, sym, ...])
#
# Gamepad[id].all_trigger?(sym[, sym, ...])
# Gamepad[id].all_press?(sym[, sym, ...])
# Gamepad[id].all_repeat?(sym[, sym, ...])
# Gamepad[id].all_release?(sym[, sym, ...])
#
# The difference here is about the symbols, you can only use symbols and has to
# be one of the next:
# :UP, :DOWN, :LEFT, :RIGHT, :JOY1, :JOY2, :JOY3, :JOY4, :JOY5, :JOY6, :JOY7,
# :JOY8, :JOY9, :JOY10, :JOY11, :JOY12
#
# If you like a more RM Style Gamepad, you can still use the original syms:
#
# :A, :B, :C, :X, :Y, :Z, :L, :R
#
# The are refering from JOY1, to JOY8
#
# if you wisth to know the X axis, the Y axis or the Z axis of an analog stick
# (if supported by your gamepad/s, of course) you can use this functions:
#
# Gamepad[id].x
# Gamepad[id].y
# Gamepad[id].z
#
# They work giving a number from - 32511 to 32511.
#
# Have fun scripting some strange things.
#
#===============================================================================
module Api
#Keyboard Apis
GetKeyboardState = Win32API.new('user32','GetKeyboardState', 'P', 'I')
GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout','L', 'L')
MapVirtualKeyEx = Win32API.new('user32', 'MapVirtualKeyEx', 'IIL', 'I')
ToUnicodeEx = Win32API.new('user32', 'ToUnicodeEx', 'LLPPILL', 'L')
GetKeyState = Win32API.new("user32","GetKeyState",'I','I')
ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
GetPrivateProfileStringA = Win32API.new('kernel32', 'GetPrivateProfileStringA','pppplp', 'l')
FindWindowA = Win32API.new('user32', 'FindWindowA', 'pp', 'l')
#Mouse Apis
SwapMouseButton = Win32API.new('user32', 'SwapMouseButton', 'L', 'L')
GetDoubleClickTime = Win32API.new('user32', 'GetDoubleClickTime', '', 'L')
GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'v')
SetCursorPos = Win32API.new('user32', 'SetCursorPos', 'ii', 'I')
GetWindowRect = Win32API.new('user32', 'GetWindowRect', 'lp', 'v')
FindWindowEx = Win32API.new('user32', 'FindWindowEx', 'llpp', 'i')
ShowCursor = Win32API.new("user32", "ShowCursor", "i", "i")
#Gamepad Apis
JoyGetNumDevs = Win32API.new("winmm","joyGetNumDevs", 'v', "i")
JoyGetPos = Win32API.new("winmm","joyGetPos", 'lp', "l")
# Get the RGSS window
game_name = "\0" * 256
GetPrivateProfileStringA.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
game_name.delete!("\0")
h = FindWindowA.call('RGSS Player', game_name)
if h
RGSS_WINDOW = h
else
RGSS_WINDOW = FindWindowA.call('RGSS Player', nil)
end
def self.get_character(vk)
c = Api::MapVirtualKeyEx.call(vk, 2, @language_layout)
return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
vsc = Api::MapVirtualKeyEx.call(vk, 0, @language_layout)
result = "\0" * 2
length = Api::ToUnicodeEx.call(vk, vsc, @state, result, 2, 0, @language_layout)
length == 0 ? '' : result
end
def self.unicode_to_utf8(string)
result = ''
begin
string.unpack('S*').each do |c|
if c < 0x0080
result += c.chr
elsif c < 0x0800
result += (0xC0 | (c >> 6)).chr
result += (0x80 | (c & 0x3F)).chr
else
result += (0xE0 | (c >> 12)).chr
result += (0x80 | ((c >> 12) & 0x3F)).chr
result += (0x80 | (c & 0x3F)).chr
end
end
rescue
end
result
end
def self.make_character
result = '' @frame_keys.each do |key|
c = get_character(key)
result += c if c != ''
end
result ? unicode_to_utf8(result) : ''
end
class << self
alias ramiro_input_mod_update update
def update
Keyboard.update
Mouse.update
Gamepad.update
ramiro_input_mod_update
end
def [](index) @pads = {} if !@pads
return pads[index]
end
def get_first_input_type
for i in 6...256
return [:keyboard, i] if Keyboard.trigger?(i)
end
for i in 1..16
Gamepad::KEYS.each do |key|
return [:gamepad, [i, key]] if Gamepad.trigger?(key)
end
end
return nil
end
def get_name(item)
case item[0]
when :keyobard
return "KEY #{get_key_name(item[1])}"
when :gamepad
return "PAD#{item[1][0]} #{get_joykey_name(item[1][1])}"
end
end
def get_key_name(number)
KEYS_NAMES[number]
end
def get_joykey_name(sym)
case sym
when :UP
return 'UP'
when :DOWN
return 'DOWN'
when :LEFT
return 'LEFT'
when :RIGHT
return 'RIGHT'
when :JOY1
return '1'
when :JOY2
return '2'
when :JOY3
return '3'
when :JOY4
return '4'
when :JOY5
return '5'
when :JOY6
return '6'
when :JOY7
return '7'
when :JOY8
return '8'
when :JOY9
return '9'
when :JOY10
return '10'
when :JOY11
return '11'
when :JOY12
return '12'
end
return '???'
end
end
end[/php]
Toàn tự đặt câu hỏi rồi tự tìm câu trả lời...
Một cảm giác tự kỉ ko hề nhẹ...
Như hôm trước, đã coi cái Scene_menu rồi , nhưng về vấn đề này thì nó cho diễn biến ra theo thướng cho người chơi chọn hoặc Cancel , và thực sự ko hiểu gì hết
Comments
Tức là ngắn gọn như vầy , làm sao để đưa một cái biến vào một cái def của một class mới tạo ra.
keyword là gamesvts :-"
với lại hình như làm lại diễn đàn rồi , làm gì còn dữ liệu đâu
Cũng thấy mấy guide, nhưng cơ bản quá, ko phải thứ mình cần
dù sao cũng đang cố học các thứ liên quan đến def và class
http://stackoverflow.com/questions/2527830/ruby-calling-class-method-from-instance
Cái nào working nhé , test mấy cái đều dở hơi rồi
mình đang dùng cái này nhé
[php]#===============================================================================
# ** Extended Input System - Scripter's TOOL
#
# Author Ramiro
# Version 1.0
# Usage Level Hard for non scripters
# Requeriments None
#
# Instructions of use:
#
# 1 About Keyboard:
#
# 1.1 Keyboard Normal methods:
# you have the options to choose the original inputs:
#
# Keyboard.trigger?(sym[, sym, ...])
# Keyboard.press?(sym[, sym, ...])
# Keyboard.repeat?(sym[, sym, ...])
# Keyboard.release?(sym[, sym, ...])
#
# If you put more than 1 symbol or key id, you will get true if any of the
# keys choosed are selected.
# Examples of key symbols are:
# :CTRL (Control key), :LEFT_SHIFT (Left Shift), :ARROW_UP ( arrow up)
# :FN (with N from 1 to 12) to function keys
# You can check the ASCII_SYM table to view all the other Symbols.
# You can also use the number key eg: 65, means "A key". Check an ASCII table
# if you wish to know more about.
#
# You can check insthead of any of the pressed keys, all of the pressed keys.
#
# Keyboard.all_trigger?(sym[, sym, ...])
# Keyboard.all_press?(sym[, sym, ...])
# Keyboard.all_repeat?(sym[, sym, ...])
# Keyboard.all_release?(sym[, sym, ...])
#
# 1.2 How each method works:
#
# trigger is activated on the first frame the key was pressed, and not again
# until you release the key.
#
# press will give true each time the key is pressed, even on consecutive frames.
#
# repeat is a special case, it will check between frames, alternating between
# true and false if the key is pressed. its more convenient to use it if you want
# a slower version of 'press'
#
# Finally release, will be set to true, when you release the key. but only the
# first frame.
#
# 1.3 Keyboard's input character:
#
# You can get the keyboard's input character using the next function:
#
# Keyboard.character
#
# This system supports custom Keyboard layauts with api calls, you yes,
# you'll never have to configure each Keyboard version or use the "Only English"
# keyboard.
#
# 2.1 About the mouse.
#
# The Mouse has great influence on modern pcs, or at least when touchscreens
# were expensive and were hard to manufacture.
#
# It doesn't matter anyway, because touchscreens still acts like a Mouse
# sometimes.
#
# 2.2 Mouse position
#
# If you use a Mouse, you can use this next functions:
#
# Mouse.screen_x
# Mouse.screen_y
# Mouse.x
# Mouse.y
#
# if you want to know the real position (in the OS) use screen_x and screen_y
# functions.
#
# to get the relative positions (the position in the game) of the Mouse, use x,
# and y.
#
# 2.3 Mouse keys
#
# You have this same functions from the Keyboard, with some differences:
#
# Mouse.trigger?([sym])
# Mouse.press?([sym])
# Mouse.repeat?([sym])
# Mouse.release?([sym])
#
# sym has to be: :PRIMARY, :SECONDARY, :MIDDLE, :MOUSE4 or :MOUSE5
#
# Each one refered to a key of the mouse, it supports left handed mouses,
# primary, means the principal key, not the left key, and the same for the
# secondary.
#
# if you don't use ANY of the symbols, it will be :PRIMARY by default.
#
# 2.4 Getting areas of mouse:
#
# you can check if the mouse is inside a rect with the next commands:
#
# Mouse.in_area?(x, y, width, height)
# Mouse.in_area?(rect)
#
# both returns true if the mouse is INSIDE the rect and false if the mouse is
# OUTSIDE.
#
# 3.1 About Gamepad
#
# Gamepad works quite different like all the other Inputs, well not really.
# to use it just call this:
#
# Gamepad[index].method(args)
#
# Where index is a number from 1 to the supported numbers of gamepad by
# the system.
#
# On windows 2k it can only support 2 Gamepads
# On windows XP and newer it can support up to 16 Gamepads at least
#
# You can always get the max number of joypads by using the function:
#
# Gamepad.pugged_joypads
#
# 3.2 Getting Gamepad input
#
# The functions are te same of the Keyboard:
#
# Gamepad[id].trigger?(sym[, sym, ...])
# Gamepad[id].press?(sym[, sym, ...])
# Gamepad[id].repeat?(sym[, sym, ...])
# Gamepad[id].release?(sym[, sym, ...])
#
# Gamepad[id].all_trigger?(sym[, sym, ...])
# Gamepad[id].all_press?(sym[, sym, ...])
# Gamepad[id].all_repeat?(sym[, sym, ...])
# Gamepad[id].all_release?(sym[, sym, ...])
#
# The difference here is about the symbols, you can only use symbols and has to
# be one of the next:
# :UP, :DOWN, :LEFT, :RIGHT, :JOY1, :JOY2, :JOY3, :JOY4, :JOY5, :JOY6, :JOY7,
# :JOY8, :JOY9, :JOY10, :JOY11, :JOY12
#
# If you like a more RM Style Gamepad, you can still use the original syms:
#
# :A, :B, :C, :X, :Y, :Z, :L, :R
#
# The are refering from JOY1, to JOY8
#
# if you wisth to know the X axis, the Y axis or the Z axis of an analog stick
# (if supported by your gamepad/s, of course) you can use this functions:
#
# Gamepad[id].x
# Gamepad[id].y
# Gamepad[id].z
#
# They work giving a number from - 32511 to 32511.
#
# Have fun scripting some strange things.
#
#===============================================================================
module Api
#Keyboard Apis
GetKeyboardState = Win32API.new('user32','GetKeyboardState', 'P', 'I')
GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout','L', 'L')
MapVirtualKeyEx = Win32API.new('user32', 'MapVirtualKeyEx', 'IIL', 'I')
ToUnicodeEx = Win32API.new('user32', 'ToUnicodeEx', 'LLPPILL', 'L')
GetKeyState = Win32API.new("user32","GetKeyState",'I','I')
ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
GetPrivateProfileStringA = Win32API.new('kernel32', 'GetPrivateProfileStringA','pppplp', 'l')
FindWindowA = Win32API.new('user32', 'FindWindowA', 'pp', 'l')
#Mouse Apis
SwapMouseButton = Win32API.new('user32', 'SwapMouseButton', 'L', 'L')
GetDoubleClickTime = Win32API.new('user32', 'GetDoubleClickTime', '', 'L')
GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'v')
SetCursorPos = Win32API.new('user32', 'SetCursorPos', 'ii', 'I')
GetWindowRect = Win32API.new('user32', 'GetWindowRect', 'lp', 'v')
FindWindowEx = Win32API.new('user32', 'FindWindowEx', 'llpp', 'i')
ShowCursor = Win32API.new("user32", "ShowCursor", "i", "i")
#Gamepad Apis
JoyGetNumDevs = Win32API.new("winmm","joyGetNumDevs", 'v', "i")
JoyGetPos = Win32API.new("winmm","joyGetPos", 'lp', "l")
# Get the RGSS window
game_name = "\0" * 256
GetPrivateProfileStringA.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
game_name.delete!("\0")
h = FindWindowA.call('RGSS Player', game_name)
if h
RGSS_WINDOW = h
else
RGSS_WINDOW = FindWindowA.call('RGSS Player', nil)
end
end
module Keyboard
KEY_SIZE = 256
DOWN_STATE_MASK = 0x80
DEAD_KEY_MASK = 0x80000000
@state = "\0" * 256
@triggered = Array.new(KEY_SIZE, false)
@pressed = Array.new(KEY_SIZE, false)
@released = Array.new(KEY_SIZE, false)
@repeated = Array.new(KEY_SIZE, false)
@frame_keys = []
@caracter = []
#
# * Keys Names
#
KEYS_NAMES = {1=>'Mouse Primary',2=>'Mouse Secondary',3=>'Cancel',
4=>'Mouse Middle',5=>'Mouse 4th',6=>'Mouse 5th',8=>'Backspace',9=>'Tab',
12=>'Clear',13=>'Enter',16=>'Shift',17=>'Control',18=>'Alt',19=>'Pause',
20=>'Capitals Lock',21=>'Kana',23=>'Junja',24=>'Final',25=>'Kanji',
27=>'Escape',28=>'Convert',29=>'Non Convert',30=>'Accept',31=>'Mode Change',
32=>'Space',33=>'Page Up',34=>'Page Down',35=>'End',36=>'Home',37=>'Left',
38=>'Up',39=>'Right',40=>'Down',41=>'Select',42=>'Print',43=>'Execute',
44=>'Snapshot',45=>'Insert',46=>'Delete',47=>'Help',48=>'0',49=>'1',50=>'2',
51=>'3',52=>'4',53=>'5',54=>'6',55=>'7',56=>'8',57=>'9',65=>'A',66=>'B',
67=>'C',68=>'D',69=>'E',70=>'F',71=>'G',72=>'H',73=>'I',74=>'J',75=>'K',
76=>'L',77=>'M',78=>'N',79=>'O',80=>'P',81=>'Q',82=>'R',83=>'S',84=>'T',
85=>'U',86=>'V',87=>'W',88=>'X',89=>'Y',90=>'Z',91=>'Left Windows',
92=>'Right Windows',93=>'Application',95=>'Sleep',96=>'PAD 0',97=>'PAD 1',
98=>'PAD 2',99=>'PAD 3',100=>'PAD 4',101=>'PAD 5',102=>'PAD 6',103=>'PAD 7',
104=>'PAD 8',105=>'PAD 9',106=>'*',107=>'+',108=>'Separator',109=>'-',110=>'.',
111=>'/',112=>'F1',113=>'F2',114=>'F3',115=>'F4',116=>'F5',117=>'F6',118=>'F7',
119=>'F8',120=>'F9',121=>'F10',122=>'F11',123=>'F12',124=>'F13',125=>'F14',
126=>'F15',127=>'F16',128=>'F17',129=>'F18',130=>'F19',131=>'F20',132=>'F21',
133=>'F22',134=>'F23',135=>'F24',144=>'Number Lock',145=>'Scroll Lock',
146=>'OEM 15',147=>'OEM 16',148=>'OEM 17',149=>'OEM 18',150=>'OEM 19',
160=>'Left Shift',161=>'Right Shift',162=>' Left Control',163=>'Right Control',
164=>' Left Alt',165=>'Right Alt',166=>'Browser Back',167=>'Browser Forward',
168=>'Browser Refresh',169=>'Browser Stop',170=>'Browser Search',
171=>'Browser Favorites',172=>'Browser Home',173=>'Volume Mute',
174=>'Volume Down',175=>'Volume Up',176=>'Media Next Track',
177=>'Media Previous Track',178=>'Media Stop',179=>'Media Play Pause',
180=>'Launch Mail',181=>'Launch Media Select',182=>'Launch Application',
183=>'Launch Application',186=>'OEM 1',187=>'OEM 2',188=>'OEM 3',189=>'OEM 4',
190=>'OEM 5',191=>'OEM 6',192=>'OEM 7',219=>'OEM 8',220=>'OEM 9',221=>'OEM 10',
222=>'OEM 11',223=>'OEM 13',225=>'OEM 20',226=>'OEM 14',227=>'OEM 21',
228=>'OEM 22',229=>'Proccess',230=>'OEM 23',232=>'OEM 24',240=>'OEM 25',
241=>'OEM 26',242=>'OEM 27',243=>'OEM 28',244=>'OEM 29',245=>'OEM 30',
246=>'ATTN',247=>'CRSEL',248=>'EXSEL',249=>'EREOF',250=>'Play',251=>'Zoom',
253=>'PA1',254=>'OEM Clear'}
# simle symbol-to-ascii-table
ASCII_SYM = { :A => 65, :B => 66, :C => 67, :D => 68, :E => 69, :F => 70,
:G => 71, :H => 72, :I => 73, :J => 74, :K => 75, :L => 76, :M => 77,
:N => 78, :O => 79, :P => 80, :Q => 81, :R => 82, :S => 83, :T => 84,
:U => 85, :V => 86, :W => 87, :X => 88, :Y => 89, :Z => 90,
:N1 => 48, :N2 => 49, :N3 => 50, :N4 => 51, :N5 => 52, :N6 => 53, :N7 => 54,
:N8 => 55, :N9 => 56, :N0 => 57,
:NUMPAD_0 => 45, :NUMPAD_1 => 35, :NUMPAD_2 => 40, :NUMPAD_3 => 34,
:NUMPAD_4 => 37, :NUMPAD_5 => 12, :NUMPAD_6 => 39, :NUMPAD_7 => 36,
:NUMPAD_8 => 38, :NUMPAD_9 => 33,
:F1 => 112, :F2 => 113, :F3 => 114, :F4 => 115, :F5 => 116, :F6 => 117,
:F7 => 118, :F8 => 118, :F9 => 120, :F10 => 121, :F11 => 122, :F12 => 123,
:BACKSPACE => 8, :TAB => 9, :ENTER => 13, :SHIFT => 16, :CTRL => 17,
:ALT => 18, :PRINT => 27, :SPACE => 32, :PAGE_UP => 33, :PAGE_DOWN => 34,
:K_END => 35, :LEFT_SHIFT => 160, :RIGHT_SHIFT => 161, :DELETE => 46,
:LEFT_CTRL => 162, :RIGHT_CTRL => 163, :HOME => 35, :INSERT => 45,
:UP => 38, :DOWN => 40, :LEFT => 37, :RIGHT => 39, :ESC => 27,
:ARROW_UP => 38, :ARROW_DOWN => 40, :ARROW_LEFT => 37, :ARROW_RIGHT => 39}
def self.trigger?(*keys)
keys.any? { |key| key.is_a?(Symbol) ? @triggered[ASCII_SYM[key]] : @triggered[key] }
end
def self.repeat?(*keys)
keys.any? { |key| key.is_a?(Symbol) ? @repeated[ASCII_SYM[key]] : @repeated[key] }
end
def self.press?(*keys)
keys.any? { |key| key.is_a?(Symbol) ? @pressed[ASCII_SYM[key]] : @pressed[key] }
end
def self.release?(*keys)
keys.any? { |key| key.is_a?(Symbol) ? @released[ASCII_SYM[key]] : @released[key] }
end
def self.all_trigger?(*keys)
keys.all? { |key| key.is_a?(Symbol) ? @triggered[ASCII_SYM[key]] : @triggered[key] }
end
def self.all_repeat?(*keys)
keys.all? { |key| key.is_a?(Symbol) ? @repeated[ASCII_SYM[key]] : @repeated[key] }
end
def self.all_press?(*keys)
keys.all? { |key| key.is_a?(Symbol) ? @pressed[ASCII_SYM[key]] : @pressed[key] }
end
def self.all_release?(*keys)
keys.all? { |key| key.is_a?(Symbol) ? @released[ASCII_SYM[key]] : @released[key] }
end
def self.character
@character
end
def self.update
@language_layout = Api::GetKeyboardLayout.call(0)
Api::GetKeyboardState.call(@state)
@frame_keys.clear
KEY_SIZE.times do |key|
if Api::GetKeyState.call(key) & DOWN_STATE_MASK == DOWN_STATE_MASK
@released[key] = false
if !@pressed[key]
@pressed[key] = true
@triggered[key] = true
@repeated[key] = false
else
@triggered[key] = false
end
@repeated[key] = !@repeated[key]
@frame_keys.push(key)
elsif !@released[key]
@triggered[key] = false
@pressed[key] = false
@repeated[key] = false
@released[key] = true
else
@released[key] = false
end
end
@character = make_character
end
def self.get_character(vk)
c = Api::MapVirtualKeyEx.call(vk, 2, @language_layout)
return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
vsc = Api::MapVirtualKeyEx.call(vk, 0, @language_layout)
result = "\0" * 2
length = Api::ToUnicodeEx.call(vk, vsc, @state, result, 2, 0, @language_layout)
length == 0 ? '' : result
end
def self.unicode_to_utf8(string)
result = ''
begin
string.unpack('S*').each do |c|
if c < 0x0080
result += c.chr
elsif c < 0x0800
result += (0xC0 | (c >> 6)).chr
result += (0x80 | (c & 0x3F)).chr
else
result += (0xE0 | (c >> 12)).chr
result += (0x80 | ((c >> 12) & 0x3F)).chr
result += (0x80 | (c & 0x3F)).chr
end
end
rescue
end
result
end
def self.make_character
result = ''
@frame_keys.each do |key|
c = get_character(key)
result += c if c != ''
end
result ? unicode_to_utf8(result) : ''
end
end
module Mouse
PRIMARY = 0
SECONDARY = 1
@double_click_time = 0
@swap = 0
@swap_values = {:PRIMARY => 1 + @swap, :SECONDARY => 2 - @swap}
@mouse_pos = "\0" * 8
@mouse_drag = [false, false]
@mouse_doubleclick = [false, false]
@visible = true
@x = 0
@y = 0
@screen_x = 0
@screen_y = 0
def self.screen_x
return @screen_x
end
def self.screen_y
return @screen_y
end
def self.x
return @x
end
def self.y
return @y
end
def self.pos
@mouse_pos.clone
end
def self.swapped?
(@swap == 1)
end
def self.press?(key=:PRIMARY)
Keyboard.press?(@swap_values[key])
end
def self.trigger?(key=:PRIMARY)
Keyboard.trigger?(@swap_values[key])
end
def self.repeat?(key=:PRIMARY)
Keyboard.repeat?(@swap_values[key])
end
def self.release?(key=:PRIMARY)
Keyboard.release?(@swap_values[key])
end
def self.click?(key=:PRIMARY)
Keyboard.trigger?(@swap_values[key])
end
def self.set_pos(x, y)
SetCursorPos.call(x, y)
@screen_x = x
@screen_y = y
p = [@x, @y].pack('LL')
Api::ScreenToClient.call(Api::RGSS_WINDOW, p)
@x, @y = p.unpack('ll')
end
def x=(value)
SetCursorPos.call(value, @y)
@screen_x = x
p = [@x, @y].pack('LL')
Api::ScreenToClient.call(Api::RGSS_WINDOW, p)
@x, @y = p.unpack('ll')
@x
end
def y=(value)
SetCursorPos.call(@x, value)
@screen_y = y
p = [@x, @y].pack('LL')
Api::ScreenToClient.call(Api::RGSS_WINDOW, p)
@x, @y = p.unpack('ll')
@y
end
def self.update
@double_click_time = Graphics.frame_rate * (Api::GetDoubleClickTime.call / 10) / 100
@swap = Api::SwapMouseButton.call(0)
@swap_values = {:PRIMARY => 1 + @swap, :SECONDARY => 2 - @swap, :MIDDLE => 4, :MOUSE4 => 5, :MOUSE5 => 6}
Api::GetCursorPos.call(@mouse_pos)
@screen_x, @screen_y = @mouse_pos.unpack('LL')
Api::ScreenToClient.call(Api::RGSS_WINDOW, @mouse_pos)
@x, @y = @mouse_pos.unpack('ll')
end
def self.in_area?(*args)
if args[0].is_a?(Rect)
p = @x >= args[0].x && @y >= args[0].y
q = @x <= args[0].x + args[0].width && @y <= args[0].y + args[0].height
else
p = @x >= args[0].x && @y >= args[1]
q = @x <= args[0] + args[2] && @y <= args[1].y + args[3]
end
return (p && q)
end
def self.visible
@visible
end
def self.visible=(value)
Api::ShowCursor.call(value ? 0 : 0)
@visible = value
end
def self.show
self.visible=true
end
def self.hide
self.visible=false
end
end
module Gamepad
AXIS = 32511
KEYS = [:UP, :DOWN, :LEFT, :RIGHT,
:JOY1, :JOY2,:JOY3, :JOY4, :JOY5, :JOY6, :JOY7, :JOY8, :JOY9, :JOY10,
:JOY11,:JOY12]
class GamepadData
def initialize(number)
@info = "\x00" * 16
@number = number
@data = {}
@pressed = {}
@triggered = {}
@released = {}
@repeated = {}
end
def update
Api::JoyGetPos.call(@number, @info)
@x, @y, @z, @buttons = @info.unpack('I4')
triggers = {:UP => (y < 0), :DOWN => (y > 0), :LEFT => (x < 0),
:RIGHT => (x > 0),
:JOY1 => (0x1 & @buttons == 0x1),
:JOY2 => (0x2 & @buttons == 0x2),
:JOY3 => (0x4 & @buttons == 0x4),
:JOY4 => (0x8 & @buttons == 0x8),
:JOY5 => (0x10 & @buttons == 0x10),
:JOY6 => (0x20 & @buttons == 0x20),
:JOY7 => (0x40 & @buttons == 0x40),
:JOY8 => (0x80 & @buttons == 0x80),
:JOY9 => (0x100 & @buttons == 0x100),
:JOY10 => (0x200 & @buttons == 0x200),
:JOY11 => (0x400 & @buttons == 0x400),
:JOY12 => (0x800 & @buttons == 0x800)}
triggers.each_key do |key|
if triggers[key]
@released[key] = false
if !@triggered[key]
@pressed[key] = true
@triggered[key] = true
@repeated[key] = false
else
@triggered[key] = false
end
@repeated[key] = !@repeated[key]
elsif !@released[key]
@triggered[key] = false
@pressed[key] = false
@repeated[key] = false
@released[key] = true
else
@released[key] = false
end
end
@pressed[:A] = @pressed[:JOY1]
@released[:A] = @released[:JOY1]
@triggered[:A] = @triggered[:JOY1]
@repeated[:A] = @repeated[:JOY1]
@pressed[:B] = @pressed[:JOY2]
@released[:B] = @released[:JOY2]
@triggered[:B] = @triggered[:JOY2]
@repeated[:B] = @repeated[:JOY2]
@pressed[:C] = @pressed[:JOY3]
@released[:C] = @released[:JOY3]
@triggered[:C] = @triggered[:JOY3]
@repeated[:C] = @repeated[:JOY3]
@pressed[:X] = @pressed[:JOY4]
@released[:X] = @released[:JOY4]
@triggered[:X] = @triggered[:JOY4]
@repeated[:X] = @repeated[:JOY4]
@pressed[:Y] = @pressed[:JOY5]
@released[:Y] = @released[:JOY5]
@triggered[:Y] = @triggered[:JOY5]
@repeated[:Y] = @repeated[:JOY5]
@pressed[:Z] = @pressed[:JOY6]
@released[:Z] = @released[:JOY6]
@triggered[:Z] = @triggered[:JOY6]
@repeated[:Z] = @repeated[:JOY6]
@pressed[:L] = @pressed[:JOY7]
@released[:L] = @released[:JOY7]
@triggered[:L] = @triggered[:JOY7]
@repeated[:L] = @repeated[:JOY7]
@pressed[:R] = @pressed[:JOY8]
@released[:R] = @released[:JOY8]
@triggered[:R] = @triggered[:JOY8]
@repeated[:R] = @repeated[:JOY8]
end
def press?(*args)
args.any? {|sym| @pressed[sym]}
end
def trigger?(*args)
args.any? {|sym| @triggered[sym]}
end
def release?(*args)
args.any? {|sym| @released[sym]}
end
def repeat?(*args)
args.any? {|sym| @repeated[sym]}
end
def all_press?(*args)
args.any? {|sym| @pressed[sym]}
end
def all_trigger?(*args)
args.any? {|sym| @triggered[sym]}
end
def all_release?(*args)
args.any? {|sym| @released[sym]}
end
def all_repeat?(*args)
args.any? {|sym| @repeated[sym]}
end
def x
return @x - AXIS
end
def y
return @y - AXIS
end
def z
return @z - AXIS
end
end
@pads = []
@plugged_joypads = 0
def self.[](number)
id = number - 1
@pads[id] = GamepadData.new(number) if !@pads[id]
@pads[id]
end
def self.update
@plugged_joypads = Api::JoyGetNumDevs.call
@plugged_joypads.times do |i|
@pads = GamepadData.new(i) if !@pads
end
@pads.each do |pad|
pad.update if pad
end
end
def self.pugged_joypads
return @plugged_joypads
end
end
module Input
class << self
alias ramiro_input_mod_update update
def update
Keyboard.update
Mouse.update
Gamepad.update
ramiro_input_mod_update
end
def [](index)
@pads = {} if !@pads
return pads[index]
end
def get_first_input_type
for i in 6...256
return [:keyboard, i] if Keyboard.trigger?(i)
end
for i in 1..16
Gamepad::KEYS.each do |key|
return [:gamepad, [i, key]] if Gamepad.trigger?(key)
end
end
return nil
end
def get_name(item)
case item[0]
when :keyobard
return "KEY #{get_key_name(item[1])}"
when :gamepad
return "PAD#{item[1][0]} #{get_joykey_name(item[1][1])}"
end
end
def get_key_name(number)
KEYS_NAMES[number]
end
def get_joykey_name(sym)
case sym
when :UP
return 'UP'
when :DOWN
return 'DOWN'
when :LEFT
return 'LEFT'
when :RIGHT
return 'RIGHT'
when :JOY1
return '1'
when :JOY2
return '2'
when :JOY3
return '3'
when :JOY4
return '4'
when :JOY5
return '5'
when :JOY6
return '6'
when :JOY7
return '7'
when :JOY8
return '8'
when :JOY9
return '9'
when :JOY10
return '10'
when :JOY11
return '11'
when :JOY12
return '12'
end
return '???'
end
end
end[/php]
Toàn tự đặt câu hỏi rồi tự tìm câu trả lời...
Một cảm giác tự kỉ ko hề nhẹ...
THAM GIA GROUP CỦA TTC TRÊN FACEBOOK
Thực ra thì đúng thế thật
___
Mở menu skill lên thì :
SceneManager.call(Scene_Skill)
Sẽ mở lên menu skill của thằng leader trong party.
Nhưng mở menu skill của thằng khác trong party thì làm thế nào vậy ?
Đưa ra hướng gợi ý đi Death ơi...