Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=============================================================================
- # *** AWorks Input Module(AIM)
- #=============================================================================
- # Created by AWorks
- # Version: 3.00
- # Last Modification: 26/01/2009 (day/month/year)
- # Compatible with RMXP & RMVX
- #=============================================================================
- #==== Description ====
- # This script simulates the RGSS/2 module Input. It is not the original module,
- # but it has all the original module functions and some new.
- #=============================================================================
- #==== Requeriments ====
- # * ALibrary (AWorks Library)
- # - Version: 1.03
- # * AKM (AWorks Keys Module)
- # - Optional, but recommended
- #=============================================================================
- #==== Version History ====
- # * Version 3.00
- # - Complete rewrite of the script, now it uses AWorks.dll for input updating
- #=============================================================================
- #==== Features ====
- # * All keyboard/mouse keys
- # - When calling one of the keys states methods(press?, trigger?, and so on)
- # you can use the AKM script for obtaining the keys identifiers.
- # Insteand of: (Like in the original Input)
- # Input.press?(Input::[KEY NAME HERE])
- # Use: (If you want to detect "X" key from keyboard/mouse)
- # Input.press?(Keys::[KEY NAME HERE])
- # Example for F3 key:
- # Input.press?(Keys::F3)
- # Example for H key:
- # Input.press?(Keys::H)
- # Example for Y key:
- # Input.press?(Keys::Y)
- #
- # * Input.release?(vk)
- # - Determines whether the key vk is being released. It can be considered as
- # the opposite function of Input.trigger?
- #
- # * Input.pressed
- # - Returns all keys which are being pressed
- #
- # * Input.triggered
- # - Returns all keys which are being triggered
- #
- # * Input.repeated
- # - Returns all keys which are being repeated
- #
- # * Input.released
- # - Returns all keys which are being released
- #=============================================================================
- #==== Notes ====
- # * For more information about the Input.press?, Input.trigger?, Input.repeat?,
- # Input.dir4, Input.dir8 and Input.update methods see the RMXP/RMVX help file.
- #
- # * Don't confuse the Input module keys(A, B, C, X, Y, Z, L, R) with the
- # keyboard letters, as the firsts recognize only the user's buttons
- # configuration(Accessible in the F1 menu) and not the real keyboard keys.
- #
- # * This input system works with virtual keys(VK) for identifying all of the
- # keyboard and mouse keys, and they consist on numbers between 0..255. Each
- # key on keyboard has its own and unique VK and are listed on the
- # AKM for easy use.
- #
- # * Note that not all computers have the same keyboard and keyboard
- # configuration(Layout), specially for the special symbols and characters
- # keys. Commonly, keyboards just vary in the OEM keys(See AKM), but also
- # some keyboards have some extra keys others doesn't have. (The same applies
- # for mouses)
- #
- # * This script doesn't detect changes in the buttons configuration from the
- # F1 menu until the game closes and the configuration is saved to the
- # registry. So, you have to restart the game for the configurations to have
- # effect.
- #
- # * The Conditional Branch "Button being pressed" option and the "Button Input
- # Processing" command are incompatible with this new Input system. However,
- # you may use AIM:PXP patch for RMXP or AIM:PVX patch for RMVX for fixing this
- # incompatibility.
- #=============================================================================
- #==== Advices ====
- # * You can check the state of a key in an event using the Script option of the
- # Conditional Branch event command just writing the Input method and the key
- # you want to check.
- # Example for letter "O", just put:
- # Input.press?(Keys::O)
- #=============================================================================
- #=============================================================================
- # ** Module Input
- #=============================================================================
- module Input
- #---------------------------------------------------------------------------
- # * Variables declaration
- #---------------------------------------------------------------------------
- @time = Array.new(256, 0)
- @press = Array.new(256, false)
- @trigger = Array.new(256, false)
- @repeat = Array.new(256, false)
- @release = Array.new(256, false)
- @dirs = [0, 0]
- #---------------------------------------------------------------------------
- # * convert_keys (internal method)
- #---------------------------------------------------------------------------
- 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}
- DEFAULT_KEYS = {11=>[16,90],12=>[27,88,96],13=>[13,32,67],14=>[65],15=>[83],
- 16=>[68],17=>[81],18=>[87]}
- def convert_keys(key)
- begin
- keys = []
- rkey = 'HKEY_CURRENT_USER\\Software\\Enterbrain\\RGSS'
- data = AWorks::Registry.read_entry(rkey, 'ButtonAssign')[10, 25].scan(/./)
- 15.times {|i| keys.push(REG_KVALUES[i]) if key == data[i].unpack('C')[0]}
- keys
- rescue
- DEFAULT_KEYS[key] rescue []
- end
- end
- module_function :convert_keys
- #---------------------------------------------------------------------------
- # * Keys Constants declaration
- #---------------------------------------------------------------------------
- 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 = [45] + convert_keys(12)
- C = convert_keys(13)
- X = convert_keys(14)
- Y = convert_keys(15)
- Z = convert_keys(16)
- L = [33] + convert_keys(17)
- R = [34] + convert_keys(18)
- SHIFT = 16
- CTRL = 17
- ALT = 18
- F5 = 116
- F6 = 117
- F7 = 118
- F8 = 119
- F9 = 120
- #---------------------------------------------------------------------------
- # * Initialize Input
- #---------------------------------------------------------------------------
- AWorks::API::InputIni.call(@time.object_id, @press.object_id,
- @trigger.object_id, @repeat.object_id, @release.object_id, @dirs.object_id)
- #---------------------------------------------------------------------------
- # * Keys input state update
- #---------------------------------------------------------------------------
- def Input.update
- AWorks::API::InputUpdate.call
- end
- #---------------------------------------------------------------------------
- # * Press?
- #---------------------------------------------------------------------------
- def Input.press?(vk)
- @press.indexes(*vk).include?(true)
- end
- #---------------------------------------------------------------------------
- # * Pressed
- #---------------------------------------------------------------------------
- def Input.pressed
- array = Array.new
- @press.each_index {|i| array.push(i) if @press[i]}
- array
- end
- #---------------------------------------------------------------------------
- # * Trigger?
- #---------------------------------------------------------------------------
- def Input.trigger?(vk)
- @trigger.indexes(*vk).include?(true)
- end
- #---------------------------------------------------------------------------
- # * Triggered
- #---------------------------------------------------------------------------
- def Input.triggered
- array = Array.new
- @trigger.each_index {|i| array.push(i) if @trigger[i]}
- array
- end
- #---------------------------------------------------------------------------
- # * Repeat?
- #---------------------------------------------------------------------------
- def Input.repeat?(vk)
- @repeat.indexes(*vk).include?(true)
- end
- #---------------------------------------------------------------------------
- # * Repeated
- #---------------------------------------------------------------------------
- def Input.repeated
- array = Array.new
- @repeat.each_index {|i| array.push(i) if @repeat[i]}
- array
- end
- #---------------------------------------------------------------------------
- # * Release?
- #---------------------------------------------------------------------------
- def Input.release?(vk)
- @release.indexes(*vk).include?(true)
- end
- #---------------------------------------------------------------------------
- # * Released
- #---------------------------------------------------------------------------
- def Input.released
- array = Array.new
- @release.each_index {|i| array.push(i) if @release[i]}
- array
- end
- #---------------------------------------------------------------------------
- # * 4 Directions
- #---------------------------------------------------------------------------
- def Input.dir4
- @dirs[0]
- end
- #---------------------------------------------------------------------------
- # * 8 Directions
- #---------------------------------------------------------------------------
- def Input.dir8
- @dirs[1]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment