设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3575|回复: 6
打印 上一主题 下一主题

[已经解决] 如何设置vx全键盘

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
6 小时
注册时间
2017-2-3
帖子
13
跳转到指定楼层
1
发表于 2017-2-6 20:26:02 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
求网址和工程,给个答案吧。
想设置一个按下v触发。
要脚本。

Lv4.逐梦者 (版主)

梦石
1
星屑
6651
在线时间
2650 小时
注册时间
2013-8-23
帖子
2315

开拓者

2
发表于 2017-2-7 01:11:39 | 只看该作者
本帖最后由 鑫晴 于 2017-2-7 01:46 编辑


Key Input Module
Author: Glitchfinder
Version: 1.30




RUBY 代码复制
  1. # 想设置一个按下v触发。
  2. Keys.press?(Keys::V)



  1. #==============================================================================
  2. # ** Glitchfinder's Key Input Module
  3. #    Version 1.30
  4. #------------------------------------------------------------------------------
  5. #  [RPG Maker XP] [RPG Maker VX] [RPG Maker VX Ace]
  6. #------------------------------------------------------------------------------
  7. #  This script helps scripters to use the full range of keys on any keyboard,
  8. #  without being limited by the default Input Module.
  9. #==============================================================================
  10. # * Version History
  11. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  12. #   Version 1.00 ------------------------------------------------- (2010-03-18)
  13. #     - Initial version
  14. #     - Author: Glitchfinder
  15. #    Version 1.10 ------------------------------------------------ (2010-08-20)
  16. #      - Added the Keys.toggle? method
  17. #      - Added the Keys.capslock? method
  18. #      - Added the Keys.numlock? method
  19. #      - Added the Keys.scroll? method
  20. #      - Added the Keys.character_press method
  21. #      - Added the Keys.character_trigger method
  22. #      - Added the Keys.character_repeat method
  23. #      - Added the Keys.get_character method
  24. #      - Added the ANYKEY key constant
  25. #      - Streamlined the script
  26. #      - Patched various errors
  27. #      - Author: Glitchfinder
  28. #    Version 1.20 ------------------------------------------------ (2011-03-17)
  29. #      - Added the Keys.array_press? method
  30. #      - Added the Keys.array_trigger? method
  31. #      - Added the Keys.array_repeat? method
  32. #      - Added the Keys.array_release? method
  33. #      - Added the Keys.array_toggle? method
  34. #      - Modified the Keys.press? method for better error hendling
  35. #      - Modified the Keys.trigger? method for better error hendling
  36. #      - Modified the Keys.repeat? method for better error hendling
  37. #      - Modified the Keys.release? method for better error hendling
  38. #      - Modified the Keys.toggle? method for better error hendling
  39. #      - Author: Glitchfinder
  40. #    Version 1.30 ------------------------------------------------ (2014-02-07)
  41. #      - Added the Keys.validate_key? method
  42. #      - Modified the Keys.array_press? method for efficiency
  43. #      - Modified the Keys.array_trigger? method for efficiency
  44. #      - Modified the Keys.array_repeat? method for efficiency
  45. #      - Modified the Keys.array_release? method for efficiency
  46. #      - Modified the Keys.array_toggle? method for efficiency
  47. #      - Modified the Keys.press? method to reduce unnecessary code
  48. #      - Modified the Keys.trigger? method to reduce unnecessary code
  49. #      - Modified the Keys.repeat? method to reduce unnecessary code
  50. #      - Modified the Keys.release? method to reduce unnecessary code
  51. #      - Modified the Keys.toggle? method to reduce unnecessary code
  52. #      - Changed the license to be more open
  53. #      - Author: Glitchfinder
  54. #==============================================================================
  55. # * Instructions
  56. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  57. #  Place this script above Main, and below the default scripts. (I realize this
  58. #  is obvious to most, but some people don't get it.)
  59. #
  60. #  This module is automatically updated by the default Input module, which
  61. #  means that the only time you need to call the update method is in a scene
  62. #  that does not update the default Input module.
  63. #
  64. #  This module does not break the functionality of the default Input module.
  65. #
  66. #  If you wish to read keys from a gamepad, you must still use the default
  67. #  input module to do so.
  68. #
  69. #  To use this module, simply use one of the four methods (press?(key),
  70. #  trigger?(key), repeat?(key), or release?(key)), where key is the index of
  71. #  the key you want to check. Key may also be used as Keys::KEYNAME. For a list
  72. #  of acceptable key names, look below the header.
  73. #
  74. #  There is a key named ANYKEY. This key can be used like any other key, with
  75. #  the exception that, instead of corresponding to any one key, it reacts to
  76. #  them all. If you use it, and any other key would cause the same method to
  77. #  return true, then the ANYKEY will also return true.
  78. #==============================================================================
  79. # * Method List
  80. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  81. #  Keys.update
  82. #    Updates keyboard input. Calls to this method are not necessary unless the
  83. #    default Input module is not being updated.
  84. #
  85. #  Keys.press?(key)
  86. #    Determines whether the button determined by key is currently being
  87. #    pressed. If the button is being pressed, returns true. If not, returns
  88. #    false.
  89. #
  90. #  Keys.trigger?(key)
  91. #    Determines whether the button determined by key is being pressed again.
  92. #    "Pressed again" is seen as time having passed between the button being not
  93. #    pressed and being pressed. If the button is being pressed, returns true.
  94. #    If not, returns false.
  95. #
  96. #  Keys.repeat?(key)
  97. #    Determines whether the button determined by key is being pressed again.
  98. #    Unlike trigger?(), this takes into account the repeat input of a button
  99. #    being held down continuously. If the button is being pressed, returns
  100. #    true. If not, returns false.
  101. #
  102. #  Keys.release?(key)
  103. #    Determines whether the button determined by key has just been released. If
  104. #    the button has been released, returns true. If not, returns false.
  105. #
  106. #  Keys.toggle?(key)
  107. #    Determines whether the button determined by key has been toggled. This
  108. #    functions like Caps Lock, Number Lock, and Scroll Lock, only for all keys.
  109. #
  110. #  Keys.array_press?(keys)
  111. #    Functions in the same manner as Keys.press?(), only it takes an array of
  112. #    keys as input.
  113. #
  114. #  Keys.array_trigger?(keys)
  115. #    Functions in the same manner as Keys.trigger?(), only it takes an array of
  116. #    keys as input.
  117. #
  118. #  Keys.array_repeat?(keys)
  119. #    Functions in the same manner as Keys.repeat?(), only it takes an array of
  120. #    keys as input.
  121. #
  122. #  Keys.array_release?(keys)
  123. #    Functions in the same manner as Keys.release?(), only it takes an array of
  124. #    keys as input.
  125. #
  126. #  Keys.array_toggle?(keys)
  127. #    Functions in the same manner as Keys.toggle?(), only it takes an array of
  128. #    keys as input.
  129. #
  130. #  Keys.capslock?
  131. #    Determines whether the caps lock key is toggled on. This will always
  132. #    return true when the corresponding keyboard light is lit, and false when
  133. #    it is not.
  134. #
  135. #  Keys.numlock?
  136. #    Determines whether the number lock key is toggled on. This will always
  137. #    return true when the corresponding keyboard light is lit, and false when
  138. #    it is not.
  139. #
  140. #  Keys.scroll?
  141. #    Determines whether the scroll lock key is toggled on. This will always
  142. #    return true when the corresponding keyboard light is lit, and false when
  143. #    it is not.
  144. #
  145. #  Keys.character_press
  146. #    Returns the currently pressed key, if it would generate text input. If no
  147. #    such key would register as pressed, it returns an empty string.
  148. #
  149. #  Keys.character_trigger
  150. #    Returns the currently triggered key, if it would generate text input. If
  151. #    no such key would register as triggered, it returns an empty string.
  152. #
  153. #  Keys.character_repeat
  154. #    Returns the currently repeated key, if it would generate text input. If no
  155. #    such key would register as repeated, it returns an empty string.
  156. #
  157. #  Keys.get_character(key, scan_code)
  158. #    Returns the character corresponding to the given key. If no character
  159. #    is recognized by the system, it returns false instead. This method is
  160. #    intended for internal use.
  161. #
  162. #  Keys.validate_key(key)
  163. #    Checks the validity of a key. If a key variable can be used by this
  164. #    module, it will return true. Otherwise, it will return false.
  165. #==============================================================================
  166. # * Known Issues
  167. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  168. #  This script has trouble with certain foreign language keyboards, where dead
  169. #  keys are shift sensitive. Dead keys are used to insert diacritical marks
  170. #  such as an accent. However, the correct character can be generated with
  171. #  creative use of shift and caps lock.
  172. #==============================================================================
  173. # * Glitchfinder's Advice
  174. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  175. #  This script is meant for people with a medium or advanced level of scripting
  176. #  knowledge and ability, or for those using scripts that require this module.
  177. #==============================================================================
  178. # * License
  179. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  180. #  This script is licensed under the MIT License:
  181. #
  182. #  Copyright (c) 2010-2014 Sean Porter (Glitchfinder) <[email protected]>
  183. #
  184. #  Permission is hereby granted, free of charge, to any person obtaining a copy
  185. #  of this software and associated documentation files (the "Software"), to deal
  186. #  in the Software without restriction, including without limitation the rights
  187. #  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  188. #  copies of the Software, and to permit persons to whom the Software is
  189. #  furnished to do so, subject to the following conditions:
  190. #
  191. #  The above copyright notice and this permission notice shall be included in
  192. #  all copies or substantial portions of the Software.
  193. #
  194. #  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  195. #  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  196. #  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  197. #  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  198. #  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  199. #  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  200. #  THE SOFTWARE.
  201. #==============================================================================

  202. #==============================================================================
  203. # ** Keys
  204. #------------------------------------------------------------------------------
  205. #  This module performs key input processing
  206. #==============================================================================

  207. module Keys
  208.   #--------------------------------------------------------------------------
  209.   # * Miscellaneous Keys
  210.   #--------------------------------------------------------------------------
  211.   CANCEL              = 0x03 # Control-Break Processing
  212.   BACKSPACE           = 0x08 # Backspace Key
  213.   TAB                 = 0x09 # Tab Key
  214.   CLEAR               = 0x0C # Clear Key
  215.   RETURN              = 0x0D # Enter Key
  216.   SHIFT               = 0x10 # Shift Key
  217.   CONTROL             = 0x11 # Ctrl Key
  218.   MENU                = 0x12 # Alt Key
  219.   PAUSE               = 0x13 # Pause Key
  220.   ESCAPE              = 0x1B # Esc Key
  221.   CONVERT             = 0x1C # IME Convert Key
  222.   NONCONVERT          = 0x1D # IME Nonconvert Key
  223.   ACCEPT              = 0x1E # IME Accept Key
  224.   SPACE               = 0x20 # Space Bar Key (Space, usually blank)
  225.   PRIOR               = 0x21 # Page Up Key
  226.   NEXT                = 0x22 # Page Down Key
  227.   ENDS                = 0x23 # End Key
  228.   HOME                = 0x24 # Home Key
  229.   LEFT                = 0x25 # Left Arrow Key
  230.   UP                  = 0x26 # Up Arrow Key
  231.   RIGHT               = 0x27 # Right Arrow Key
  232.   DOWN                = 0x28 # Down Arrow Key
  233.   SELECT              = 0x29 # Select Key
  234.   PRINT               = 0x2A # Print Key
  235.   EXECUTE             = 0x2B # Execute Key
  236.   SNAPSHOT            = 0x2C # Print Screen Key
  237.   DELETE              = 0x2E # Delete Key
  238.   HELP                = 0x2F # Help Key
  239.   LSHIFT              = 0xA0 # Left Shift Key
  240.   RSHIFT              = 0xA1 # Right Shift Key
  241.   LCONTROL            = 0xA2 # Left Control Key (Ctrl)
  242.   RCONTROL            = 0xA3 # Right Control Key (Ctrl)
  243.   LMENU               = 0xA4 # Left Menu Key (Alt)
  244.   RMENU               = 0xA5 # Right Menu Key (Alt)
  245.   PACKET              = 0xE7 # Used to Pass Unicode Characters as Keystrokes
  246.   #--------------------------------------------------------------------------
  247.   # * Number Keys
  248.   #--------------------------------------------------------------------------
  249.   N0                  = 0x30 # 0 Key
  250.   N1                  = 0x31 # 1 Key
  251.   N2                  = 0x32 # 2 Key
  252.   N3                  = 0x33 # 3 Key
  253.   N4                  = 0x34 # 4 Key
  254.   N5                  = 0x35 # 5 Key
  255.   N6                  = 0x36 # 6 Key
  256.   N7                  = 0x37 # 7 Key
  257.   N8                  = 0x38 # 8 Key
  258.   N9                  = 0x39 # 9 Key
  259.   #--------------------------------------------------------------------------
  260.   # * Letter Keys
  261.   #--------------------------------------------------------------------------
  262.   A                   = 0x41 # A Key
  263.   B                   = 0x42 # B Key
  264.   C                   = 0x43 # C Key
  265.   D                   = 0x44 # D Key
  266.   E                   = 0x45 # E Key
  267.   F                   = 0x46 # F Key
  268.   G                   = 0x47 # G Key
  269.   H                   = 0x48 # H Key
  270.   I                   = 0x49 # I Key
  271.   J                   = 0x4A # J Key
  272.   K                   = 0x4B # K Key
  273.   L                   = 0x4C # L Key
  274.   M                   = 0x4D # M Key
  275.   N                   = 0x4E # N Key
  276.   O                   = 0x4F # O Key
  277.   P                   = 0x50 # P Key
  278.   Q                   = 0x51 # Q Key
  279.   R                   = 0x52 # R Key
  280.   S                   = 0x53 # S Key
  281.   T                   = 0x54 # T Key
  282.   U                   = 0x55 # U Key
  283.   V                   = 0x56 # V Key
  284.   W                   = 0x57 # W Key
  285.   X                   = 0x58 # X Key
  286.   Y                   = 0x59 # Y Key
  287.   Z                   = 0x5A # Z Key
  288.   #--------------------------------------------------------------------------
  289.   # * Windows Keys
  290.   #--------------------------------------------------------------------------
  291.   LWIN                = 0x5B # Left Windows Key (Natural keyboard)
  292.   RWIN                = 0x5C # Right Windows Key (Natural Keyboard)
  293.   APPS                = 0x5D # Applications Key (Natural keyboard)
  294.   SLEEP               = 0x5F # Computer Sleep Key
  295.   BROWSER_BACK        = 0xA6 # Browser Back Key
  296.   BROWSER_FORWARD     = 0xA7 # Browser Forward Key
  297.   BROWSER_REFRESH     = 0xA8 # Browser Refresh Key
  298.   BROWSER_STOP        = 0xA9 # Browser Stop Key
  299.   BROWSER_SEARCH      = 0xAA # Browser Search Key
  300.   BROWSER_FAVORITES   = 0xAB # Browser Favorites Key
  301.   BROWSER_HOME        = 0xAC # Browser Start and Home Key
  302.   VOLUME_MUTE         = 0xAD # Volume Mute Key
  303.   VOLUME_DOWN         = 0xAE # Volume Down Key
  304.   VOLUME_UP           = 0xAF # Volume Up Key
  305.   MEDIA_NEXT_TRACK    = 0xB0 # Next Track Key
  306.   MEDIA_PREV_TRACK    = 0xB1 # Previous Track Key
  307.   MEDIA_STOP          = 0xB2 # Stop Media Key
  308.   MEDIA_PLAY_PAUSE    = 0xB3 # Play/Pause Media Key
  309.   LAUNCH_MAIL         = 0xB4 # Start Mail Key
  310.   LAUNCH_MEDIA_SELECT = 0xB5 # Select Media Key
  311.   LAUNCH_APP1         = 0xB6 # Start Application 1 Key
  312.   LAUNCH_APP2         = 0xB7 # Start Application 2 Key
  313.   PROCESSKEY          = 0xE5 # IME Process Key
  314.   ATTN                = 0xF6 # Attn Key
  315.   CRSEL               = 0xF7 # CrSel Key
  316.   EXSEL               = 0xF8 # ExSel Key
  317.   EREOF               = 0xF9 # Erase EOF Key
  318.   PLAY                = 0xFA # Play Key
  319.   ZOOM                = 0xFB # Zoom Key
  320.   PA1                 = 0xFD # PA1 Key
  321.   #--------------------------------------------------------------------------
  322.   # * Number Pad Keys
  323.   #--------------------------------------------------------------------------
  324.   NUMPAD0             = 0x60 # Numeric Keypad 0 Key
  325.   NUMPAD1             = 0x61 # Numeric Keypad 1 Key
  326.   NUMPAD2             = 0x62 # Numeric Keypad 2 Key
  327.   NUMPAD3             = 0x63 # Numeric Keypad 3 Key
  328.   NUMPAD4             = 0x64 # Numeric Keypad 4 Key
  329.   NUMPAD5             = 0x65 # Numeric Keypad 5 Key
  330.   NUMPAD6             = 0x66 # Numeric Keypad 6 Key
  331.   NUMPAD7             = 0x67 # Numeric Keypad 7 Key
  332.   NUMPAD8             = 0x68 # Numeric Keypad 8 Key
  333.   NUMPAD9             = 0x69 # Numeric Keypad 9 Key
  334.   MULTIPLY            = 0x6A # Multiply Key (*)
  335.   ADD                 = 0x6B # Add Key (+)
  336.   SEPARATOR           = 0x6C # Separator Key
  337.   SUBTRACT            = 0x6D # Subtract Key (-)
  338.   DECIMAL             = 0x6E # Decimal Key (.)
  339.   DIVIDE              = 0x6F # Divide Key (/)
  340.   #--------------------------------------------------------------------------
  341.   # * Function Keys
  342.   #--------------------------------------------------------------------------
  343.   F1                  = 0x70 # F1 Key
  344.   F2                  = 0x71 # F2 Key
  345.   F3                  = 0x72 # F3 Key
  346.   F4                  = 0x73 # F4 Key
  347.   F5                  = 0x74 # F5 Key
  348.   F6                  = 0x75 # F6 Key
  349.   F7                  = 0x76 # F7 Key
  350.   F8                  = 0x77 # F8 Key
  351.   F9                  = 0x78 # F9 Key
  352.   F10                 = 0x79 # F10 Key
  353.   F11                 = 0x7A # F11 Key
  354.   F12                 = 0x7B # F12 Key
  355.   F13                 = 0x7C # F13 Key
  356.   F14                 = 0x7D # F14 Key
  357.   F15                 = 0x7E # F15 Key
  358.   F16                 = 0x7F # F16 Key
  359.   F17                 = 0x80 # F17 Key
  360.   F18                 = 0x81 # F18 Key
  361.   F19                 = 0x82 # F19 Key
  362.   F20                 = 0x83 # F20 Key
  363.   F21                 = 0x84 # F21 Key
  364.   F22                 = 0x85 # F22 Key
  365.   F23                 = 0x86 # F23 Key
  366.   F24                 = 0x87 # F24 Key
  367.   #--------------------------------------------------------------------------
  368.   # * Toggle Keys
  369.   #--------------------------------------------------------------------------
  370.   CAPITAL             = 0x14 # Caps Lock Key
  371.   KANA                = 0x15 # IME Kana Mode Key
  372.   HANGUL              = 0x15 # IME Hangul Mode Key
  373.   JUNJA               = 0x17 # IME Junja Mode Key
  374.   FINAL               = 0x18 # IME Final Mode Key
  375.   HANJA               = 0x19 # IME Hanja Mode Key
  376.   KANJI               = 0x19 # IME Kanji Mode Key
  377.   MODECHANGE          = 0x1F # IME Mode Change Request Key
  378.   INSERT              = 0x2D # Insert Key
  379.   NUMLOCK             = 0x90 # Num Lock Key
  380.   SCROLL              = 0x91 # Scroll Lock Key
  381.   #--------------------------------------------------------------------------
  382.   # * OEM Keys (Vary by keyboard)
  383.   #--------------------------------------------------------------------------
  384.   OEM_1               = 0xBA # Misc Characters (; : in USA 101/102 Keyboards)
  385.   OEM_PLUS            = 0xBB # + = Key
  386.   OEM_COMMA           = 0xBC # , < Key
  387.   OEM_MINUS           = 0xBD # - _ Key
  388.   OEM_PERIOD          = 0xBE # . > Key
  389.   OEM_2               = 0xBF # Misc Characters (/ ? in USA 101/102 Keyboards)
  390.   OEM_3               = 0xC0 # Misc Characters (` ~ in USA 101/102 Keyboards)
  391.   OEM_4               = 0xDB # Misc Characters ([ { in USA 101/102 Keyboards)
  392.   OEM_5               = 0xDC # Misc Characters (\ | in USA 101/102 Keyboards)
  393.   OEM_6               = 0xDD # Misc Characters (] } in USA 101/102 Keyboards)
  394.   OEM_7               = 0xDE # Misc Characters (' " in USA 101/102 Keyboards)
  395.   OEM_8               = 0xDF # Misc Characters (Varies by Keyboard)
  396.   OEM_9               = 0xE1 # OEM Specific
  397.   OEM_10              = 0x92 # OEM Specific
  398.   OEM_11              = 0x93 # OEM Specific
  399.   OEM_12              = 0x94 # OEM Specific
  400.   OEM_13              = 0x95 # OEM Specific
  401.   OEM_14              = 0x96 # OEM Specific
  402.   OEM_15              = 0xE3 # OEM Specific
  403.   OEM_16              = 0xE4 # OEM Specific
  404.   OEM_17              = 0xE6 # OEM Specific
  405.   OEM_18              = 0xE9 # OEM Specific
  406.   OEM_19              = 0xEA # OEM Specific
  407.   OEM_20              = 0xEB # OEM Specific
  408.   OEM_21              = 0xEC # OEM Specific
  409.   OEM_22              = 0xED # OEM Specific
  410.   OEM_23              = 0xEE # OEM Specific
  411.   OEM_24              = 0xEF # OEM Specific
  412.   OEM_25              = 0xF1 # OEM Specific
  413.   OEM_26              = 0xF2 # OEM Specific
  414.   OEM_27              = 0xF3 # OEM Specific
  415.   OEM_28              = 0xF4 # OEM Specific
  416.   OEM_29              = 0xF5 # OEM Specific
  417.   OEM_102             = 0xE2 # Angle Bracket or Backslash on RT-102 Keyboards
  418.   OEM_CLEAR           = 0xFE # Clear Key
  419.   #--------------------------------------------------------------------------
  420.   # * Special Keys
  421.   #--------------------------------------------------------------------------
  422.   ANYKEY              = 0x100 # Any Key
  423.   #--------------------------------------------------------------------------
  424.   # * Declare Module Variables
  425.   #--------------------------------------------------------------------------
  426.   begin
  427.     # Create strings for unpacking input
  428.     @unpack_string = 'B' * 256
  429.     @toggle_unpack_string = 'b' * 256
  430.     # Generate blank input arrays
  431.     @last_array = '0' * 256
  432.     @press   = Array.new(256, false) # Key currently pressed
  433.     @trigger = Array.new(256, false) # Key initially pressed
  434.     @repeat  = Array.new(256, false) # Key being held
  435.     @release = Array.new(256, false) # Key being released
  436.     @toggle  = Array.new(256, false) # Key currently toggled
  437.     # Generate blank counter array
  438.     @repeat_counter = Array.new(256, 0)
  439.     # Declare keyboard API
  440.     @getKeyboardState = Win32API.new('user32.dll', 'GetKeyboardState', 'P', 'V')
  441.     @getAsyncKeyState = Win32API.new('user32.dll', 'GetAsyncKeyState', 'I', 'I')
  442.     @getKeyState = Win32API.new('user32.dll', 'GetKeyState', 'I', 'I')
  443.     @getKeyboardLayoutName = Win32API.new('user32.dll', 'GetKeyboardLayoutName',
  444.       'P', 'I')
  445.     @loadKeyboardLayout = Win32API.new('user32.dll', 'LoadKeyboardLayout', 'PI',
  446.       'I')
  447.     @mapVirtualKeyEx = Win32API.new('user32.dll', 'MapVirtualKeyEx', 'III', 'I')
  448.     @toUnicodeEx = Win32API.new('user32.dll', 'ToUnicodeEx', 'IIPPIII', 'I')
  449.     # Call current keyboard state
  450.     @getKeyboardState.call(@last_array)
  451.     # Set previous keyboard state
  452.     @last_array = @last_array.unpack(@unpack_string)
  453.     # Set a blank keyboard state
  454.     @keyboard_state = '0'*256
  455.     # Set array to input character list
  456.     @input_characters = [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S,
  457.       T, U, V, W, X, Y, Z, N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, OEM_MINUS,
  458.       OEM_PLUS, OEM_COMMA, OEM_PERIOD, OEM_1, OEM_2, OEM_3, OEM_4, OEM_5, OEM_6,
  459.       OEM_7, OEM_8, OEM_9, OEM_10, OEM_11, OEM_12, OEM_13, OEM_14, OEM_15,
  460.       OEM_16, OEM_17, OEM_18, OEM_19, OEM_20, OEM_21, OEM_22, OEM_23, OEM_24,
  461.       OEM_25, OEM_26, OEM_27, OEM_28, OEM_29, OEM_102, NUMPAD0, NUMPAD1, NUMPAD2,
  462.       NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, DECIMAL,
  463.       MULTIPLY, ADD, SEPARATOR, SUBTRACT, DIVIDE, SPACE]
  464.     # Create a keyboard layout buffer
  465.     layout_name = '0' * 8
  466.     # Get the keyboard name
  467.     success = @getKeyboardLayoutName.call(layout_name)
  468.     # Set the layout to US 101 if no name was obtained
  469.     layout_name = '00000409' if success == 0
  470.     # Save the keyboard layout
  471.     @layout = @loadKeyboardLayout.call(layout_name, 0x00000001)
  472.     # Create an empty array to store mapped virtual keys
  473.     @mapped_keys = []
  474.     # Iterate through the input character list
  475.     for key in @input_characters
  476.       # Insert the mapped virtual key into the array
  477.       @mapped_keys.push(@mapVirtualKeyEx.call(key, 0, @layout))
  478.     end
  479.     # create blank input array
  480.     @keyboard_state = '0'*256
  481.     # Call current keyboard state
  482.     @getKeyboardState.call(@keyboard_state)
  483.     # Create an array to detect dead keys
  484.     @dead_keys = []
  485.     # Iterate through the input character array
  486.     for key in 0...256
  487.       # Find the key's current scan code
  488.       scan_code = @mapVirtualKeyEx.call(key, 0, @layout)
  489.       # Skip if there is no scan code for the current layout
  490.       next if scan_code == 0
  491.       # Create a character buffer
  492.       buffer = '0' * 10
  493.       # Test the key
  494.       dead_key = @toUnicodeEx.call(key, scan_code, @keyboard_state, buffer, 5, 0,
  495.         @layout)
  496.       # if the key is a dead key
  497.       if dead_key == -1
  498.         # Add the key to the dead key array
  499.         @dead_keys.push(key)
  500.         # Create a character buffer
  501.         buffer = '0' * 10
  502.         # Clear the input queue
  503.         dead_key = @toUnicodeEx.call(@input_characters[-1], @mapped_keys[-1],
  504.           @keyboard_state, buffer, 5, 0, @layout)
  505.       end
  506.    end
  507.    # Set the dead keys to off
  508.    @dead_key_on = false
  509.   end
  510.   #--------------------------------------------------------------------------
  511.   # * Frame Update
  512.   #--------------------------------------------------------------------------
  513.   def self.update
  514.     # Clear input arrays
  515.     @trigger = Array.new(256, false)
  516.     @repeat = Array.new(256, false)
  517.     @release = Array.new(256, false)
  518.     # create blank input array
  519.     @keyboard_state = '0' * 256
  520.     # Call current keyboard state
  521.     @getKeyboardState.call(@keyboard_state)
  522.     # unpack toggle array
  523.     toggle = @keyboard_state.unpack(@toggle_unpack_string)
  524.     # Unpack key array
  525.     array = @keyboard_state.unpack(@unpack_string)
  526.     # Cycle through all keys
  527.     for i in 0...array.size
  528.       # Set the current key state
  529.       @press[i] = (array[i].to_i != 0)
  530.       # Set the current toggle unpack state
  531.       @toggle[i] = (toggle[i].to_i != 0)
  532.       # If the current key state does not match the previous state
  533.       if array[i] != @last_array[i]
  534.         # If the repeat counter is at 0
  535.         if @repeat_counter[i] <= 0 && @press[i]
  536.           # Set the key to repeat
  537.           @repeat[i] = true
  538.           # Set the repeat counter to 15 frames
  539.           @repeat_counter[i] = 15
  540.         end
  541.         # If the key is not being pressed
  542.         if !@press[i]
  543.           # Set the key to released
  544.           @release[i] = true
  545.         # If the key is being pressed
  546.         else
  547.           # Set the key to triggered
  548.           @trigger[i] = true
  549.         end
  550.       # If the key state is the same
  551.       else
  552.         # If the repeat counter is greater than 0 and the key is pressed
  553.         if @repeat_counter[i] > 0 && @press[i]
  554.           # Cycle the repeat counter down one frame
  555.           @repeat_counter[i] -= 1
  556.         # If the repeat counter is 0 or less and the key is pressed
  557.         elsif @repeat_counter[i] <= 0 && @press[i]
  558.           # Set the key to repeat
  559.           @repeat[i] = true
  560.           # Set the repeat counter to 15 frames
  561.           @repeat_counter[i] = 3
  562.         # If the repeat counter does not equal 0
  563.         elsif @repeat_counter[i] != 0 && !@press[i]
  564.           # Set the repeat counter to 0
  565.           @repeat_counter[i] = 0
  566.         end
  567.       end
  568.     end
  569.     # Set the previous keyboard state
  570.     @last_array = array
  571.   end
  572.   #--------------------------------------------------------------------------
  573.   # * Get Key Pressed State
  574.   #     key : key index
  575.   #--------------------------------------------------------------------------
  576.   def self.press?(key)
  577.     # Return the array state if key is an array
  578.     return array_press?(key) if (Array == key.class)
  579.     # Return false if key is invalid
  580.     return false if !validate_key(key)
  581.     # Return for any key
  582.     return @press.include?(true) if key == 0x100
  583.     # Return key pressed state
  584.     return @press[key]
  585.   end
  586.   #--------------------------------------------------------------------------
  587.   # * Get Key Triggered State
  588.   #     key : key index
  589.   #--------------------------------------------------------------------------
  590.   def self.trigger?(key)
  591.     # Return the array state if key is an array
  592.     return array_trigger?(key) if (Array == key.class)
  593.     # Return false if key is invalid
  594.     return false if !validate_key(key)
  595.     # Return for any key
  596.     return @trigger.include?(true) if key == 0x100
  597.     # Return key triggered state
  598.     return @trigger[key]
  599.   end
  600.   #--------------------------------------------------------------------------
  601.   # * Get Key Repeated State
  602.   #     key : key index
  603.   #--------------------------------------------------------------------------
  604.   def self.repeat?(key)
  605.     # Return the array state if key is an array
  606.     return array_repeat?(key) if (Array == key.class)
  607.     # Return false if key is invalid
  608.     return false if !validate_key(key)
  609.     # Return for any key
  610.     return @repeat.include?(true) if key == 0x100
  611.     # Return key repeated state
  612.     return @repeat[key]
  613.   end
  614.   #--------------------------------------------------------------------------
  615.   # * Get Key Released State
  616.   #     key : key index
  617.   #--------------------------------------------------------------------------
  618.   def self.release?(key)
  619.     # Return the array state if key is an array
  620.     return array_release?(key) if (Array == key.class)
  621.     # Return false if key is invalid
  622.     return false if !validate_key(key)
  623.     # Return for any key
  624.     return @release.include?(true) if key == 0x100
  625.     # Return key released state
  626.     return @release[key]
  627.   end
  628.   #--------------------------------------------------------------------------
  629.   # * Get Key Toggled State
  630.   #     key : key index
  631.   #--------------------------------------------------------------------------
  632.   def self.toggle?(key)
  633.     # Return the array state if key is an array
  634.     return array_toggle?(key) if (Array == key.class)
  635.     # Return false if key is invalid
  636.     return false if !validate_key(key)
  637.     # Return for any key
  638.     return @toggle.include?(true) if key == 0x100
  639.     # Return key toggled state
  640.     return @toggle[key]
  641.   end
  642.   #--------------------------------------------------------------------------
  643.   # * Get Key Pressed State (array)
  644.   #     keys : array of key indices
  645.   #--------------------------------------------------------------------------
  646.   def self.array_press?(keys)
  647.     # Return as a key if the input is not an array
  648.     return press?(keys) if (Array != keys.class)
  649.     # Create a temporary array to store key states
  650.     states = [false]
  651.     # Iterate through the keys array
  652.     for key in keys
  653.       # Add the key state to the array
  654.       states << press?(key)
  655.     end
  656.     # Return true if any of the keys were pressed
  657.     return states.include?(true)
  658.   end
  659.   #--------------------------------------------------------------------------
  660.   # * Get Key Triggered State (array)
  661.   #     keys : array of key indices
  662.   #--------------------------------------------------------------------------
  663.   def self.array_trigger?(keys)
  664.     # Return as a key if the input is not an array
  665.     return trigger?(keys.to_i) if (Array != keys.class)
  666.     # Create a temporary array to store key states
  667.     states = [false]
  668.     # Iterate through the keys array
  669.     for key in keys
  670.       # Add the key state to the array
  671.       states << trigger?(key)
  672.     end
  673.     # Return true if any of the keys were pressed
  674.     return states.include?(true)
  675.   end
  676.   #--------------------------------------------------------------------------
  677.   # * Get Key Repeated State (array)
  678.   #     keys : array of key indices
  679.   #--------------------------------------------------------------------------
  680.   def self.array_repeat?(keys)
  681.     # Return as a key if the input is not an array
  682.     return repeat?(keys.to_i) if (Array != keys.class)
  683.     # Create a temporary array to store key states
  684.     states = [false]
  685.     # Iterate through the keys array
  686.     for key in keys
  687.       # Add the key state to the array
  688.       states << repeat?(key)
  689.     end
  690.     # Return true if any of the keys were pressed
  691.     return states.include?(true)
  692.   end
  693.   #--------------------------------------------------------------------------
  694.   # * Get Key Released State (array)
  695.   #     keys : array of key indices
  696.   #--------------------------------------------------------------------------
  697.   def self.array_release?(keys)
  698.     # Return as a key if the input is not an array
  699.     return release?(keys.to_i) if (Array != keys.class)
  700.     # Create a temporary array to store key states
  701.     states = [false]
  702.     # Iterate through the keys array
  703.     for key in keys
  704.       # Add the key state to the array
  705.       states << release?(key)
  706.     end
  707.     # Return true if any of the keys were pressed
  708.     return states.include?(true)
  709.   end
  710.   #--------------------------------------------------------------------------
  711.   # * Get Key Toggled State (array)
  712.   #     keys : array of key indices
  713.   #--------------------------------------------------------------------------
  714.   def self.array_toggle?(keys)
  715.     # Return as a key if the input is not an array
  716.     return toggle?(keys.to_i) if (Array != keys.class)
  717.     # Create a temporary array to store key states
  718.     states = [false]
  719.     # Iterate through the keys array
  720.     for key in keys
  721.       # Add the key state to the array
  722.       states << toggle?(key)
  723.     end
  724.     # Return true if any of the keys were pressed
  725.     return states.include?(true)
  726.   end
  727.   #--------------------------------------------------------------------------
  728.   # * Get Caps Lock State
  729.   #--------------------------------------------------------------------------
  730.   def self.capslock?
  731.     # Return the current toggle state of Caps Lock
  732.     return @toggle[CAPITAL]
  733.   end
  734.   #--------------------------------------------------------------------------
  735.   # * Get Number Lock State
  736.   #--------------------------------------------------------------------------
  737.   def self.numlock?
  738.     # Return the current toggle state of Num Lock
  739.     return @toggle[NUMLOCK]
  740.   end
  741.   #--------------------------------------------------------------------------
  742.   # * Get Scroll Lock State
  743.   #--------------------------------------------------------------------------
  744.   def self.scroll?
  745.     # Return the current toggle state of Scroll Lock
  746.     return @toggle[SCROLL]
  747.   end
  748.   #--------------------------------------------------------------------------
  749.   # * Return Current Key Character Pressed
  750.   #--------------------------------------------------------------------------
  751.   def self.character_press
  752.     # Iterate through the list of input characters
  753.     for i in 0...@input_characters.size
  754.       # Set a temporary variable to the value of the current key
  755.       key = @input_characters[i]
  756.       # Skip if the character is not currently pressed
  757.       next unless self.press?(key)
  758.       # Get the current key's scan code
  759.       scan_code = @mapped_keys[i]
  760.       # Get the specified character
  761.       character = get_character(key, scan_code)
  762.       # Skip if there was no translation for the character
  763.       next if !character || character == -1
  764.       # Return the translated character
  765.       return character
  766.     end
  767.     # Return blank if no characters were returned
  768.     return ""
  769.   end
  770.   #--------------------------------------------------------------------------
  771.   # * Return Current Key Character Triggered
  772.   #--------------------------------------------------------------------------
  773.   def self.character_trigger
  774.     # Iterate through the list of input characters
  775.     for i in 0...@input_characters.size
  776.       # Set a temporary variable to the value of the current key
  777.       key = @input_characters[i]
  778.       # Skip if the character is not currently triggered
  779.       next unless self.trigger?(key)
  780.       # Get the current key's scan code
  781.       scan_code = @mapped_keys[i]
  782.       # Get the specified character
  783.       character = get_character(key, scan_code)
  784.       # Skip if there was no translation for the character
  785.       next if !character || character == -1
  786.       # Return the translated character
  787.       return character
  788.     end
  789.     # Return blank if no characters were returned
  790.     return ""
  791.   end
  792.   #--------------------------------------------------------------------------
  793.   # * Return Current Key Character Repeated
  794.   #--------------------------------------------------------------------------
  795.   def self.character_repeat
  796.     # Iterate through the list of input characters
  797.     for i in 0...@input_characters.size
  798.       # Set a temporary variable to the value of the current key
  799.       key = @input_characters[i]
  800.       # Skip if the character is not currently repeated
  801.       next unless self.repeat?(key)
  802.       # Get the current key's scan code
  803.       scan_code = @mapped_keys[i]
  804.       # Get the specified character
  805.       character = get_character(key, scan_code)
  806.       # Skip if there was no translation for the character
  807.       next if !character || character == -1
  808.       # Return the translated character
  809.       return character
  810.     end
  811.     # Return blank if no characters were returned
  812.     return ""
  813.   end
  814.   #--------------------------------------------------------------------------
  815.   # * Get Character from Key
  816.   #--------------------------------------------------------------------------
  817.   def self.get_character(key, scan_code)
  818.     # Create a character buffer
  819.     buffer = '0' * 10
  820.     # Translate the current key to Unicode
  821.     success = @toUnicodeEx.call(key, scan_code, @keyboard_state, buffer, 5, 0,
  822.       @layout)
  823.     # Return false there was no translation for the character
  824.     return false if success == 0
  825.     # Iterate through the dead keys
  826.     for dead_key in @dead_keys
  827.       # If the dead key was pressed
  828.       if @getAsyncKeyState.call(dead_key) != 0
  829.         # Map the dead key scan code
  830.         dead_scan =  @mapVirtualKeyEx.call(dead_key, 0, @layout)
  831.         # Recreate a character buffer
  832.         buffer = '0' * 10
  833.         # Translate the current key to Unicode
  834.         success = @toUnicodeEx.call(dead_key, dead_scan, @keyboard_state,
  835.           buffer, 5, 0, @layout)
  836.         # If it returns as a dead key
  837.         if success == -1
  838.           # Recreate a character buffer
  839.           buffer = '0' * 10
  840.           # Translate the current key to Unicode
  841.           success = @toUnicodeEx.call(key, scan_code, @keyboard_state, buffer,
  842.           5, 0, @layout)
  843.         end
  844.         # Return false there was no translation for the character
  845.         return false if success == 0
  846.       end
  847.     end
  848.     # Translate the characters to Ruby encoding
  849.     characters = buffer.unpack('C*').pack('U*')
  850.     # Create the return character
  851.     array = []
  852.     # Iterate through the character buffer
  853.     for i in 0...(success * 2)
  854.       # Add characters to the character array
  855.       array.push(characters[i]) unless array.include?(characters[i])
  856.     end
  857.     # If a dead key was pressed
  858.     if success == -1
  859.       # Iterate through the character buffer
  860.       for i in 0...2
  861.         # Add characters to the character array
  862.         array.push(characters[i]) unless array.include?(characters[i])
  863.       end
  864.     end
  865.     # Delete null characters
  866.     array.delete_if {|byte| byte == 0}
  867.     # Create an empty string for the return character
  868.     character = ' ' * array.size
  869.     # Iterate through the character array
  870.     for i in 0...array.size
  871.       # Add the character to the string
  872.       character[i] = array[i]
  873.     end
  874.     # Return the translated character
  875.     return character
  876.   end
  877.   #--------------------------------------------------------------------------
  878.   # * Validate Key
  879.   #--------------------------------------------------------------------------
  880.   def self.validate_key(key)
  881.     # Return false if key is not a number
  882.     return false if !(key.is_a?(Numeric))
  883.     # Force key into the integer class
  884.     key = key.to_i
  885.     # Return false if the key does not exist or is not an integer
  886.     return false if ((key < 0x01) || (key > 0x100) || !(key == key.to_i))
  887.     # Return that the key is valid
  888.     return true
  889.   end
  890. end

  891. #==============================================================================
  892. # ** Input
  893. #------------------------------------------------------------------------------
  894. #  This module performs key input processing
  895. #==============================================================================

  896. module Input
  897.   # Add class data
  898.   class << self
  899.     #------------------------------------------------------------------------
  900.     # * Alias Methods
  901.     #------------------------------------------------------------------------
  902.     # If the update method has not been aliased
  903.     unless method_defined?(:keyinputmodule_input_update)
  904.       # Alias the update method
  905.       alias keyinputmodule_input_update update
  906.     end
  907.     #-------------------------------------------------------------------------
  908.     # * Frame Update
  909.     #-------------------------------------------------------------------------
  910.     def update
  911.       # Call original method
  912.       keyinputmodule_input_update
  913.       # Update Keys module
  914.       Keys.update
  915.     end
  916.   end
  917. end
复制代码

评分

参与人数 1星屑 +15 收起 理由
怪蜀黍 + 15 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
6 小时
注册时间
2017-2-3
帖子
13
3
 楼主| 发表于 2017-2-7 11:52:13 | 只看该作者
在脚本里新创一个变量吗
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
6 小时
注册时间
2017-2-3
帖子
13
4
 楼主| 发表于 2017-2-7 11:52:45 | 只看该作者
鑫晴 发表于 2017-2-7 01:11
Key Input Module
Author: Glitchfinder
Version: 1.30

在脚本里新创一个变量吗?
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

梦石
1
星屑
6651
在线时间
2650 小时
注册时间
2013-8-23
帖子
2315

开拓者

5
发表于 2017-2-7 13:52:48 | 只看该作者
shihaoyun 发表于 2017-2-7 11:52
在脚本里新创一个变量吗?

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
6 小时
注册时间
2017-2-3
帖子
13
6
 楼主| 发表于 2017-2-7 18:12:02 | 只看该作者
# 想设置一个按下v触发。
Keys.press?(Keys::V)
上面那个怎么办。
需要把那些比较多代码的那个的注释要删吗
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
6 小时
注册时间
2017-2-3
帖子
13
7
 楼主| 发表于 2017-2-7 18:42:49 | 只看该作者
显示:执行脚本发现名字错误

QQ图片20170207183609.png (59.88 KB, 下载次数: 19)

QQ图片20170207183609.png
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-21 22:32

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表