Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=============================================================================
- # *** Aleworks Input Module(AIM)
- #=============================================================================
- # Created by Aleworks
- # Version: 2.02
- # Last Modification: 13/09/2007 (day/month/year)
- #=============================================================================
- #==== Description ====
- # This script simulates the RGSS module "Input". It is not the original module,
- # but it has all the original module functions and some new.
- #=============================================================================
- #==== Requeriments ====
- # * Aleworks Library
- # - Version: 1.01 or superior
- #=============================================================================
- #==== Version History ====
- # * Version 1.00
- # - New methods: Input.reiterate?; Input.activated?; Input.press_all;
- # Input.trigger_all; Input.repeat_all; Input.reiterate_all
- # - New Keys: LOWER_LEFT; LOWER_RIGHT; UPPER_LEFT; UPPER_RIGHT
- # * Version 1.10
- # - New methods: Input.event; Input.free_key; Input.free_all_keys
- # * Version 1.11
- # - Changed the variables: @repeat_time, @reiterate_time, @reiterate and
- # @update_keys to global variables for easy editing.
- # * Version 1.12(Now in Aleworks Input Module Compability Patch 1)
- # - Compability with the event commands: Asing Key and Condition Branch
- # * Version 1.20
- # - Little lag reduction
- # - New methods: Input.release?; Input.release_all
- # * Version 1.21
- # - Major bug fixed, when using arrays in Input.press?, Input.trigger?,
- # Input.reiterate? and Input.release?
- # - Removed $update_keys and $reiterate
- # * Version 2.00
- # - Little lag reduction
- # - Rewrited some code
- # - No more need of Win32::Registry, but need Aleworks Library
- # - Key Combos
- # - New Class: Input::Key_Combo
- # - New Methods: Input.add_combo; Input.combo; Input.combos; Input.combos;
- # Input.delete_combo; Input.delete_ended_combos
- # - Mouse Input
- # - New Methods: Input.mouse_double_click?; Input.mouse_x?; Input.mouse_y?;
- # Input.mouse_dragging?; Input.mouse_drag_rect?; Input.mouse_drag_coor?
- # - New Constants: MOUSE_INPUT; MOUSE_DOUBLE_CLICK_TIME;
- # MOUSE_DOUBLE_CLICK_PIX; MOUSE_DRAG_PIX; MOUSE_PRIMARY; MOUSE_SECONDARY
- # * Version 2.01
- # - Input.mouse_x? and Input.mouse_y? will now return nil if the mouse poiter
- # is out of the game screen.
- # * Version 2.02
- # - Fixed error in Input.press?
- #=============================================================================
- #==== Indications ====
- # * Constants
- # - REPEAT_TIME
- # Frames for repeat in Input.repeat?. By default 7.
- # - REITERATE_TIME
- # Frames for reiterate in Input.reiterate?. By default 20.
- # - MOUSE_INPUT
- # Flag for mouse input updating. By default true.
- # - MOUSE_DOUBLE_CLICK_TIME = nil
- # The mouse double click time, if nil, will be used the windows default time.
- # - MOUSE_DOUBLE_CLICK_PIX = 4
- # Max pixels count the mouse can move around the first click point for double
- # clicking. By default 4.
- # - MOUSE_DRAG_PIX
- # Pixels needed for the cursor to move around the first point to start
- # dragging. By default 4.
- # - REG_KVALUES
- # Contains values for reading the A, B, C, X, Y, Z, L and R keys from windows
- # registry.
- # - DOWN; LEFT; RIGHT; UP; LOWER_LEFT; LOWER_RIGHT; UPPER_LEFT; UPPER_RIGHT
- # Numbers corresponding to the directions.
- # - A; B; C; X; Y; Z; L; R
- # Numbers corresponding to the various controller buttons.
- # - SHIFT; CTRL; ALT
- # Numbers directly corresponding to the keyboard's SHIFT, CTRL, and ALT keys.
- # - F5; F6; F7; F8; F9
- # Numbers corresponding to the keyboard's function keys.
- # - MOUSE_PRIMARY
- # Number corresponding to the mouse's primary button.
- # - MOUSE_SECONDARY
- # Number corresponding to the mouse's secondary button.
- # * Methods
- # - Input.update
- # Updates input data. This method need to be called once per frame.
- # - Input.press?(vk)
- # Determines whether the key vk is currently being pressed. If the key is
- # being pressed, returns true. If not, returns false.
- # - Input.press_all([state])
- # Returns all keys that have its press value same as state. If state is not
- # given, it will be true.
- # - Input.trigger?(vk)
- # Determines whether the key vk is being pressed again. "Pressed again" is
- # seen as time having passed between the button being not pressed and being
- # pressed. If the button is being pressed, returns true. If not, returns
- # false.
- # - Input.trigger_all([state])
- # Returns all keys that have its trigger value same as state. If state is not
- # given, it will be true.
- # - Input.repeat?(vk)
- # Determines whether the key vk is being pressed and some time has passed
- # again. "Being pressed and some time has passed again" is seen as time
- # having passed again after the button was being pressed. If the button is
- # being pressed and some time has passed again, returns true. If not, returns
- # false. The time being passed again, is determined by the REPEAT_TIME
- # constant.
- # - Input.repeat_all([state])
- # Returns all keys that have its repeat value same as state. If state is not
- # given, it will be true.
- # - Input.reiterate?(num)
- # Determines whether the key vk is being pressed again in the given frames.
- # "Being pressed again in the given frames" is seen as time having passed
- # between the button is pressed and being again pressed. If the button is
- # being pressed again in the given frames, returns true. If not, returns
- # false. The given frames is determined by REITERATE_TIME constant.
- # - Input.reiterate_all([state])
- # Returns all keys that have its reiterate value same as state. If state is
- # not given, it will be true.
- # - Input.release?(vk)
- # Determines whether the key vk is being not pressed. "Not pressed" is seen
- # as time having passed between the button is pressed and being not pressed.
- # If the button is being not pressed, returns true. If not, returns false.
- # - Input.release_all([state])
- # Returns all keys that have its release value same as state. If state is not
- # given, it will be true.
- # - Input.dir4
- # Checks the status of the directional buttons, translates the data into a
- # specialized 4-direction input format, and returns the number pad equivalent
- # (2, 4, 6, 8). If no directional buttons are being pressed (or the
- # equivalent), returns 0.
- # - Input.dir8
- # Checks the status of the directional buttons, translates the data into a
- # specialized 8-direction input format, and returns the number pad equivalent
- # (1, 2, 3, 4, 6, 7, 8, 9). If no directional buttons are being pressed (or
- # the equivalent), returns 0.
- # - Input.activated?(vk)
- # Returns true if the key vk is activated. Applicable for mode keys, like
- # num, caps or scroll lock.
- # - Input.key_click(vk)
- # Makes key vk to be pressed, and instantaly after released.
- # - Input.key_release(vk)
- # Makes key vk to be released.
- # - Input.key_press(vk)
- # Makes key vk to be pressed.
- # - Input.mouse_double_click?
- # Return true, if the primary button of the mouse has been twice clicked,
- # false instad.
- # - Input.mouse_x?
- # Returns X pixel coordinates of the mouse pointer. If the cursor is out of
- # the game screen, returns nil.
- # - Input.mouse_y?
- # Returns Y pixel coordinates of the mouse pointer. If the cursor is out of
- # the game screen, returns nil.
- # - Input.mouse_dragging?
- # Returns true if the user is dragging with mouse, false instad.
- # - Input.mouse_drag_rect?
- # Returns a Rect with the dragged rectangle coordinates and size, if no
- # dragging is being maked returns nil.
- # - Input.mouse_drag_coor?
- # Returns an Array with the dragged coordinates, the firts two values are the
- # x and y coordinates of the initial point of draging, the last 2 values are
- # the x and y coordinates of the actual point, if no dragging is being maked
- # returns nil.
- # - Input.add_combo(params, restart_count, res_type[, update[, id]])
- # Add a Key Combo with the given params, restart count, restart
- # type(res_type) and update; with the given id as identifier. If the id is
- # not given it will be auto-selected and returned by this function. If
- # update is not given it will be not given to the Key Combo. See Key Combo
- # for more reference.
- # - Input.combos
- # Returns a hash with all combos, with the keys as theirs identifiers.
- # - Input.combos=(new)
- # Overwrites combos list with new.
- # - Input.delete_combo(id)
- # Deletes the combo that have the given id.
- # - Input.delete_ended_combos(ending = nil)
- # Deletes all ended combos that have the end value equal to "ending". If
- # "ending" is nil both true ended and false ended will be deleted.
- #=============================================================================
- #==== Key Combo ====
- # * Methods
- # - update
- # Updates the timers and the keys combination. Input.update, autoupdate
- # all the combos created in Input.
- # - true?
- # Returns the ending value of the combo. Nil if the combo has not ended.
- # - end?
- # Returns true if the combo has ended, false instead.
- # - frozen?
- # Returns true if the combo is frozen, false instead.
- # - restarts_count?
- # Returns the total restart count that the combo has maked.
- # - start_frame?
- # Returns the the frame, based on Graphics.frame_count, which is assigned
- # when the combo is created or restarted.
- # - end_frame?
- # Returns the the frame, based on Graphics.frame_count, which is assigned
- # when the combo is ended.
- # - freeze
- # Freezes the combo. Frozen combos will be not updated.
- # - unfreeze
- # Unfreezes the combo.
- # - restart
- # Restarts all the combo, like when it had been created.
- # * Accessible Variables
- # - params
- # See params in Input Values.
- # - restart_count
- # See restart count in Input Values.
- # - restart_type
- # See restart type count in Input Values.
- # - update
- # See update count in Input Values.
- # * Input Values
- # - params
- # This is an Array containing all the checks, the time they have to be
- # checked, and the wait time between each check.
- # A check is a comprobation for if its keys combination is true. When a
- # check is false, the combo will restart depending of the restart count and
- # the restart type.
- # - Numerical values in the main array, are frames to wait before or
- # between the checks. They don't need to be between each check, and can
- # be more than one consecutively. They are countdown timers, and will
- # continue with the next main array value when they reaches 0.
- # - Array values, are the checks.
- # [A, B[, C[, D]]]
- # - A, the first value, is a countdown timer for the keys combination to
- # be checked. When it reaches 0 the check will be false. If it is an
- # Integer, the timer will be reduced, only if the key combination(B) is
- # false. If it is a String convertible to an integer, the timer will be
- # reduced ever.
- # - B, the second value is an array containing the keys combination to
- # be checked(For more info see "Array Input")
- # - C, the third value is a countdown timer, that when it is reaches 0
- # after the first check to key combination(B) results true, the check
- # will be true. If it is an Integer or a String convertible to an
- # integer, C is the exact time needed for the keys combination to be
- # true. If it is a Range, or a Range writed like a String, or an Array
- # containing Integers or Strings convertible to integers, the first
- # value will be the minimum time that the keys combination need to be
- # true; and the second value, will be the limit, so, when the pressed
- # time is more than the limit, this check will be true. When the value/
- # values is/are not strings, if the key combination stop being true
- # after its first press, the check will be false, but if the values are
- # strings the check will be only false when A finish. When C is not
- # given, it will be 0.
- # - D, the last value is the times the check need to be true, for
- # continuing with the combo. If D is -1, the check will be restarted
- # infinitely. If D is not given it will be 0.
- # - restart count
- # -1 => infinite times
- # 0 => 1 time
- # >0 => times + 1
- # - restart type
- # 0 => start to check all the combo again when restarted
- # 1 => start to check from the last no true check when restarted
- # - update
- # Array => The Key Combo will only be updated when the actual Scene(stored
- # in $scene) is included in the Array.
- # Hash => The Key Combo will be updated when the actual Scene(stored in
- # $scene) is not included in the keys of the Hash, or if it is
- # included and the evaluation of its value returns true.
- #=============================================================================
- #==== Array Input ====
- # This feature allows you to use Arrays for some special virtual keys checking
- # in the commands Input.press?, Input.trigger?, Input.reiterate?, Input.release?,
- # Input.key_click, Input.key_release, Input.key_press and for the params value
- # in the Key Combos.
- # * Syntax
- # This Array, can have numerical values and other Arrays, as values. The
- # subarrays can have numerical values. The numerical values are the virtual
- # keys to be checked.
- # - Examples:
- # - [Keys::A, Keys::B, [Keys::C, Keys::D]]
- # - [65, 66, [67, 68]]
- # * Return Value
- # The return value will be true when at least one of virtual keys in the array
- # are true for the corresponding method.
- # The Sub-Arrays will have true value, when all of its values are true for the
- # corresponding method.
- # - Examples:
- # - Input.press?( [Keys::A] )
- # Will return true if the key A is pressed.
- # - Input.press?( [Keys::A, Keys::B, Keys::C] )
- # Will return true if one or more of the A, B and C keys are pressed.
- # - Input.press?( [ [Keys::A, Keys::B] ] )
- # Will return true if both A and B keys are pressed.
- # - Input.press?( [ [Keys::A, Keys::B, Keys::C] ] )
- # Will return true if the A, B and C keys are pressed.
- # - Input.press?( [ [Keys::A, Keys::B, Keys::C], Keys::D] )
- # Will return true if the A, B and C keys are pressed or
- # the key D is pressed.
- # - Input.press?( [ [Keys::A, Keys::B, Keys::C], [Keys::D, Keys::E]] )
- # Will return true if the A, B and C keys are pressed or
- # the keys D and E are pressed.
- #=============================================================================
- #=============================================================================
- # ** Module Input
- #=============================================================================
- module Input
- #---------------------------------------------------------------------------
- # * Expand Input module with Aleworks Library
- #---------------------------------------------------------------------------
- include Aleworks
- #---------------------------------------------------------------------------
- # * Options
- #---------------------------------------------------------------------------
- START_REPEAT_TIME = 10
- REPEAT_TIME = 2
- REITERATE_TIME = 20
- MOUSE_INPUT = true
- MOUSE_DOUBLE_CLICK_TIME = nil
- MOUSE_DOUBLE_CLICK_PIX = 4
- MOUSE_DRAG_PIX = 4
- #---------------------------------------------------------------------------
- # * Internal variables definition
- #---------------------------------------------------------------------------
- @trigger, @trigger2, @repeat, @repeat2, @repeat3, @reiterate, @reiterate2,
- @reiterate3, @release, @release2 = ([[]] * 10).clone_all
- 256.times do |i|
- @trigger.push(false)
- @trigger2.push(false)
- @repeat.push(false)
- @repeat2.push(0)
- @reiterate.push(false)
- @reiterate2.push(0)
- @reiterate3.push(API::GetKeyState.call(i) & 1)
- @release.push(false)
- @release2.push(false)
- end
- @combos = {}
- @mouse_pos = nil
- @mouse_swap_buttons = Aleworks.get_mouse_swap_buttons_flag
- @mouse_primary_dc = [0, 0, [nil, nil]]
- @mouse_rectdrag = nil
- @mouse_draw = []
- if MOUSE_DOUBLE_CLICK_TIME.nil?
- MOUSE_DOUBLE_CLICK_TIME = Graphics.frame_rate
- MOUSE_DOUBLE_CLICK_TIME *= (API::GetDoubleClickTime.call / 10)
- MOUSE_DOUBLE_CLICK_TIME /= 100
- end
- #---------------------------------------------------------------------------
- # * convert_keys (internal method)
- #---------------------------------------------------------------------------
- # It reads the windows registry and returns the corresponding keys to the
- # F1 keys menu.
- #---------------------------------------------------------------------------
- REG_KVALUES = {0=>32,1=>13,2=>27,3=>96,4=>16,5=>90,6=>88,7=>67,8=>86,9=>66,
- 10=>65,11=>83,12=>68,13=>81,14=>87}
- def convert_keys(key)
- keys = []
- reg_key = 'HKEY_CURRENT_USER\\Software\\Enterbrain\\RGSS'
- data = Registry.read_entry(reg_key, 'ButtonAssign')[10, 25].scan(/./)
- 15.times {|i| keys.push(REG_KVALUES[i]) if key == data[i].unpack('C')[0]}
- keys
- end
- module_function :convert_keys
- #---------------------------------------------------------------------------
- # * Keys Constants definitions
- #---------------------------------------------------------------------------
- LOWER_LEFT = 97
- LOWER_RIGHT = 99
- UPPER_LEFT = 103
- UPPER_RIGHT = 105
- DOWN = [98, 40]
- LEFT = [100, 37]
- RIGHT = [102, 39]
- UP = [104, 38]
- A = convert_keys(11)
- B = convert_keys(12).concat([45])
- C = convert_keys(13)
- X = convert_keys(14)
- Y = convert_keys(15)
- Z = convert_keys(16)
- L = convert_keys(17).concat([33])
- R = convert_keys(18).concat([34])
- SHIFT = 16
- CTRL = 17
- ALT = 18
- F5 = 116
- F6 = 117
- F7 = 118
- F8 = 119
- F9 = 120
- MOUSE_PRIMARY = 1 + @mouse_swap_buttons
- MOUSE_SECONDARY = 2 - @mouse_swap_buttons
- #===========================================================================
- # ** Class Key_Combo
- #===========================================================================
- class Key_Combo
- attr_accessor(:params, :restart_count, :restart_type, :update)
- #-------------------------------------------------------------------------
- # * Initialize
- #-------------------------------------------------------------------------
- def initialize(params, restart_count, restart_type, update)
- params.each_index do |i|
- if params[i].is_a?(Array)
- params[i][2] = [0, 0] if params[i].size == 2
- params[i][3] = 0 if params[i].size == 3
- params[i][1] = params[i][1].to_a
- if params[i][2].is_a?(Numeric)
- params[i][2] = [params[i][2], 0]
- elsif params[i][2].is_a?(Range)
- if params[i][2].exclude_end?
- params[i][2] = [params[i][2].first, params[i][2].last - 1]
- else
- params[i][2] = [params[i][2].first, params[i][2].last]
- end
- elsif params[i][2].is_a?(String)
- if !params[i][2][/(.*)\.\.\.(.*)/].nil?
- params[i][2] = [$1, ($2.to_i - 1).to_s]
- elsif !params[i][2][/(.*)\.\.(.*)/].nil?
- params[i][2] = [$1, $2]
- else
- params[i][2] = [params[i][2], 0]
- end
- elsif params[i][2].is_a?(Array)
- if params[i][2][0].is_a?(String)
- params[i][2][1] = params[i][2][1].to_s
- end
- if params[i][2][1].is_a?(String)
- params[i][2][0] = params[i][2][0].to_s
- end
- end
- end
- end
- if @update.is_a?(Array)
- @update.each_index do |i|
- @update[i] = @update[i].type.to_s
- end
- elsif @update.is_a?(Hash)
- @update = !@update
- @update.each do |k, v|
- @update[k] = @update[k].type.to_s
- end
- @update = !@update
- end
- @params = params
- @state = @params.clone_all
- @restart_count = restart_count
- @_restart_count = restart_count
- @restart_type = restart_type
- @update = update
- @last_state = @state.clone_all if @restart_type == 1
- @frame_start = Graphics.frame_count
- @frame_end = nil
- @_true = nil
- @_end = false
- @start_check = false
- @end_check = false
- @restarts = 0
- @frozen = false
- end
- #-------------------------------------------------------------------------
- # * Update
- #-------------------------------------------------------------------------
- def update
- return if @frozen or @_end or @params.size == 0
- if @update.is_a?(Array)
- return if !@update.include?($scene.type.to_s)
- elsif @update.is_a?(Hash)
- if @update.has_key?($scene.type.to_s)
- return if eval(@update[$scene.type.to_s].to_s)
- end
- end
- if @state[0].is_a?(Numeric)
- @state[0] -= 1
- check_true if @state[0] <= 0
- elsif @state[0].is_a?(Array)
- if Input.press?(@state[0][1])
- input_checked = true
- if @state[0][2][0].is_a?(Numeric)
- @start_check = true
- @state[0][2][0] -= 1 unless @state[0][2][0] <= 0
- @state[0][2][1] -= 1 unless @state[0][2][1] <= 0
- if @state[0][2][0] <= 0 and @state[0][2][1] <= 0
- check_true
- return
- end
- elsif @state[0][2][0].is_a?(String)
- unless @state[0][2][0].to_i <= 0
- @state[0][2][0] = (@state[0][2][0].to_i - 1).to_s
- end
- unless @state[0][2][1].to_i <= 0
- @state[0][2][1] = (@state[0][2][1].to_i - 1).to_s
- end
- if @state[0][2][0].to_i <= 0 and @state[0][2][1].to_i <= 0
- check_true
- return
- end
- end
- if @state[0][0].is_a?(String)
- if @state[0][0].to_i >= 0
- @state[0][0] = (@state[0][0].to_i - 1).to_s
- is_false if @state[0][0].to_i == 0
- end
- end
- else
- if @state[0][2][0].to_i <= 0
- check_true
- return
- elsif @start_check
- is_false
- return
- end
- if @state[0][0].is_a?(String)
- if @state[0][0].to_i >= 0
- @state[0][0] = (@state[0][0].to_i - 1).to_s
- is_false if @state[0][0].to_i == 0
- end
- elsif @state[0][0].is_a?(Numeric)
- if @state[0][0] >= 0
- @state[0][0] -= 1 unless @state[0][0] <= 0
- is_false if @state[0][0] == 0
- end
- end
- end
- end
- end
- #-------------------------------------------------------------------------
- def true?
- @_true
- end
- #-------------------------------------------------------------------------
- def end?
- @_end
- end
- #-------------------------------------------------------------------------
- def frozen?
- @frozen
- end
- #-------------------------------------------------------------------------
- def restarts_count?
- @restarts
- end
- #-------------------------------------------------------------------------
- def start_frame?
- @frame_start
- end
- #-------------------------------------------------------------------------
- def end_frame?
- @frame_end
- end
- #-------------------------------------------------------------------------
- def freeze
- @frozen = true
- end
- #-------------------------------------------------------------------------
- def unfreeze
- @frozen = false
- end
- #-------------------------------------------------------------------------
- def restart
- @state = @params.clone_all
- @last_state = @state.clone_all if @restart_type == 1
- @restart_count = @_restart
- @frame_start = Graphics.frame_count
- @frame_end = nil
- @_true = nil
- @_end = false
- @start_check = false
- @restarts = 0
- end
- #-------------------------------------------------------------------------
- def is_false
- if @restart_count <= -1
- if @restart_type == 1
- @state = @last_state.clone_all
- else
- @state = @params.clone_all
- end
- @restarts += 1
- elsif @restart_count == 0
- @_end = true
- @frame_end = Graphics.frame_count
- else
- if @restart_type == 1
- @state = @last_state.clone_all
- else
- @state = @params.clone_all
- end
- @restart_count -= 1
- @restarts += 1
- end
- @start_check = false
- end
- #-------------------------------------------------------------------------
- def check_true
- if @state[0][3] > 0
- @state[0][3] -= 1
- elsif @state[0][3] == 0
- @state.slice!(0)
- @last_state = @state.clone_all if @restart_type == 1
- if @state.size == 0
- @_true = true
- @_end = true
- @frame_end = Graphics.frame_count
- end
- end
- end
- private :is_false, :check_true
- end
- #---------------------------------------------------------------------------
- # * Keys input state update
- #---------------------------------------------------------------------------
- def Input.update
- state = API.get_keyboard_state.oscan
- state.each_index do |i|
- @repeat2[i] -= 1 if @repeat2[i] > 1
- if state[i] == "\200" or state[i] == "\201"
- if @trigger2[i]
- @trigger[i] = false
- else
- @trigger[i] = true
- @trigger2[i] = true
- end
- if @repeat2[i] <= 1
- @repeat2[i] = @repeat2[i] == 1 ? REPEAT_TIME : START_REPEAT_TIME
- @repeat2[i] += 1
- @repeat[i] = true
- else
- @repeat[i] = false
- end
- @release2[i] = true
- else
- @trigger[i] = false
- @trigger2[i] = false
- @repeat[i] = false
- @repeat2[i] = 0
- @release[i] = @release2[i] ? true : false
- @release2[i] = false
- end
- @reiterate2[i] -= 1 if @reiterate2[i] > 0
- @reiterate[i] = false if @reiterate2[i] == 0
- if (state[i] == "\001" or state[i] == "\201") and @reiterate3[i] == 0
- @reiterate[i] = true
- @reiterate2[i] = REITERATE_TIME
- @reiterate3[i] = 1
- elsif (state[i] == "\000" or state[i] == "\200") and @reiterate3[i] == 1
- @reiterate[i] = true
- @reiterate2[i] = REITERATE_TIME
- @reiterate3[i] = 0
- end
- end
- @combos.each_value {|c| c.update}
- if MOUSE_INPUT
- @mouse_pos = Aleworks.get_mouse_window_position
- case @mouse_primary_dc[0]
- when 0
- if Input.trigger?(MOUSE_PRIMARY) and @mouse_pos != nil
- @mouse_primary_dc = [1, MOUSE_DOUBLE_CLICK_TIME, @mouse_pos.clone]
- end
- when 1
- if @mouse_pos != nil
- if @mouse_primary_dc[1] > 0 and
- @mouse_pos[0].between?(@mouse_primary_dc[2][0] -
- MOUSE_DOUBLE_CLICK_PIX, @mouse_primary_dc[2][0] +
- MOUSE_DOUBLE_CLICK_PIX) and
- @mouse_pos[1].between?(@mouse_primary_dc[2][1] -
- MOUSE_DOUBLE_CLICK_PIX, @mouse_primary_dc[2][1] +
- MOUSE_DOUBLE_CLICK_PIX)
- @mouse_primary_dc[1] -= 1
- @mouse_primary_dc[0, 1] = 2, 0 if Input.trigger?(MOUSE_PRIMARY)
- else
- @mouse_primary_dc = [0, 0, [nil, nil]]
- end
- else
- @mouse_primary_dc = [0, 0, [nil, nil]]
- end
- when 2
- @mouse_primary_dc = [0, 0, [nil, nil]]
- end
- if Input.press?(MOUSE_PRIMARY)
- if @mouse_pos != nil
- if @mouse_rectdrag == nil
- @mouse_rectdrag = @mouse_pos.clone if Input.trigger?(MOUSE_PRIMARY)
- elsif @mouse_rectdrag.size == 2
- if !@mouse_pos[0].between?(@mouse_rectdrag[0] - MOUSE_DRAG_PIX,
- @mouse_rectdrag[0] + MOUSE_DRAG_PIX) or
- !@mouse_pos[1].between?(@mouse_rectdrag[1] - MOUSE_DRAG_PIX,
- @mouse_rectdrag[1] + MOUSE_DRAG_PIX)
- @mouse_rectdrag.push(*@mouse_pos)
- end
- else
- @mouse_rectdrag[2, 3] = *@mouse_pos
- end
- else
- @mouse_rectdrag = nil
- end
- else
- @mouse_rectdrag = nil
- end
- @mouse_draw = []
- end
- end
- #---------------------------------------------------------------------------
- # * Press?
- #---------------------------------------------------------------------------
- def Input.press?(vk)
- if vk.is_a?(Array)
- vk.each do |i|
- if i.is_a?(Array)
- returntrue = true
- i.each do |e|
- if e.is_a?(Array)
- returntrue2 = false
- e.each do |o|
- if !API::GetAsyncKeyState.call(o).between?(0, 1)
- returntrue2 = true
- end
- end
- returntrue = false if !returntrue2
- elsif !API::GetAsyncKeyState.call(e).between?(0, 1)
- returntrue = false
- end
- end
- return true if returntrue
- else
- return true if !API::GetAsyncKeyState.call(i).between?(0, 1)
- end
- end
- false
- else
- !API::GetAsyncKeyState.call(vk).between?(0, 1)
- end
- end
- #---------------------------------------------------------------------------
- # * Press? all
- #---------------------------------------------------------------------------
- def Input.press_all(state = true)
- pressed = API.get_keyboard_state
- pressed = pressed.scan(/./)
- if state
- pressed.rindexes("\200", "\201")
- else
- pressed.rindexes("\000", "\001")
- end
- end
- #---------------------------------------------------------------------------
- # * Trigger?
- #---------------------------------------------------------------------------
- def Input.trigger?(vk)
- if vk.is_a?(Array)
- vk.each do |i|
- if i.is_a?(Array)
- returntrue = true
- i.each do |e|
- if e.is_a?(Array)
- returntrue2 = false
- e.each do |o| returntrue2 = true if @trigger[o] end
- returntrue = false if !returntrue2
- elsif @trigger[e]
- returntrue = false
- end
- end
- return true if returntrue
- else
- return true if @trigger[i]
- end
- end
- false
- else
- @trigger[vk]
- end
- end
- #---------------------------------------------------------------------------
- # * Trigger? all
- #---------------------------------------------------------------------------
- def Input.trigger_all(state = true)
- @trigger.rindexes(state)
- end
- #---------------------------------------------------------------------------
- # * Repeat?
- #---------------------------------------------------------------------------
- def Input.repeat?(vk)
- if vk.is_a?(Array)
- vk.each do |i|
- if i.is_a?(Array)
- returntrue = true
- i.each do |e|
- if e.is_a?(Array)
- returntrue2 = false
- e.each do |o| returntrue2 = true if @repeat[o] end
- returntrue = false if !returntrue2
- elsif @repeat[e]
- returntrue = false
- end
- end
- return true if returntrue
- else
- return true if @repeat[i]
- end
- end
- false
- else
- @repeat[vk]
- end
- end
- #---------------------------------------------------------------------------
- # * Repeat? all
- #---------------------------------------------------------------------------
- def Input.repeat_all(state = true)
- @repeat.rindexes(state)
- end
- #---------------------------------------------------------------------------
- # * Reiterate?
- #---------------------------------------------------------------------------
- def Input.reiterate?(num)
- if vk.is_a?(Array)
- vk.each do |i|
- if i.is_a?(Array)
- returntrue = true
- i.each do |e|
- if e.is_a?(Array)
- returntrue2 = false
- e.each do |o| returntrue2 = true if @reiterate[o] end
- returntrue = false if !returntrue2
- elsif @reiterate[e]
- returntrue = false
- end
- end
- return true if returntrue
- else
- return true if @reiterate[i]
- end
- end
- false
- else
- @reiterate[vk]
- end
- end
- #---------------------------------------------------------------------------
- # * Reiterate? all
- #---------------------------------------------------------------------------
- def Input.reiterate_all(state = true)
- @reiterate.rindexes(state)
- end
- #---------------------------------------------------------------------------
- # * Release?
- #---------------------------------------------------------------------------
- def Input.release?(vk)
- if vk.is_a?(Array)
- vk.each do |i|
- if i.is_a?(Array)
- returntrue = true
- i.each do |e|
- if e.is_a?(Array)
- returntrue2 = false
- e.each do |o| returntrue2 = true if @release[o] end
- returntrue = false if !returntrue2
- elsif @release[e]
- returntrue = false
- end
- end
- return true if returntrue
- else
- return true if @release[i]
- end
- end
- false
- else
- @release[vk]
- end
- end
- #---------------------------------------------------------------------------
- # * Release? all
- #---------------------------------------------------------------------------
- def Input.release_all(state = true)
- @release.rindexes(state)
- end
- #---------------------------------------------------------------------------
- # * 4 Directions
- #---------------------------------------------------------------------------
- def Input.dir4
- return 2 if Input.press?(Input::DOWN)
- return 4 if Input.press?(Input::LEFT)
- return 6 if Input.press?(Input::RIGHT)
- return 8 if Input.press?(Input::UP)
- 0
- end
- #---------------------------------------------------------------------------
- # * 8 Directions
- #---------------------------------------------------------------------------
- def Input.dir8
- return 1 if Input.press?([[Input::DOWN, Input::LEFT]])
- return 3 if Input.press?([[Input::DOWN, Input::RIGHT]])
- return 7 if Input.press?([[Input::UP, Input::LEFT]])
- return 9 if Input.press?([[Input::UP, Input::RIGHT]])
- return 1 if Input.press?(Input::LOWER_LEFT)
- return 3 if Input.press?(Input::LOWER_RIGHT)
- return 7 if Input.press?(Input::UPPER_LEFT)
- return 9 if Input.press?(Input::UPPER_RIGHT)
- return 2 if Input.press?(Input::DOWN)
- return 4 if Input.press?(Input::LEFT)
- return 6 if Input.press?(Input::RIGHT)
- return 8 if Input.press?(Input::UP)
- 0
- end
- #---------------------------------------------------------------------------
- # * Activated?
- #---------------------------------------------------------------------------
- def Input.activated?(vk)
- API::GetKeyState.call(vk) & 1 == 1
- end
- #---------------------------------------------------------------------------
- # * Key Click
- #---------------------------------------------------------------------------
- def Input.key_click(vk)
- vk = vk.to_a
- vk.each {|k| API::Keybd_Event.call(k, 0, 0, 0)}
- vk.each {|k| API::Keybd_Event.call(k, 0, 2, 0)}
- end
- #---------------------------------------------------------------------------
- # * Key Release
- #---------------------------------------------------------------------------
- def Input.key_release(vk)
- vk = vk.to_a
- vk.each {|k| API::Keybd_Event.call(k, 0, 2, 0)}
- end
- #---------------------------------------------------------------------------
- # * Key Press
- #---------------------------------------------------------------------------
- def Input.key_press(vk)
- vk = vk.to_a
- vk.each {|k| API::Keybd_Event.call(k, 0, 0, 0)}
- end
- #---------------------------------------------------------------------------
- # * Mouse Double Click?
- #---------------------------------------------------------------------------
- def Input.mouse_double_click?
- @mouse_primary_dc[0] == 2
- end
- #---------------------------------------------------------------------------
- # * Mouse X Coordinate
- #---------------------------------------------------------------------------
- def Input.mouse_x?
- @mouse_pos.nil? ? nil : @mouse_pos[0]
- end
- #---------------------------------------------------------------------------
- # * Mouse Y Coordinate
- #---------------------------------------------------------------------------
- def Input.mouse_y?
- @mouse_pos.nil? ? nil : @mouse_pos[1]
- end
- #---------------------------------------------------------------------------
- # * Mouse Dragging?
- #---------------------------------------------------------------------------
- def Input.mouse_dragging?
- return false if @mouse_rectdrag.nil?
- if @mouse_rectdrag.size >= 4
- true
- else
- false
- end
- end
- #---------------------------------------------------------------------------
- # * Mouse Drag Rect
- #---------------------------------------------------------------------------
- def Input.mouse_drag_rect?
- return nil if @mouse_rectdrag.nil?
- if @mouse_rectdrag.size >= 4
- if @mouse_rectdrag[0] <= @mouse_rectdrag[2]
- x = @mouse_rectdrag[0]
- width = @mouse_rectdrag[2] - @mouse_rectdrag[0]
- else
- x = @mouse_rectdrag[2]
- width = @mouse_rectdrag[0] - @mouse_rectdrag[2]
- end
- if @mouse_rectdrag[1] <= @mouse_rectdrag[3]
- y = @mouse_rectdrag[1]
- heigth = @mouse_rectdrag[3] - @mouse_rectdrag[1]
- else
- y = @mouse_rectdrag[3]
- heigth = @mouse_rectdrag[1] - @mouse_rectdrag[3]
- end
- Rect.new(x, y, width, heigth)
- else
- nil
- end
- end
- #---------------------------------------------------------------------------
- # * Mouse Drag Coordinates
- #---------------------------------------------------------------------------
- def Input.mouse_drag_coor?
- return nil if @mouse_rectdrag.nil?
- if @mouse_rectdrag.size >= 4
- @mouse_rectdrag
- else
- nil
- end
- end
- #---------------------------------------------------------------------------
- # * Add Combo
- #---------------------------------------------------------------------------
- def Input.add_combo(params, restart_count, res_type, update = nil, id = nil)
- combo = Key_Combo.new(params, restart_count, res_type, update)
- if id.nil?
- if !@combos.has_key?(combo.id)
- id = combo.id
- else
- loop do
- id = rand(0xFFFF)
- break if !@combos.has_key?(id)
- end
- end
- else
- if @combos.has_key?(id)
- loop do
- id = rand(0xFFFF)
- break if !@combos.has_key?(id)
- end
- end
- end
- @combos[id] = combo
- return id
- end
- #---------------------------------------------------------------------------
- # * Get All Combos
- #---------------------------------------------------------------------------
- def Input.combos
- @combos
- end
- #---------------------------------------------------------------------------
- # * Edit combos
- #---------------------------------------------------------------------------
- def Input.combos=(new)
- @combos = new
- end
- #---------------------------------------------------------------------------
- # * Delete Combo
- #---------------------------------------------------------------------------
- def Input.delete_combo(id)
- @combos.delete(id)
- end
- #---------------------------------------------------------------------------
- # * Delete Ended Combos
- #---------------------------------------------------------------------------
- def Input.delete_ended_combos(ending = true)
- deleted = {}
- @combo.each_key do |c|
- if @combo[c].end?
- next if !@combo[c].true? == ending
- deleted[c] = @combo[c]
- @combos.delete(c)
- end
- end
- return deleted
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment