Mouse Input Module 3.00 [XP/VX/VXA]

Mouse Input Module
Author: Glitchfinder
Version: 3.00





Index





Introduction

    Glitchfinder's Mouse Input Module is an advanced scripting tool that provides full scripted access to to check various attributes of the mouse, from location to the key status. It is useful in the sense that it will not break the default Input module, and because it allows you to use the mouse, which you cannot do with default RMXP. It is more accurate than AWorks, which has several logical errors in its mouse related programming. It also does not need to be updated, aside from the default call to Input.update that is used in most cases. Finally, it does not break default scripts or events that use key input.

(Return to top)



Features

  • Check the mouse location
  • Check the mouse buttons
  • Can check more than one button at a time
  • Allows you to check to see if a button has been released
  • Includes double clicking support
  • Includes dragging support
  • Allows you to hide the mouse
  • Allows you to move the mouse
  • Doesn't break the default Input module
  • Does not break events or scripts that call the default Input module
  • Automatically updated by the required Key Input Module
  • Doesn't use a .dll file
  • Doesn't crash on F12
  • Has the unique Anykey and Anybutton functions (not found in any other script)
  • Can check a key's toggle state. (Not found in any other script)

(Return to top)



Screenshots

    Since this script has no visual elements, a screenshot cannot be taken.

(Return to top)



Script

    1. #==============================================================================
    2. # ** Glitchfinder's Mouse Input Module
    3. #    Version 3.00
    4. #------------------------------------------------------------------------------
    5. #  [RPG Maker XP] [RPG Maker VX] [RPG Maker VX Ace]
    6. #------------------------------------------------------------------------------
    7. #  This script helps scripters to use the mouse, without being limited by the
    8. #  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-06-02)
    16. #      - Methods renamed for efficiency
    17. #      - Modified to be updated by the Key module instead of the Input module
    18. #      - Author: Glitchfinder
    19. #   Version 2.10 ------------------------------------------------- (2011-03-17)
    20. #     - Added the Mouse.toggle?() method
    21. #     - Added the Mouse.array_press? method
    22. #     - Added the Mouse.array_trigger? method
    23. #     - Added the Mouse.array_repeat? method
    24. #     - Added the Mouse.array_release? method
    25. #     - Added the Mouse.array_toggle? method
    26. #     - Added the Mouse.real_pos() method
    27. #     - Added the Mouse.relative_pos() method
    28. #     - Added the Mouse.tile_pos() method
    29. #     - Added the Mouse.real_x() method
    30. #     - Added the Mouse.real_y() method
    31. #     - Added the Mouse.relative_x() method
    32. #     - Added the Mouse.relative_y() method
    33. #     - Added the Mouse.tile_x() method
    34. #     - Added the Mouse.tile_y() method
    35. #     - Added the Mouse.hide_cursor() method
    36. #     - Added the Mouse.show_cursor() method
    37. #     - Added the ANYKEY constant
    38. #     - Added the ANYBUTTON constant
    39. #     - Corrected calculations for x() method
    40. #     - Corrected calculations for y() method
    41. #     - Author: Glitchfinder
    42. #   Version 3.00 ------------------------------------------------- (2014-03-02)
    43. #     - Added the Mouse.double_click?() method
    44. #     - Added the Mouse.last_click_x() method
    45. #     - Added the Mouse.last_click_y() method
    46. #     - Added the Mouse.set_x() method
    47. #     - Added the Mouse.set_y() method
    48. #     - Added the Mouse.set_real_x() method
    49. #     - Added the Mouse.set_real_y() method
    50. #     - Added the Mouse.set_relative_x() method
    51. #     - Added the Mouse.set_relative_y() method
    52. #     - Added the Mouse.set_pos() method
    53. #     - Added the Mouse.set_real_pos() method
    54. #     - Added the Mouse.set_relative_pos() method
    55. #     - Added the Mouse.x_to_real() method
    56. #     - Added the Mouse.y_to_real() method
    57. #     - Added the Mouse.x_to_relative() method
    58. #     - Added the Mouse.y_to_relative() method
    59. #     - Added the Mouse.real_x_to_x() method
    60. #     - Added the Mouse.real_y_to_y() method
    61. #     - Added the Mouse.real_x_to_relative() method
    62. #     - Added the Mouse.real_y_to_relative() method
    63. #     - Added the Mouse.relative_x_to_x() method
    64. #     - Added the Mouse.relative_y_to_y() method
    65. #     - Added the Mouse.relative_x_to_real() method
    66. #     - Added the Mouse.relative_y_to_real() method
    67. #     - Updated the Mouse.dragging?() method
    68. #     - Updated the Mouse.drag_rect() method
    69. #     - Updated the Mouse.drag_coor() method
    70. #     - Fixed the Mouse.hide_cursor() method
    71. #     - Fixed the Mouse.show_cursor() method
    72. #     - Fixed the Mouse.in_screen() method
    73. #     - Fixed the calculations for screen location
    74. #     - Improved the Mouse.update() method
    75. #     - Author: Glitchfinder
    76. #==============================================================================
    77. # * Instructions
    78. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    79. #  Place this script above Main, and below the default scripts. This script
    80. #  must also be placed below Glitchfinder's Key Input Module.
    81. #
    82. #  This script requires Glitchfinder's Key Input Module. This can be found in
    83. #  a forum post at viewtopic.php?p=742465
    84. #
    85. #  This module is automatically updated by the required Keys module, which
    86. #  means that the only time you need to call the update method is in a scene
    87. #  that does not update the default Input module.
    88. #
    89. #  This module does not break the functionality of the default Input module.
    90. #
    91. #  To use this module, simply use one of the four methods (press?(key),
    92. #  trigger?(key), repeat?(key), or release?(key)), where key is the index of
    93. #  the key you want to check. Key may also be used as Mouse::KEYNAME. For a
    94. #  list of acceptable key names, look below the header.
    95. #
    96. #  There is a key named ANYKEY. This can be used like any other key, with the
    97. #  exception that, instead of corresponding to any one key, it reacts to them
    98. #  all. If you use it, and any other key would cause the same method to return
    99. #  true, then the ANYKEY will also return true. This takes into account all
    100. #  keys on the keyboard, as well.
    101. #
    102. #  There is a key named ANYBUTTON. This can be used like any other key, with
    103. #  the exception that, instead of corresponding to any one key, it reacts to
    104. #  them all. If you use it, and any other key would cause the same method to
    105. #  return true, then the ANYBUTTON will also return true. This only takes into
    106. #  account keys on the mouse.
    107. #
    108. #  This script has several additional methods, details of which are in the
    109. #  method list below.
    110. #==============================================================================
    111. # * Method List
    112. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    113. #  Mouse.update
    114. #    Updates mouse input. Calls to this method are not necessary unless the
    115. #    default Input module is not being updated.
    116. #
    117. #  Mouse.press?(key)
    118. #    Determines whether the button determined by key is currently being
    119. #    pressed. If the button is being pressed, returns true. If not, returns
    120. #    false.
    121. #
    122. #  Mouse.trigger?(key)
    123. #    Determines whether the button determined by key is being pressed again.
    124. #    "Pressed again" is seen as time having passed between the button being not
    125. #    pressed and being pressed. If the button is being pressed, returns true.
    126. #    If not, returns false.
    127. #
    128. #  Mouse.repeat?(key)
    129. #    Determines whether the button determined by key is being pressed again.
    130. #    Unlike trigger?(), this takes into account the repeat input of a button
    131. #    being held down continuously. If the button is being pressed, returns
    132. #    true. If not, returns false.
    133. #
    134. #  Mouse.release?(key)
    135. #    Determines whether the button determined by key has just been released. If
    136. #    the button has been released, returns true. If not, returns false.
    137. #
    138. #  Mouse.toggle?(key)
    139. #    Determines whether the button determined by key has been toggled. This
    140. #    functions like Caps Lock, Number Lock, and Scroll Lock, only for all keys.
    141. #
    142. #  Mouse.array_press?(keys)
    143. #    Functions in the same manner as Mouse.press?(), only it takes an array of
    144. #    keys as input.
    145. #
    146. #  Mouse.array_trigger?(keys)
    147. #    Functions in the same manner as Mouse.trigger?(), only it takes an array
    148. #    of keys as input.
    149. #
    150. #  Mouse.array_repeat?(keys)
    151. #    Functions in the same manner as Mouse.repeat?(), only it takes an array of
    152. #    keys as input.
    153. #
    154. #  Mouse.array_release?(keys)
    155. #    Functions in the same manner as Mouse.release?(), only it takes an array
    156. #    of keys as input.
    157. #
    158. #  Mouse.array_toggle?(keys)
    159. #    Functions in the same manner as Mouse.toggle?(), only it takes an array of
    160. #    keys as input.
    161. #
    162. #  Mouse.in_screen?
    163. #    This method returns true if the mouse is over the game window, and false if
    164. #    not. (The function returns false if the mouse is currently over the window
    165. #    title or edge, instead of the client area)
    166. #
    167. #  Mouse.pos
    168. #    This method returns an array containing the current mouse position, in the
    169. #    following format: [x, y]
    170. #
    171. #  Mouse.real_pos
    172. #    This method returns an array containing the current mouse position, in the
    173. #    following format: [x, y] The position returned by this method is the exact
    174. #    position of the mouse on the monitor.
    175. #
    176. #  Mouse.relative_pos
    177. #    This method returns an array containing the current mouse position, in the
    178. #    following format: [x, y] The position returned by this method is similar to
    179. #    the position returned by Mouse.pos, only it will return offscreen
    180. #    coordinates as well.
    181. #
    182. #  Mouse.tile_pos
    183. #    This method returns an array containing the current mouse position, in the
    184. #    following format: [x, y] The position returned by this method will be the
    185. #    position of the map tile the mouse is currently hovering over.
    186. #
    187. #  Mouse.x
    188. #    Returns the current mouse x position. If the mouse is to the left of the
    189. #    game screen, returns 0. If the mouse is to the right of the game window,
    190. #    returns the width of the window minus one.
    191. #
    192. #  Mouse.y
    193. #    Returns the current mouse y position. If the mouse is above the game
    194. #    screen, returns 0. If the mouse is below the game window, returns the
    195. #    height of the window minus one.
    196. #
    197. #  Mouse.real_x
    198. #    Returns the current x position of the mouse on the monitor.
    199. #
    200. #  Mouse.real_y
    201. #    Returns the current y position of the mouse on the monitor.
    202. #
    203. #  Mouse.relative_x
    204. #    Returns the current mouse x position. If the mouse is to the left of the
    205. #    game screen, returns negative values. If the mouse is to the right of the
    206. #    game window, returns values higher than the width of the game window.
    207. #
    208. #  Mouse.relative_y
    209. #    Returns the current mouse y position. If the mouse is above the game
    210. #    screen, returns negative values. If the mouse is below the game window,
    211. #    returns values higher than the height of the game window.
    212. #
    213. #  Mouse.tile_x
    214. #    Returns the x position of the map tile the mouse is currently hovering
    215. #    over. If the mouse is to the left of the game screen, returns 0. If the
    216. #    mouse is to the right of the game window, returns the x position of the
    217. #    tiles on the right edge of the screen.
    218. #
    219. #  Mouse.tile_y
    220. #    Returns the y position of the map tile the mouse is currently hovering
    221. #    over. If the mouse is above the game screen, returns 0. If the mouse is
    222. #    below the game window, returns the y position of the tiles on the bottom
    223. #    edge of the screen.
    224. #
    225. #  Mouse.dragging?
    226. #  Mouse.dragging?(button)
    227. #    Checks to see if the mouse is currently dragging. (The primary button is
    228. #    being held while the mouse moves across the screen) Returns true if the
    229. #    mouse is dragging, false if the mouse is not. If an argument is supplied,
    230. #    this will check the dragging status of the button in question. Otherwise,
    231. #    the check will supply the status of the primary mouse key.
    232. #
    233. #  Mouse.drag_rect
    234. #  Mouse.drag_rect(button)
    235. #    Checks to see if the mouse is dragging, and returns the rect of the drag
    236. #    area. If the mouse is not currently dragging, returns an empty rect. If
    237. #    the mouse is dragging, returns a screen rect that covers the current drag
    238. #    area. If an argument is supplied, this will check the dragging status of
    239. #    the button in question. Otherwise, the check will supply the status of the
    240. #    primary mouse key.
    241. #
    242. #  Mouse.drag_coor
    243. #  Mouse.drag_coor(button)
    244. #    Checks to see if the mouse is dragging, and returns the starting
    245. #    coordinates. If the mouse is not dragging, returns the current mouse
    246. #    position.  If an argument is supplied, this will check the dragging status
    247. #    of the button in question. Otherwise, the check will supply the status of
    248. #    the primary mouse key.The return data is in the following format: [x, y]
    249. #
    250. #  Mouse.in_area?(Rect)
    251. #  Mouse.in_area?(x, y, width, height)
    252. #    Determines if the mouse is within the specified area. You can input either
    253. #    a rect or the x, y, width, and height of the area. If the mouse is
    254. #    currently within that area, returns true. Otherwise, returns false.
    255. #
    256. #  Mouse.hide_cursor
    257. #  Mouse.hide_cursor(reset_state)
    258. #    Hides the mouse cursor while it is over the game screen. No arguments are
    259. #    needed. If reset_state is false, the mouse state will not be changed and
    260. #    it will remain visible. Reset_state is set to true by default.
    261. #
    262. #  Mouse.show_cursor
    263. #  Mouse.show_cursor(reset_state)
    264. #  Mouse.show_cursor(cursor_name)
    265. #  Mouse.show_cursor(reset_state, cursor_name)
    266. #  Mouse.show_cursor(cursor_name, reset_state)
    267. #    Shows the mouse cursor. No arguments are needed. If reset_state is false,
    268. #    the mouse state will not be changed and it will remain invisible.
    269. #    Reset_state is set to true by default. The cursor_name argument is the
    270. #    location of a bitmap to use as the cursor image. This defaults to
    271. #    "Graphics/Pictures/GF001-Cursor01" for the file location.
    272. #
    273. #  Mouse.double_click?(button)
    274. #    Returns true if the specified button is pressed twice within a short time.
    275. #
    276. #  Mouse.last_click_x(button)
    277. #  Mouse.last_click_y(button)
    278. #    Returns the coordinate of the last location at which the supplied mouse
    279. #    button was pressed.
    280. #
    281. #  Mouse.set_x(coordinate)
    282. #  Mouse.set_y(coordinate)
    283. #  Mouse.set_real_x(coordinate)
    284. #  Mouse.set_real_y(coordinate)
    285. #  Mouse.set_relative_x(coordinate)
    286. #  Mouse.set_relative_y(coordinate)
    287. #  Mouse.set_pos(x, y)
    288. #  Mouse.set_real_pos(x, y)
    289. #  Mouse.set_relative_pos(x, y)
    290. #    Sets the mouse location. These functions follow the same coordinate rules
    291. #    as the equivalent checks listed above.
    292. #
    293. #  Mouse.x_to_real(coordinate)
    294. #  Mouse.y_to_real(coordinate)
    295. #  Mouse.x_to_relative(coordinate)
    296. #  Mouse.y_to_relative(coordinate)
    297. #  Mouse.real_x_to_x(coordinate)
    298. #  Mouse.real_y_to_y(coordinate)
    299. #  Mouse.real_x_to_relative(coordinate)
    300. #  Mouse.real_y_to_relative(coordinate)
    301. #  Mouse.relative_x_to_x(coordinate)
    302. #  Mouse.relative_y_to_y(coordinate)
    303. #  Mouse.relative_x_to_real(coordinate)
    304. #  Mouse.relative_y_to_real(coordinate)
    305. #    Converts a coordinate from one system to another. These follow the same
    306. #    rules as the equivalent functions listed above.
    307. #==============================================================================
    308. # *Glitchfinder's Advice
    309. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    310. #  This script is meant for people with a medium or advanced level of scripting
    311. #  knowledge and ability, or for those using scripts that require this module.
    312. #==============================================================================
    313. # * License
    314. #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    315. #  This script is licensed under the MIT License:
    316. #
    317. #  Copyright (c) 2010-2014 Sean Porter (Glitchfinder) <[email hidden]>
    318. #
    319. #  Permission is hereby granted, free of charge, to any person obtaining a copy
    320. #  of this software and associated documentation files (the "Software"), to deal
    321. #  in the Software without restriction, including without limitation the rights
    322. #  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    323. #  copies of the Software, and to permit persons to whom the Software is
    324. #  furnished to do so, subject to the following conditions:
    325. #
    326. #  The above copyright notice and this permission notice shall be included in
    327. #  all copies or substantial portions of the Software.
    328. #
    329. #  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    330. #  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    331. #  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    332. #  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    333. #  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    334. #  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    335. #  THE SOFTWARE.
    336. #==============================================================================
    337.  
    338. #==============================================================================
    339. # ** Mouse
    340. #------------------------------------------------------------------------------
    341. #  This module performs mouse input processing
    342. #==============================================================================
    343.  
    344. module Mouse
    345.   #--------------------------------------------------------------------------
    346.   # * Declare Module Variables
    347.   #--------------------------------------------------------------------------
    348.   # Declare API calls
    349.   @metrics       = Win32API.new('user32', 'GetSystemMetrics', 'i' , 'i')
    350.   @getCursorPos  = Win32API.new('user32', 'GetCursorPos'    , 'p' , 'v')
    351.   @getWindowRect = Win32API.new('user32', 'GetWindowRect'   , 'lp', 'v')
    352.   @showCursor    = Win32API.new('user32', 'ShowCursor'      , 'i' , 'i')
    353.   @setCursorPos  = Win32API.new('user32', 'SetCursorPos'    , 'ii', 'i')
    354.   # Get window thread
    355.   findWindowEx = Win32API.new('user32', 'FindWindowEx', 'llpp', 'i')
    356.   @window      = findWindowEx.call(0, 0, "RGSS Player", 0)
    357.   # Set up double click
    358.   @double_click         = Array.new(7, false)
    359.   @double_click_counter = Array.new(7, 0)
    360.   @double_click_frames  = 20
    361.   @double_click_pixels  = 4
    362.   # Set up drag
    363.   @mouse_drag  = Array.new(7) {Array.new([false, 0, 0, 0, 0])}
    364.   @drag_pixels = 4
    365.   # Set up last click
    366.   @last_click_x = Array.new(7, 0)
    367.   @last_click_y = Array.new(7, 0)
    368.   # Set mouse to visible
    369.   @hidden           = false
    370.   @visible_override = false
    371.   @cursor           = nil
    372.   #--------------------------------------------------------------------------
    373.   # * Mouse Keys
    374.   #--------------------------------------------------------------------------
    375.   SWAPBUTTON = @metrics.call(23) == 0 ? false : true # Buttons Swapped
    376.   LBUTTON    = 0x01 # Physical Left Button
    377.   RBUTTON    = 0x02 # Physical Right Button
    378.   MBUTTON    = 0x04 # Middle Mouse Button
    379.   XBUTTON1   = 0x05 # X1 Mouse Button
    380.   XBUTTON2   = 0x06 # X2 Mouse Button
    381.   PRIMARY    = !SWAPBUTTON ? 0x01 : 0x02 # Primary Mouse Button
    382.   SECONDARY  = !SWAPBUTTON ? 0x02 : 0x01 # Secondary Mouse Button
    383.   #--------------------------------------------------------------------------
    384.   # * Special Keys
    385.   #--------------------------------------------------------------------------
    386.   ANYKEY     = 0x100 # Any Key
    387.   ANYBUTTON  = [0x01, 0x02, 0x04, 0x05, 0x06]
    388.   #--------------------------------------------------------------------------
    389.   # * Frame Update
    390.   #--------------------------------------------------------------------------
    391.   def self.update
    392.     # create blank rect
    393.     rect = '0' * 16
    394.     # Get window rect
    395.     @getWindowRect.call(@window, rect)
    396.     # Unpack rect data
    397.     left, top, right, bottom = rect.unpack("LLLL")
    398.     # Get window coordinates
    399.     @window_x = left
    400.     @window_y = top
    401.     # Get window dimensions
    402.     @window_width  = right  - left
    403.     @window_height = bottom - top
    404.     # If the game is not fullscreen
    405.     if @window_width < @metrics.call(16) && @window_height < @metrics.call(17)
    406.       # Adjust window coordinates
    407.       @window_x += @metrics.call(5) + @metrics.call(45)
    408.       @window_y += @metrics.call(6) + @metrics.call(46) + @metrics.call(4)
    409.       # Adjust window width
    410.       @window_width  -= (@metrics.call(5) + @metrics.call(45)) * 2
    411.       # Adjust window height
    412.       @window_height -= (@metrics.call(6) + @metrics.call(46)) * 2
    413.       @window_height -= @metrics.call(4)
    414.     end
    415.     # Set blank cursor position
    416.     cursor_position = '0' * 8
    417.     # Get cursor position
    418.     @getCursorPos.call(cursor_position)
    419.     # Unpack cursor position data
    420.     @real_x, @real_y = cursor_position.unpack('LL')
    421.     # Set cursor position relative to the window
    422.     @mouse_x = [[@real_x - @window_x, 0].max, (@window_width  - 1)].min
    423.     @mouse_y = [[@real_y - @window_y, 0].max, (@window_height - 1)].min
    424.     # If the cursor is not over the window
    425.     if (@mouse_x != (@real_x - @window_x) || @mouse_y != (@real_y - @window_y))
    426.       # Set the mouse to off screen
    427.       @in_screen = false
    428.     # If the cursor is over the window
    429.     else
    430.       # Set the mouse to on screen
    431.       @in_screen = true
    432.     end
    433.     # Clear double click flags
    434.     @double_click = Array.new(6, false)
    435.     # Iterate the mouse buttons
    436.     for i in ANYBUTTON
    437.       # Set up mouse deviance
    438.       x_deviance = (@last_click_x[i] - @mouse_x).abs
    439.       y_deviance = (@last_click_y[i] - @mouse_y).abs
    440.       # Correct mouse deviance
    441.       x_deviance *= -1 if x_deviance < 0
    442.       y_deviance *= -1 if y_deviance < 0
    443.       # If the button is triggered
    444.       if Keys.trigger?(i)
    445.         # Set allowed deviance
    446.         deviance = @double_click_pixels
    447.         # Get the double click counter
    448.         counter = @double_click_counter[i]
    449.         # If double click counter is active and deviance is within allowed range
    450.         if (counter > 0 && x_deviance <= deviance && y_deviance <= deviance)
    451.           # Set double click flag to true
    452.           @double_click[i] = true
    453.         # If double click counter is not running or the cursor is out of bounds
    454.         else
    455.           # Reset double click counter
    456.           @double_click_counter[i] = @double_click_frames
    457.         end
    458.         # Set drag start coordinates
    459.         @mouse_drag[i][1] = @mouse_x
    460.         @mouse_drag[i][2] = @mouse_y
    461.         # Set last click coordinates
    462.         @last_click_x[i]  = @mouse_x
    463.         @last_click_y[i]  = @mouse_y
    464.       # If the button is pressed
    465.       elsif Keys.press?(i)
    466.         # If the mouse has moved beyond the required deviance
    467.         if x_deviance >= @drag_pixels && y_deviance >= @drag_pixels
    468.           # Set the mouse to dragging
    469.           @mouse_drag[i][0] = true
    470.         end
    471.         # If the mouse is dragging
    472.         if @mouse_drag[i][0] == true
    473.           # Set current dragging corrdinates
    474.           @mouse_drag[i][3] = @mouse_x
    475.           @mouse_drag[i][4] = @mouse_y
    476.         end
    477.       # If the button is released
    478.       else
    479.         # Reset drag data
    480.         @mouse_drag[i][0] = false
    481.         @mouse_drag[i][1] = 0
    482.         @mouse_drag[i][2] = 0
    483.         @mouse_drag[i][3] = 0
    484.         @mouse_drag[i][4] = 0
    485.       end
    486.       # If the double click counter is running
    487.       if @double_click_counter[i] > 0
    488.         # Cycle the double click counter down one frame
    489.         @double_click_counter[i] -= 1
    490.       end
    491.     end
    492.     # If the cursor is in the screen and it is set to hidden
    493.     if @in_screen && @hidden
    494.       # Hide the mouse cursor
    495.       hide_cursor(false)
    496.     # If the cursor is not set to hidden or is not on screen
    497.     else
    498.       # Set the mouse to visible
    499.       show_cursor(false)
    500.     end
    501.   end
    502.   #--------------------------------------------------------------------------
    503.   # * Get Key Pressed State
    504.   #     key : key index
    505.   #--------------------------------------------------------------------------
    506.   def self.press?(key)
    507.     # Return key pressed state
    508.     return Keys.press?(key)
    509.   end
    510.   #--------------------------------------------------------------------------
    511.   # * Get Key Triggered State
    512.   #     key : key index
    513.   #--------------------------------------------------------------------------
    514.   def self.trigger?(key)
    515.     # Return key triggered state
    516.     return Keys.trigger?(key)
    517.   end
    518.   #--------------------------------------------------------------------------
    519.   # * Get Key Repeated State
    520.   #     key : key index
    521.   #--------------------------------------------------------------------------
    522.   def self.repeat?(key)
    523.     # Return key repeated state
    524.     return Keys.repeat?(key)
    525.   end
    526.   #--------------------------------------------------------------------------
    527.   # * Get Key Released State
    528.   #     key : key index
    529.   #--------------------------------------------------------------------------
    530.   def self.release?(key)
    531.     # Return key released state
    532.     return Keys.release?(key)
    533.   end
    534.   #--------------------------------------------------------------------------
    535.   # * Get Key Toggled State
    536.   #     key : key index
    537.   #--------------------------------------------------------------------------
    538.   def self.toggle?(key)
    539.     # Return key toggled state
    540.     return Keys.toggle?(key)
    541.   end
    542.   #--------------------------------------------------------------------------
    543.   # * Get Key Pressed State (array)
    544.   #     keys : array of key indices
    545.   #--------------------------------------------------------------------------
    546.   def self.array_press?(keys)
    547.     # Return key pressed state
    548.     return Keys.array_press?(keys)
    549.   end
    550.   #--------------------------------------------------------------------------
    551.   # * Get Key Triggered State (array)
    552.   #     keys : array of key indices
    553.   #--------------------------------------------------------------------------
    554.   def self.array_trigger?(keys)
    555.     # Return key triggered state
    556.     return Keys.array_trigger?(keys)
    557.   end
    558.   #--------------------------------------------------------------------------
    559.   # * Get Key Repeated State (array)
    560.   #     keys : array of key indices
    561.   #--------------------------------------------------------------------------
    562.   def self.array_repeat?(keys)
    563.     # Return key repeated state
    564.     return Keys.array_repeat?(keys)
    565.   end
    566.   #--------------------------------------------------------------------------
    567.   # * Get Key Released State (array)
    568.   #     keys : array of key indices
    569.   #--------------------------------------------------------------------------
    570.   def self.array_release?(keys)
    571.     # Return key released state
    572.     return Keys.array_release?(keys)
    573.   end
    574.   #--------------------------------------------------------------------------
    575.   # * Get Key Toggled State (array)
    576.   #     keys : array of key indices
    577.   #--------------------------------------------------------------------------
    578.   def self.array_toggle?(keys)
    579.     # Return key toggled state
    580.     return Keys.array_toggle?(keys)
    581.   end
    582.   #--------------------------------------------------------------------------
    583.   # * Is the Mouse on Screen?
    584.   #--------------------------------------------------------------------------
    585.   def self.in_screen?
    586.     # Return mouse in screen flag
    587.     return @in_screen
    588.   end
    589.   #--------------------------------------------------------------------------
    590.   # * Get Mouse Position
    591.   #--------------------------------------------------------------------------
    592.   def self.pos
    593.     # Return mouse position array
    594.     return [@mouse_x, @mouse_y]
    595.   end
    596.   #--------------------------------------------------------------------------
    597.   # * Get Real Mouse Position
    598.   #--------------------------------------------------------------------------
    599.   def self.real_pos
    600.     # Return real mouse position array
    601.     return [@real_x, @real_y]
    602.   end
    603.   #--------------------------------------------------------------------------
    604.   # * Get Relative Mouse Position
    605.   #--------------------------------------------------------------------------
    606.   def self.relative_pos
    607.     # Return relative mouse position array
    608.     return [relative_x, relative_y]
    609.   end
    610.   #--------------------------------------------------------------------------
    611.   # * Get Mouse Tile Position
    612.   #--------------------------------------------------------------------------
    613.   def self.tile_pos
    614.     # Return mouse tile position array
    615.     return [tile_x, tile_y]
    616.   end
    617.   #--------------------------------------------------------------------------
    618.   # * Get Mouse X Position
    619.   #--------------------------------------------------------------------------
    620.   def self.x
    621.     # Return mouse x position
    622.     return @mouse_x
    623.   end
    624.   #--------------------------------------------------------------------------
    625.   # * Get Mouse Y Position
    626.   #--------------------------------------------------------------------------
    627.   def self.y
    628.     # Return mouse y position
    629.     return @mouse_y
    630.   end
    631.   #--------------------------------------------------------------------------
    632.   # * Get Real Mouse X Position
    633.   #--------------------------------------------------------------------------
    634.   def self.real_x
    635.     # Return real mouse x position
    636.     return @real_x
    637.   end
    638.   #--------------------------------------------------------------------------
    639.   # * Get Real Mouse Y Position
    640.   #--------------------------------------------------------------------------
    641.   def self.real_y
    642.     # Return real mouse y position
    643.     return @real_y
    644.   end
    645.   #--------------------------------------------------------------------------
    646.   # * Get Relative Mouse X Position
    647.   #--------------------------------------------------------------------------
    648.   def self.relative_x
    649.     # Return mouse x position
    650.     return (@real_x - @window_x)
    651.   end
    652.   #--------------------------------------------------------------------------
    653.   # * Get Relative Mouse Y Position
    654.   #--------------------------------------------------------------------------
    655.   def self.relative_y
    656.     # Return mouse y position
    657.     return (@real_y - @window_y)
    658.   end
    659.   #--------------------------------------------------------------------------
    660.   # * Get Mouse Tile X Position
    661.   #--------------------------------------------------------------------------
    662.   def self.tile_x
    663.     # Return mouse x tile position
    664.     return (@mouse_x / 32).to_i
    665.   end
    666.   #--------------------------------------------------------------------------
    667.   # * Get Mouse Tile Y Position
    668.   #--------------------------------------------------------------------------
    669.   def self.tile_y
    670.     # Return mouse y tile position
    671.     return (@mouse_y / 32).to_i
    672.   end
    673.   #--------------------------------------------------------------------------
    674.   # * Get Mouse Dragging Boolean
    675.   #     args : the mouse button to check
    676.   #--------------------------------------------------------------------------
    677.   def self.dragging?(*args)
    678.     # Get the button
    679.     if args.is_a?(NilClass) || args[0].is_a?(NilClass)
    680.       button = PRIMARY
    681.     else
    682.       button = args[0]
    683.     end
    684.     # Validate button
    685.     return false if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
    686.     # Return mouse dragging flag
    687.     return @mouse_drag[button][0]
    688.   end
    689.   #--------------------------------------------------------------------------
    690.   # * Get Mouse Drag Rect
    691.   #     args : the mouse button to check
    692.   #--------------------------------------------------------------------------
    693.   def self.drag_rect(*args)
    694.     # Get the button
    695.     if args.is_a?(NilClass) || args[0].is_a?(NilClass)
    696.       button = PRIMARY
    697.     else
    698.       button = args[0]
    699.     end
    700.     # Validate button
    701.     if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
    702.       return Rect.new(0, 0, 0, 0)
    703.     end
    704.     # Return blank rect if the mouse is not dragging
    705.     return Rect.new(0, 0, 0, 0) if !@mouse_drag[i][0]
    706.     # Get drag rect coordinates
    707.     x = @mouse_drag[i][1]
    708.     y = @mouse_drag[i][2]
    709.     # Correct drag rect coordinates
    710.     x = @mouse_drag[i][3] if x > @mouse_drag[i][3]
    711.     y = @mouse_drag[i][4] if y > @mouse_drag[i][4]
    712.     # Get drag rect dimensions
    713.     width  = @mouse_drag[i][1]
    714.     height = @mouse_drag[i][2]
    715.     # Correct drag rect dimensions
    716.     width  = @mouse_drag[i][3] if x == width
    717.     height = @mouse_drag[i][4] if y == height
    718.     width  -= x
    719.     height -= y
    720.     # Return drag rect
    721.     return Rect.new(x, y, width, height)
    722.   end
    723.   #--------------------------------------------------------------------------
    724.   # * Get Mouse Drag Coordinates
    725.   #     args : the mouse button to check
    726.   #--------------------------------------------------------------------------
    727.   def self.drag_coor(*args)
    728.     # Get the button
    729.     if args.is_a?(NilClass) || args[0].is_a?(NilClass)
    730.       button = PRIMARY
    731.     else
    732.       button = args[0]
    733.     end
    734.     # Validate button
    735.     if (!(button.to_i.is_a?(Integer)) || button < 1 || button > 6)
    736.       return [@mouse_x, @mouse_y] if (button < 1 || button > 6)
    737.     end
    738.     # Return current coordinates if the mouse isn't dragging
    739.     return [@mouse_x, @mouse_y] if !@mouse_drag[button][0]
    740.     # return mouse drag starting coordinates
    741.     return [@mouse_drag[button][1], @mouse_drag[button][2]]
    742.   end
    743.   #--------------------------------------------------------------------------
    744.   # * Get Mouse in Area Flag
    745.   #--------------------------------------------------------------------------
    746.   def self.in_area?(*args)
    747.     # return false if the mouse is not on screen
    748.     return false if !@in_screen
    749.     # If the argument is a rect
    750.     if args[0].is_a?(Rect)
    751.       # Return if the mouse is within the rect
    752.       return (@mouse_x >= args[0].x && @mouse_y >= args[0].y &&
    753.         @mouse_x < args[0].x + args[0].width &&
    754.         @mouse_y < args[0].y + args[0].height)
    755.     # If the arguments are separate
    756.     else
    757.       # Return if the mouse is within the specified coordinates
    758.       return (@mouse_x >= args[0] && @mouse_y >= args[1] &&
    759.         @mouse_x < args[0] + args[2] && @mouse_y < args[1] + args[3])
    760.     end
    761.   end
    762.   #--------------------------------------------------------------------------
    763.   # * Hide Cursor
    764.   #     reset_state : if true, mouse is set to hidden, if false, it is not
    765.   #--------------------------------------------------------------------------
    766.   def self.hide_cursor(reset_state = true)
    767.     # Hide the mouse cursor
    768.     success = @showCursor.call(0)
    769.     # If the display counter is less than negative one
    770.     if success < -1
    771.       # Loop until the display counter is negative one
    772.       until success == -1
    773.         # Increment the mouse display count
    774.         success = @showCursor.call(1)
    775.       end
    776.     # If the display counter is zero or greater
    777.     elsif success >= 0
    778.       # Loop until the display counter is netagive one
    779.       until success == -1
    780.         # Decrement the mouse display count
    781.         success = @showCursor.call(0)
    782.       end
    783.     end
    784.     # If set to reset the cursor state
    785.     if reset_state
    786.       # Set the mouse to hidden
    787.       @hidden = true
    788.       @visible_override = true
    789.       # hide the cursor if a cursor graphic exists
    790.       if @cursor.is_a?(Sprite)
    791.         @cursor.visible = false
    792.       end
    793.     end
    794.   end
    795.   #--------------------------------------------------------------------------
    796.   # * Show Cursor
    797.   #     reset_state : (optional) if false, does not override cursor state
    798.   #     name        : (optional) the name of a cursor to load
    799.   #--------------------------------------------------------------------------
    800.   def self.show_cursor(*args)
    801.     # Get the reset state for mouse visibility
    802.     reset_state = true
    803.     if args[0].is_a?(FalseClass) || args[1].is_a?(FalseClass)
    804.       reset_state = false
    805.     end
    806.     # If set to reset the mouse state
    807.     if reset_state
    808.       # Override the cursor visibility
    809.       @hidden = false
    810.       # Set the default cursor name
    811.       cursor_name = "Graphics/Pictures/GF001-Cursor01"
    812.       # If a cursor name was provided as the first argument
    813.       if args[0].is_a?(String)
    814.         cursor_name = args[0]
    815.       # If a cursor name was provided as the second argument instead
    816.       elsif args[1].is_a?(String)
    817.         cursor_name = args[1]
    818.       end
    819.       # If the cursor already exists and the bitmap has not been disposed
    820.       if @cursor.is_a?(Sprite) && !@cursor.bitmap.disposed?
    821.         # Dispose the bitmap
    822.         @cursor.bitmap.dispose
    823.       # If the cursor does not exist
    824.       elsif !@cursor.is_a?(Sprite)
    825.         # Create the cursor sprite
    826.         @cursor = Sprite.new
    827.       end
    828.       # Load and set the cursor
    829.       bitmap = Bitmap.new(cursor_name)
    830.       @cursor.bitmap = bitmap
    831.       @cursor.z = 10000
    832.       @visible_override = true
    833.     end
    834.     # If the cursor is set to visible
    835.     if @visible_override
    836.       # If the mouse is on screen and there is a cursor
    837.       if @in_screen && @cursor.is_a?(Sprite)
    838.         # Hide the Windows cursor
    839.         hide_cursor(false)
    840.         # Set the cursor visibility and coordinates
    841.         @cursor.visible = true
    842.         @cursor.x = @mouse_x
    843.         @cursor.y = @mouse_y
    844.       # Hide the cursor if one exists and if the mouse is off screen
    845.       elsif @cursor.is_a?(Sprite)
    846.         @cursor.visible = false
    847.       end
    848.       # If the cursor is off screen
    849.       if !@in_screen
    850.         # Show the mouse cursor
    851.         success = @showCursor.call(1)
    852.         # If the display counter is less than negative one
    853.         if success < 15
    854.           # Loop until the display counter is negative one
    855.           until success == 15
    856.             # Increment the mouse display count
    857.             success = @showCursor.call(1)
    858.           end
    859.         # If the display counter is zero or greater
    860.         elsif success > 15
    861.           # Loop until the display counter is netagive one
    862.           until success == 15
    863.             # Decrement the mouse display count
    864.             success = @showCursor.call(0)
    865.           end
    866.         end
    867.       end
    868.     end
    869.   end
    870.   #--------------------------------------------------------------------------
    871.   # * Set Mouse X
    872.   #     coord : the x coordinate to move the mouse to
    873.   #--------------------------------------------------------------------------
    874.   def self.set_x(coord)
    875.     # Validate the argument
    876.     return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    877.     # Set the coordinate
    878.     return self.set_relative_x([[coord.to_i, 0].max, @window_width - 1].min)
    879.   end
    880.   #--------------------------------------------------------------------------
    881.   # * Set Mouse Y
    882.   #     coord : the y coordinate to move the mouse to
    883.   #--------------------------------------------------------------------------
    884.   def self.set_y(coord)
    885.     # Validate the argument
    886.     return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    887.     # Set the coordinate
    888.     return self.set_relative_y([[coord.to_i, 0].max, @window_height - 1].min)
    889.   end
    890.   #--------------------------------------------------------------------------
    891.   # * Set Real Mouse X
    892.   #     coord : the x coordinate to move the mouse to
    893.   #--------------------------------------------------------------------------
    894.   def self.set_real_x(coord)
    895.     # Validate the argument
    896.     return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    897.     # Set the coordinate
    898.     return false if(@setCursorPos.call(coord.to_i, @real_y) == 0)
    899.     # Modify internal coordinates
    900.     @real_x = coord.to_i
    901.     @mouse_x = [[coord.to_i - @window_x, 0].max, (@window_width - 1)].min
    902.     return true
    903.   end
    904.   #--------------------------------------------------------------------------
    905.   # * Set Real Mouse Y
    906.   #     coord : the y coordinate to move the mouse to
    907.   #--------------------------------------------------------------------------
    908.   def self.set_real_y(coord)
    909.     # Validate the argument
    910.     return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    911.     # Set the coordinate
    912.     return false if(@setCursorPos.call(@real_x, coord.to_i) == 0)
    913.     # Modify internal coordinates
    914.     @real_y = coord.to_i
    915.     @mouse_y = [[coord.to_i - @window_y, 0].max, (@window_height - 1)].min
    916.     return true
    917.   end
    918.   #--------------------------------------------------------------------------
    919.   # * Set Relative Mouse X
    920.   #     coord : the x coordinate to move the mouse to
    921.   #--------------------------------------------------------------------------
    922.   def self.set_relative_x(coord)
    923.     # Validate the argument
    924.     return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    925.     # Set the coordinate
    926.     return self.set_real_x([coord.to_i + @window_x, 0].max)
    927.   end
    928.   #--------------------------------------------------------------------------
    929.   # * Set Relative Mouse Y
    930.   #     coord : the y coordinate to move the mouse to
    931.   #--------------------------------------------------------------------------
    932.   def self.set_relative_y(coord)
    933.     # Validate the argument
    934.     return false if (coord.is_a?(NilClass)) || !(coord.to_i.is_a?(Integer))
    935.     # Set the coordinate
    936.     return self.set_real_y([coord.to_i + @window_y, 0].max)
    937.   end
    938.   #--------------------------------------------------------------------------
    939.   # * Set Mouse Position
    940.   #     x : the x coordinate to move the mouse to
    941.   #     y : the y coordinate to move the mouse to
    942.   #--------------------------------------------------------------------------
    943.   def self.set_pos(x, y)
    944.     # Validate the arguments
    945.     return false if (x.is_a?(NilClass)) || !(x.to_i.is_a?(Integer))
    946.     return false if (y.is_a?(NilClass)) || !(y.to_i.is_a?(Integer))
    947.     # Correct the coordinates
    948.     x = [[x.to_i, 0].max, @window_width  - 1].min
    949.     y = [[y.to_i, 0].max, @window_height - 1].min
    950.     # Set the coordinate
    951.     return self.set_relative_pos(x, y)
    952.   end
    953.   #--------------------------------------------------------------------------
    954.   # * Set Real Mouse Position
    955.   #     x : the x coordinate to move the mouse to
    956.   #     y : the y coordinate to move the mouse to
    957.   #--------------------------------------------------------------------------
    958.   def self.set_real_pos(x, y)
    959.     # Validate the arguments
    960.     return false if (x.is_a?(NilClass)) || !(x.to_i.is_a?(Integer))
    961.     return false if (y.is_a?(NilClass)) || !(y.to_i.is_a?(Integer))
    962.     # Set the coordinate
    963.     return false if (@setCursorPos.call(x.to_i, y.to_i) == 0)
    964.     # Update internal coordinates
    965.     @real_x = x.to_i
    966.     @real_y = y.to_i
    967.     @mouse_x = [[x.to_i - @window_x, 0].max, (@window_width  - 1)].min
    968.     @mouse_y = [[y.to_i - @window_y, 0].max, (@window_height - 1)].min
    969.   end
    970.   #--------------------------------------------------------------------------
    971.   # * Set Relative Mouse Position
    972.   #     x : the x coordinate to move the mouse to
    973.   #     y : the y coordinate to move the mouse to
    974.   #--------------------------------------------------------------------------
    975.   def self.set_relative_pos(x, y)
    976.     # Validate the arguments
    977.     return false if (x.is_a?(NilClass)) || !(x.to_i.is_a?(Integer))
    978.     return false if (y.is_a?(NilClass)) || !(y.to_i.is_a?(Integer))
    979.     # Correct the coordinates
    980.     x = [x.to_i + @window_x, 0].max
    981.     y = [y.to_i + @window_y, 0].max
    982.     # Set the coordinate
    983.     return self.set_real_pos(x, y)
    984.   end
    985.   #--------------------------------------------------------------------------
    986.   # * Get Button Double-Click State
    987.   #     button : the button to check
    988.   #--------------------------------------------------------------------------
    989.   def self.double_click?(button)
    990.     # Validate button
    991.     return false if (button < 1 || button > 6)
    992.     # Return the double click state
    993.     return @double_click[button]
    994.   end
    995.   #--------------------------------------------------------------------------
    996.   # * Get Last Click X
    997.   #     button : the button to check
    998.   #--------------------------------------------------------------------------
    999.   def self.last_click_x(button)
    1000.     # Validate button
    1001.     return false if (button < 1 || button > 6)
    1002.     # Return the double click state
    1003.     return @last_click_x[button]
    1004.   end
    1005.   #--------------------------------------------------------------------------
    1006.   # * Get Last Click Y
    1007.   #     button : the button to check
    1008.   #--------------------------------------------------------------------------
    1009.   def self.last_click_y(button)
    1010.     # Validate button
    1011.     return false if (button < 1 || button > 6)
    1012.     # Return the double click state
    1013.     return @last_click_y[button]
    1014.   end
    1015.   #--------------------------------------------------------------------------
    1016.   # * Convert X Coordinate to Real X Coordinate
    1017.   #     coord : the coordinate to convert
    1018.   #--------------------------------------------------------------------------
    1019.   def self.x_to_real(coord)
    1020.     # Correct coordinate and return
    1021.     return [[coord, 0].max, @window_width - 1].min + @window_x
    1022.   end
    1023.   #--------------------------------------------------------------------------
    1024.   # * Convert Y Coordinate to Real Y Coordinate
    1025.   #     coord : the coordinate to convert
    1026.   #--------------------------------------------------------------------------
    1027.   def self.y_to_real(coord)
    1028.     # Correct coordinate and return
    1029.     return [[coord, 0].max, @window_height - 1].min + @window_y
    1030.   end
    1031.   #--------------------------------------------------------------------------
    1032.   # * Convert X Coordinate to Relative X Coordinate
    1033.   #     coord : the coordinate to convert
    1034.   #--------------------------------------------------------------------------
    1035.   def self.x_to_relative(coord)
    1036.     # Correct coordinate and return
    1037.     return [[coord, 0].max, @window_width - 1].min
    1038.   end
    1039.   #--------------------------------------------------------------------------
    1040.   # * Convert Y Coordinate to Relative Y Coordinate
    1041.   #     coord : the coordinate to convert
    1042.   #--------------------------------------------------------------------------
    1043.   def self.y_to_relative(coord)
    1044.     # Correct coordinate and return
    1045.     return [[coord, 0].max, @window_height - 1].min
    1046.   end
    1047.   #--------------------------------------------------------------------------
    1048.   # * Convert Real X Coordinate to X Coordinate
    1049.   #     coord : the coordinate to convert
    1050.   #--------------------------------------------------------------------------
    1051.   def self.real_x_to_x(coord)
    1052.     # Correct coordinate and return
    1053.     return [[coord - @window_x, 0].max, @window_width - 1].min
    1054.   end
    1055.   #--------------------------------------------------------------------------
    1056.   # * Convert Real Y Coordinate to Y Coordinate
    1057.   #     coord : the coordinate to convert
    1058.   #--------------------------------------------------------------------------
    1059.   def self.real_y_to_y(coord)
    1060.     # Correct coordinate and return
    1061.     return [[coord - @window_y, 0].max, @window_height - 1].min
    1062.   end
    1063.   #--------------------------------------------------------------------------
    1064.   # * Convert Real X Coordinate to Relative X Coordinate
    1065.   #     coord : the coordinate to convert
    1066.   #--------------------------------------------------------------------------
    1067.   def self.real_x_to_relative(coord)
    1068.     # Correct coordinate and return
    1069.     return coord - @window_x
    1070.   end
    1071.   #--------------------------------------------------------------------------
    1072.   # * Convert Real Y Coordinate to Relative Y Coordinate
    1073.   #     coord : the coordinate to convert
    1074.   #--------------------------------------------------------------------------
    1075.   def self.real_y_to_relative(coord)
    1076.     # Correct coordinate and return
    1077.     return coord - @window_y
    1078.   end
    1079.   #--------------------------------------------------------------------------
    1080.   # * Convert Relative X Coordinate to X Coordinate
    1081.   #     coord : the coordinate to convert
    1082.   #--------------------------------------------------------------------------
    1083.   def self.relative_x_to_x(coord)
    1084.     # Correct coordinate and return
    1085.     return [[coord, 0].max, @window_width - 1].min
    1086.   end
    1087.   #--------------------------------------------------------------------------
    1088.   # * Convert Relative Y Coordinate to Y Coordinate
    1089.   #     coord : the coordinate to convert
    1090.   #--------------------------------------------------------------------------
    1091.   def self.relative_y_to_y(coord)
    1092.     # Correct coordinate and return
    1093.     return [[coord, 0].max, @window_height - 1].min
    1094.   end
    1095.   #--------------------------------------------------------------------------
    1096.   # * Convert Relative X Coordinate to Real X Coordinate
    1097.   #     coord : the coordinate to convert
    1098.   #--------------------------------------------------------------------------
    1099.   def self.relative_x_to_real(coord)
    1100.     # Correct coordinate and return
    1101.     return [[coord, 0].max, @window_width - 1].min + @window_x
    1102.   end
    1103.   #--------------------------------------------------------------------------
    1104.   # * Convert Relative Y Coordinate to Real Y Coordinate
    1105.   #     coord : the coordinate to convert
    1106.   #--------------------------------------------------------------------------
    1107.   def self.relative_y_to_real(coord)
    1108.     # Correct coordinate and return
    1109.     return [[coord, 0].max, @window_height - 1].min + @window_y
    1110.   end
    1111.   #--------------------------------------------------------------------------
    1112.   # * Initialize Module
    1113.   #--------------------------------------------------------------------------
    1114.   begin
    1115.     self.update
    1116.   end
    1117. end
    1118.  
    1119. #==============================================================================
    1120. # ** Keys
    1121. #------------------------------------------------------------------------------
    1122. #  This module performs key input processing
    1123. #==============================================================================
    1124.  
    1125. module Keys
    1126.   # Add class data
    1127.   class << self
    1128.     #------------------------------------------------------------------------
    1129.     # * Alias Methods
    1130.     #------------------------------------------------------------------------
    1131.     # If the update method has not been aliased
    1132.     unless method_defined?(:mouseinputmodule_keys_update)
    1133.       # Alias the update method
    1134.       alias mouseinputmodule_keys_update update
    1135.     end
    1136.     #------------------------------------------------------------------------
    1137.     # * Frame Update
    1138.     #------------------------------------------------------------------------
    1139.     def update
    1140.       # Call original method
    1141.       mouseinputmodule_keys_update
    1142.       # Update Keys module
    1143.       Mouse.update
    1144.     end
    1145.   end
    1146. end
    Expand to see the code.

(Return to top)



Instructions

  • Place this script above Main, and below the default scripts. This script must also be placed below Glitchfinder's Key Input Module. (I realize this is obvious to most, but some people don't get it.)
  • This script requires Glitchfinder's Key Input Module. This can be found here
  • This module is automatically updated by the required Keys module, which means that the only time you need to call the update method is in a scene that does not update the default Input module.
  • This module does not break the functionality of the default Input module.
  • If you wish to read keys from a gamepad, you must still use the default input module to do so.
  • To use this module, simply use one of the four methods (press?(key), trigger?(key), repeat?(key), or release?(key)), where key is the index of the key you want to check. Key may also be used as Mouse::KEYNAME. For a list of acceptable key names, look below the header.
  • There is a key named ANYKEY. This can be used like any other key, with the exception that, instead of corresponding to any one key, it reacts to them all. If you use it, and any other key would cause the same method to return true, then the ANYKEY will also return true. This takes into account all keys on the keyboard, as well.
  • There is a key named ANYBUTTON. This can be used like any other key, with the exception that, instead of corresponding to any one key, it reacts to them all. If you use it, and any other key would cause the same method to return true, then the ANYBUTTON will also return true. This only takes into account keys on the mouse.
  • One function in this script uses a default image, which goes in "Graphics/Pictures/GF001-Cursor01.png". You can find an example for this image here.
  • This script has several additional methods, details of which are in the method list below.

(Return to top)



Method List

    Mouse.update
      Updates mouse input. Calls to this method are not necessary unless the default Input module is not being updated.

    Mouse.press?(key)
      Determines whether the button determined by key is currently being pressed. If the button is being pressed, returns true. If not, returns false.

    Mouse.trigger?(key)
      Determines whether the button determined by key 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.

    Mouse.repeat?(key)
      Determines whether the button determined by key is being pressed again. Unlike trigger?(), this takes into account the repeat input of a button being held down continuously. If the button is being pressed, returns true. If not, returns false.

    Mouse.release?(key)
      Determines whether the button determined by key has just been released. If the button has been released, returns true. If not, returns false.

    Mouse.toggle?(key)
      Determines whether the button determined by key has been toggled. This functions like Caps Lock, Number Lock, and Scroll Lock, only for all keys.

    Mouse.array_press?(keys)
      Functions in the same manner as Mouse.press?(), only it takes an array of keys as input.

    Mouse.array_trigger?(keys)
      Functions in the same manner as Mouse.trigger?(), only it takes an array of keys as input.

    Mouse.array_repeat?(keys)
      Functions in the same manner as Mouse.repeat?(), only it takes an array of keys as input.

    Mouse.array_release?(keys)
      Functions in the same manner as Mouse.release?(), only it takes an array of keys as input.

    Mouse.array_toggle?(keys)
      Functions in the same manner as Mouse.toggle?(), only it takes an array of keys as input.

    Mouse.in_screen?
      This method returns true if the mouse is over the game window, and false if not. (The function returns false if the mouse is currently over the window title or edge, instead of the client area)

    Mouse.pos
      This method returns an array containing the current mouse position, in the following format: [x, y]

    Mouse.real_pos
      This method returns an array containing the current mouse position, in the following format: [x, y] The position returned by this method is the exact position of the mouse on the monitor.

    Mouse.relative_pos
      This method returns an array containing the current mouse position, in the following format: [x, y] The position returned by this method is similar to the position returned by Mouse.pos, only it will return offscreen coordinates as well.

    Mouse.tile_pos
      This method returns an array containing the current mouse position, in the following format: [x, y] The position returned by this method will be the position of the map tile the mouse is currently hovering over.

    Mouse.x
      Returns the current mouse x position. If the mouse is to the left of the game screen, returns 0. If the mouse is to the right of the game window, returns the width of the window minus one.

    Mouse.y
      Returns the current mouse y position. If the mouse is above the game screen, returns 0. If the mouse is below the game window, returns the height of the window minus one.

    Mouse.real_x
      Returns the current x position of the mouse on the monitor.

    Mouse.real_y
      Returns the current y position of the mouse on the monitor.

    Mouse.relative_x
      Returns the current mouse x position. If the mouse is to the left of the game screen, returns negative values. If the mouse is to the right of the game window, returns values higher than the width of the game window.

    Mouse.relative_y
      Returns the current mouse y position. If the mouse is above the game screen, returns negative values. If the mouse is below the game window, returns values higher than the height of the game window.

    Mouse.tile_x
      Returns the x position of the map tile the mouse is currently hovering over. If the mouse is to the left of the game screen, returns 0. If the mouse is to the right of the game window, returns the x position of the tiles on the right edge of the screen.

    Mouse.tile_y
      Returns the y position of the map tile the mouse is currently hovering over. If the mouse is above the game screen, returns 0. If the mouse is below the game window, returns the y position of the tiles on the bottom edge of the screen.

    Mouse.dragging?
    Mouse.dragging?(button)

      Checks to see if the mouse is currently dragging. (The primary button is being held while the mouse moves across the screen) Returns true if the mouse is dragging, false if the mouse is not. If an argument is supplied, this will check the dragging status of the button in question. Otherwise, the check will supply the status of the primary mouse key.

    Mouse.drag_rect
    Mouse.drag_rect(button)

      Checks to see if the mouse is dragging, and returns the rect of the drag area. If the mouse is not currently dragging, returns an empty rect. If the mouse is dragging, returns a screen rect that covers the current drag area. If an argument is supplied, this will check the dragging status of the button in question. Otherwise, the check will supply the status of the primary mouse key.

    Mouse.drag_coor
    Mouse.drag_coor(button)

      Checks to see if the mouse is dragging, and returns the starting coordinates. If the mouse is not dragging, returns the current mouse position. If an argument is supplied, this will check the dragging status of the button in question. Otherwise, the check will supply the status of the primary mouse key.The return data is in the following format: [x, y]

    Mouse.in_area?(Rect)
    Mouse.in_area?(x, y, width, height)

      Determines if the mouse is within the specified area. You can input either a rect or the x, y, width, and height of the area. If the mouse is currently within that area, returns true. Otherwise, returns false.

    Mouse.hide_cursor
    Mouse.hide_cursor(reset_state)

      Hides the mouse cursor while it is over the game screen. No arguments are needed. If reset_state is false, the mouse state will not be changed and it will remain visible. Reset_state is set to true by default.

    Mouse.show_cursor
    Mouse.show_cursor(reset_state)
    Mouse.show_cursor(cursor_name)
    Mouse.show_cursor(reset_state, cursor_name)
    Mouse.show_cursor(cursor_name, reset_state)

      Shows the mouse cursor. No arguments are needed. If reset_state is false, the mouse state will not be changed and it will remain invisible. Reset_state is set to true by default. The cursor_name argument is the location of a bitmap to use as the cursor image. This defaults to "Graphics/Pictures/GF001-Cursor01" for the file location.

    Mouse.double_click?(button)
      Returns true if the specified button is triggered twice within a short time.

    Mouse.last_click_x(button)
    Mouse.last_click_y(button)

      Returns the coordinate of the last location at which the supplied mouse button was pressed.

    Mouse.set_x(coordinate)
    Mouse.set_y(coordinate)
    Mouse.set_real_x(coordinate)
    Mouse.set_real_y(coordinate)
    Mouse.set_relative_x(coordinate)
    Mouse.set_relative_y(coordinate)
    Mouse.set_pos(x, y)
    Mouse.set_real_pos(x, y)
    Mouse.set_relative_pos(x, y)

      Sets the mouse location. These functions follow the same coordinate rules as the equivalent checks listed above.

    Mouse.x_to_real(coordinate)
    Mouse.y_to_real(coordinate)
    Mouse.x_to_relative(coordinate)
    Mouse.y_to_relative(coordinate)
    Mouse.real_x_to_x(coordinate)
    Mouse.real_y_to_y(coordinate)
    Mouse.real_x_to_relative(coordinate)
    Mouse.real_y_to_relative(coordinate)
    Mouse.relative_x_to_x(coordinate)
    Mouse.relative_y_to_y(coordinate)
    Mouse.relative_x_to_real(coordinate)
    Mouse.relative_y_to_real(coordinate)

      Converts a coordinate from one system to another. These follow the same rules as the equivalent functions listed above.

(Return to top)



License

    This script is licensed under the MIT License:

    The License wrote:
    Copyright (c) 2010-2014 Sean Porter (Glitchfinder) <[email hidden]>

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

(Return to top)

I just tested this in RMVX, and, to the best of my knowledge, it works perfectly in both VX and XP. I have changed the script header and post icon to reflect this.
Dude this really looks good. I wish I had a game that uses a mouse command, if I ever need it I will save it and maybe use it for a later project. It's also good that it works in both XP and VX. I'm surprised nobody has commented yet, I can't imagine why anybody wouldn't find this really neat.
Star wrote:
Dude this really looks good. I wish I had a game that uses a mouse command, if I ever need it I will save it and maybe use it for a later project. It's also good that it works in both XP and VX. I'm surprised nobody has commented yet, I can't imagine why anybody wouldn't find this really neat.


Thanks for the great comment! As far as I know, this is the only mouse input module that is both cross-compatible between XP and VX, and that doesn't include a lot of other, unrelated stuff.

Anyway, I just updated this to version 1.10. It's mostly superficial, since I renamed the majority of the methods so that they would no longer include a mouse_ prefix. (This was mostly because I was trying to make it easier on those switching from AWorks, but that's pretty much a worthless feature) At the same time, I updated it so that, instead of adding a second alias to the default Input module's update method, this will now be updated automatically by my Keys module, since that module is required for this one to function properly. Anyway, enjoy. (And here I am, still hoping to see what Bluescope would have to say about this and my Key Input Module)
So, here I am... and unlike the keyboard module, I have lots and lots of stuff to complain about! (I so feel at home... :tongue: )

First of all, you use a bunch of API calls, and while each of the variables get an appropriate name (such as @getCursorPos for the GetCursorPos call), GetSystemMetrics gets brutally chopped into @metrics... which is neither understandable to me, nor something good to do in terms of keeping a consistent style.


Next up is key assignment... now you quite cleverly check the OS' settings on the button swapping, which I haven't seen before in a mouse module, however, you seem to do something weird, being...
  1. PRIMARY    = !SWAPBUTTON ? 0x01 : 0x02 # Primary Mouse Button
  2. SECONDARY  = !SWAPBUTTON ? 0x02 : 0x01 # Secondary Mouse Button
Expand to see the code.

...while you could just as well do...
  1. PRIMARY = SWAPBUTTON ? 0x02 : 0x01 # Primary Mouse Button
  2. SECONDARY = SWAPBUTTON ? 0x01 : 0x02 # Secondary Mouse Button
Expand to see the code.

Also, the comments in there again seem to be redundant, as one should be able to figure out that PRIMARY within a mouse input script has somethign to do with the mouse's primary button ^^


Later on, you got a check for the cursor being in the screen, or not. It's located in update, which I don't quite understand, as putting that to a compact method will save you both the calculation of the cursor's coordinates each frame, as well as an instance variable, like so:
  1.  #--------------------------------------------------------------------------
  2.   # * Is the Mouse on Screen?
  3.   #--------------------------------------------------------------------------
  4.   def self.in_screen?
  5.     if (@mouse_x < 0 || @mouse_y < 0 || @mouse_x >= @window_width ||
  6.       @mouse_y >= @window_height)
  7.       in_screen = false # set the mouse to off screen
  8.     else
  9.       in_screen = true # set the mouse to on screen
  10.     end
  11.     return in_screen
  12.   end
Expand to see the code.



At this point, let me note that I expected you, as everyone else, to forget about the double click functionality. You included it, which I haven't seen before other than in a snippet I did some time ago, so yeah - nice ^^


Originally, I was going to complain about your @mouse_x and @mouse_y values getting falsified to ensure they're within the screen. On a later thought, that actually is useful for a bunch of occasions, including a script I'm working on at the moment... while I wanna thank you for that, I wanna add that some applications might still require something like @mouse_real_x, for example if a line's getting drawn from the center of the screen to the cursor - it'd have a different direction with your way than by having the real coordinates preserved.
Actually, writing this, I notice it shouldn't be a commonly used function... therefore, doing something like this should be sufficient:
  1.  def self.real_pos
  2.     x, y = cursor_position.unpack('LL')
  3.     return [x, y]
  4.   end
Expand to see the code.



Last but not least, something I noticed in the Keyboard script as well - you're using your nickname for alias names. I'm mentioning this purely for assuring people I'm still crazy about it, not because I actually think anyone will listen to me... :tongue:


Overall, nice work definately... despite all the little things I mentioned (from which probably 50% are perfectly fine the way they are XD ), it's still a clean, non-lazy way of handling mouse input processing, and as you said, isn't weaved into some cluttery comprehensive scripts that also have keyboard input, gamepad input, a menu systen and a brush-your-teeth instruction manual ^^

Keep up the good work!
Thanks for commenting, BlueScope! I think I'll address what you said with this one, since some things really do need a bit of explanation.
BlueScope wrote:
So, here I am... and unlike the keyboard module, I have lots and lots of stuff to complain about! (I so feel at home... :tongue: )

First of all, you use a bunch of API calls, and while each of the variables get an appropriate name (such as @getCursorPos for the GetCursorPos call), GetSystemMetrics gets brutally chopped into @metrics... which is neither understandable to me, nor something good to do in terms of keeping a consistent style.

Actually, this one was on purpose. Sort of. Specifically, I have this thing about lines extending onto a second line, and absolutely hate doing it. You're right, however, and I'll probably change that when I include several of your other suggestions.

BlueScope wrote:
Next up is key assignment... now you quite cleverly check the OS' settings on the button swapping, which I haven't seen before in a mouse module, however, you seem to do something weird, being...
  1. PRIMARY    = !SWAPBUTTON ? 0x01 : 0x02 # Primary Mouse Button
  2. SECONDARY  = !SWAPBUTTON ? 0x02 : 0x01 # Secondary Mouse Button
Expand to see the code.

...while you could just as well do...
  1. PRIMARY = SWAPBUTTON ? 0x02 : 0x01 # Primary Mouse Button
  2. SECONDARY = SWAPBUTTON ? 0x01 : 0x02 # Secondary Mouse Button
Expand to see the code.

Also, the comments in there again seem to be redundant, as one should be able to figure out that PRIMARY within a mouse input script has somethign to do with the mouse's primary button ^^

The odd code is probably due more to the fact that I was writing it at around 1:00 in the morning, and it didn't occur to me to use the second type of statement. As for the redundant commenting, it's out of habit. I tend to comment everything, even when the comment provides very little in the way of illumination. I'm of the opinion that it's always better to have the comment, just in case it does help.

BlueScope wrote:
Later on, you got a check for the cursor being in the screen, or not. It's located in update, which I don't quite understand, as putting that to a compact method will save you both the calculation of the cursor's coordinates each frame, as well as an instance variable, like so:
  1.   #--------------------------------------------------------------------------
  2.   # * Is the Mouse on Screen?
  3.   #--------------------------------------------------------------------------
  4.   def self.in_screen?
  5.     if (@mouse_x < 0 || @mouse_y < 0 || @mouse_x >= @window_width ||
  6.       @mouse_y >= @window_height)
  7.       in_screen = false # set the mouse to off screen
  8.     else
  9.       in_screen = true # set the mouse to on screen
  10.     end
  11.     return in_screen
  12.   end
Expand to see the code.

All right. I'm going to have to flat-out disagree with this one. While it might save me the calculation of the mouse's coordinates every frame, that's only if the script is not being used, which makes you wonder why it would be in the project in the first place. If they're using one of the majority of the methods in the script, it would be required to call this method. And if they're using more than one of the methods, or calling the same one multiple times, it would be recalculating these values every single time the method was called, every single frame. In other words, this would actually reduce efficiency, assuming that the script was actually being used.

BlueScope wrote:
At this point, let me note that I expected you, as everyone else, to forget about the double click functionality. You included it, which I haven't seen before other than in a snippet I did some time ago, so yeah - nice ^^

I couldn't really call this a mouse module without double clicking, could I? I would also like to note that AWorks includes a double clicking feature as well.

BlueScope wrote:
Originally, I was going to complain about your @mouse_x and @mouse_y values getting falsified to ensure they're within the screen. On a later thought, that actually is useful for a bunch of occasions, including a script I'm working on at the moment... while I wanna thank you for that, I wanna add that some applications might still require something like @mouse_real_x, for example if a line's getting drawn from the center of the screen to the cursor - it'd have a different direction with your way than by having the real coordinates preserved.
Actually, writing this, I notice it shouldn't be a commonly used function... therefore, doing something like this should be sufficient:
  1.  def self.real_pos
  2.     x, y = cursor_position.unpack('LL')
  3.     return [x, y]
  4.   end
Expand to see the code.

Actually, this is an excellent idea, and one I'm surprised I didn't come up with on my own. Even if it wouldn't be used often, I will probably end up including both a method to read the position, and methods for the x/y of the mouse, just likee I did for the current methods.

BlueScope wrote:
Last but not least, something I noticed in the Keyboard script as well - you're using your nickname for alias names. I'm mentioning this purely for assuring people I'm still crazy about it, not because I actually think anyone will listen to me... :tongue:

This one has a very, very simple explanation. I learned my script formatting style by studying the guide in the SDK, which has very specific rules regarding the formatting of an alias, to prevent the same alias being used more than once.

BlueScope wrote:
Overall, nice work definately... despite all the little things I mentioned (from which probably 50% are perfectly fine the way they are XD ), it's still a clean, non-lazy way of handling mouse input processing, and as you said, isn't weaved into some cluttery comprehensive scripts that also have keyboard input, gamepad input, a menu systen and a brush-your-teeth instruction manual ^^

Keep up the good work!

Again, thanks for the great comment, since You did point out things I hadn't seen before. I would like to note that this script does require my keyboard script, since it uses that to keep track of the mouse keys, instead of simply checking them itself. (One thing to note is that, if you really wanted to be a weird scripter, you could route keyboard input checks through this script, since it isn't programmed to reject them)
Consider everything not addressed in this post as totally agreed with :p

Af for the in_screen? matter... right now, that method is called every frame, no matter if needed or not (which is also during the title screen, transitions, all that stuff where 90% won't ever use any input at all), while the downside obviously is that people using this multiple times will get more calculations. I guess it depends on how you use it (which ultimately comes down to if you use it in a single or multiple scenes), but yeah... I guess both methods have their advantages and flaws...

And yeah, interesting that the weird way of putting nicknames in aliases comes from the SDK... I was aware of Seph being one of the first to use it, however I didn't know he was spreading it like a virus :x

I'm glad I could help! :) I hope it'll do something for the script you PMed me, which I'm at right now ^^
All right guys, I have a new version! A lot of stuff was added in this version, so please enjoy!
I'll try it later, I hope its more accurate and responsive than the last mouse script I used
friend wrote:
I'll try it later, I hope its more accurate and responsive than the last mouse script I used


If that last mouse script was AInput, the answer would be a definite yes. I was using that script as the major comparison for testing and such when I made this one, and would never have released mine if it performed worse than AInput did.
when i get off work ill test it, about ten of my scripts use your old version :D
Glitchfinder wrote:
friend wrote:
I'll try it later, I hope its more accurate and responsive than the last mouse script I used


If that last mouse script was AInput, the answer would be a definite yes. I was using that script as the major comparison for testing and such when I made this one, and would never have released mine if it performed worse than AInput did.

Well I forgot about testing this today, I'll do it tomorrow.

And I forogt which mouse script it was.
You've got in_rect, how about in_radius? Something to check if within a circle?

Or more specifically, be able to activate certain events if within their individually defined radius, including the mouse changing image when in that radius.

This actually being alive might make me tempted to work on my point-and-click game again.

Still, it's really cool to see an in_rect function there.
I'm no scripter, so I must ask, how do I implement this script?

Not install, if that is what you think. Its how do I put it to use.

My guess is that I put Mouse.press?(key) in the scripts that I want to call right?

Can you give me an example on how to implement this on the start screen so I can get a flow of it?
Taylor wrote:
You've got in_rect, how about in_radius? Something to check if within a circle?

Or more specifically, be able to activate certain events if within their individually defined radius, including the mouse changing image when in that radius.

This actually being alive might make me tempted to work on my point-and-click game again.

Still, it's really cool to see an in_rect function there.


in_radius would be a bit tougher to implement, simply because dealing with circles would be tougher to deal with. That said, I'll look into it, I suppose.

friend wrote:
I'm no scripter, so I must ask, how do I implement this script?

Not install, if that is what you think. Its how do I put it to use.

My guess is that I put Mouse.press?(key) in the scripts that I want to call right?

Can you give me an example on how to implement this on the start screen so I can get a flow of it?


Sure! Instead of giving you an edit to the title screen, I'll give you an edit to Window_Command, since that is both easier to do and more effective for what you wanted. I commented it to make it a bit easier to understand.

  1. #==============================================================================
  2. # ** Window_Command
  3. #------------------------------------------------------------------------------
  4. #  This window deals with general command choices.
  5. #==============================================================================
  6.  
  7. class Window_Command < Window_Selectable
  8.   #--------------------------------------------------------------------------
  9.   # * Frame Update
  10.   #--------------------------------------------------------------------------
  11.   def update
  12.     # Call the update method from Window_Selectable
  13.     super
  14.     # Calculate the starting position of the commands
  15.     x = self.x + 16
  16.     y = self.y + 16
  17.     # Calculate the dimensions of the command
  18.     width = self.width - 32
  19.     height = 32
  20.     # Iterate through all of the commands
  21.     for i in 0...@commands.size
  22.       # Calculate the y position of the current command
  23.       extra_y = 32 * i
  24.       # Create a rectangle with the current command's position
  25.       rect = Rect.new(x, y + extra_y, width, height)
  26.       # Check to see if the mouse is over the command
  27.       if Mouse.in_area?(rect)
  28.         # Check to see if this command is not currently selected
  29.         if self.index != i
  30.           # Play the option change SE
  31.           $game_system.se_play($data_system.cursor_se)
  32.           # Select the new command
  33.           self.index = i
  34.         end
  35.       end
  36.     end
  37.   end
  38. end
Expand to see the code.


Just keep in mind that this mouse script does require my keyboard script as well, so it will crash your game if you don't have that in there too.
@Glitch
Thanks mate, and yeah I downloaded the keyboard input too...

sadly I don't think I'll use RMXP for a project anyway, I'll give this script a try though
I tried replacing my own mouse input with yours in my mouse implementation and it seems to work just fine :3
http://webgel.net/bb/files/GlitchMouseImpl.zip

*hugs*
Zeriab wrote:
I tried replacing my own mouse input with yours in my mouse implementation and it seems to work just fine :3
http://webgel.net/bb/files/GlitchMouseImpl.zip

*hugs*

No THAT is cool! I know it might be easier to make point and click events, as well, because of the new tile_x and tile_y methods. (As well as the tile_pos method)
Thankies ^_^
It was pretty easy converting to your script. Of course there may be some subtle differences which needs to be fixed, but overall it was nice and easy to use.
The idea behind the mouse system was to enable the mouse to control all the menus while leaving the map alone. It is also an experiment where I use an eventing concept for the mouse control which I have been very pleased with. It is way easier to manage than using a top-down approach.
You can indeed make point and click events, but that was not a part of what I intended with the system. There is nothing wrong with building on top of my system.

I do hope my implementation also helps people getting an idea of how much scripting is still required after adding your script to have the mouse feel fully functioning.
Lemme add a little disclaimer just incase: The parts I have scripted are free to use in commercial and noncommercial alike, but use are your own risk only.

*hugs*
ok, i tested it with all my scripts, it works like a charm, i like the new features(though i had added many of them myself to your old one) there is one downside IMO. i have my own little cursor i use in game. i use this to hide the real one
  1. cursor = Win32API.new("user32", "ShowCursor", "i", "i" ).call(0)
Expand to see the code.

i had no problems with your old script doing this, but for what ever reason when i replaced it with your new version it isnt hiding the mouse any more. i didnt play with it much. just replaced your old script with your new one
Plague180 wrote:
ok, i tested it with all my scripts, it works like a charm, i like the new features(though i had added many of them myself to your old one) there is one downside IMO. i have my own little cursor i use in game. i use this to hide the real one
  1. cursor = Win32API.new("user32", "ShowCursor", "i", "i" ).call(0)
Expand to see the code.

i had no problems with your old script doing this, but for what ever reason when i replaced it with your new version it isnt hiding the mouse any more. i didnt play with it much. just replaced your old script with your new one


My new script actually has a method to hide the mouse. It's made so that the mouse is only hidden while it is in the game screen, and it's also been set so that if the mouse is detected to be in the wrong state, it gets put to the right one. Check out the last two methods in the method list, hide_cusor and show_cursor.
:D thanks glitch told ya i didnt play too much with it :D
What cure would you prescribe for the "Stack level too deep" error when resetting the game with the F12 key?
I would suggest using this snippet of mine: http://pastebin.com/KdBFd0Cn
Create a new section at the very top and put it there. It must be the very first code or there is a danger of still getting that error.

*hugs*
Nice Script! Ey men I will pay or Thanks forever if one could kindly put this script working with Zenith Tactical Battle System. I expect one of the experts could do me a favor.

I have uploaded a ztbs version, www.megaupload.com/?d=FRKVJJ81

thanks in advanced! see you ;)
Zeriab wrote:
I would suggest using this snippet of mine: http://pastebin.com/KdBFd0Cn
Create a new section at the very top and put it there. It must be the very first code or there is a danger of still getting that error.

*hugs*


That indeed solves the problem. But the newly created thread is not active by default. Is it possible to make it so? It's a small thing, but it matters to me. (my game normally takes a noticeable amount of time to load as it is)

Hmm, the part of the script that seems to be leading to the stack error is the key update for the input module.
I've been able to implement full mouse support for my game thanks to this excellent script. The only problem remains that it crashes on F12 unless I use Zeriab's code, in which case F12 launches a new (inactive) thread. But it sounds as if nobody knows of a better solution.
What do you mean by that it is not active? Does the game just exit when you press F12?

On a different note you can change the behavior of F12 so it pauses the game instead with this script: viewtopic.php?f=11&t=64701

*hugs*
i think flowerthief is having the same issue i always had with this script, when you are testing something over and over you often want to restart the exe, pressing f12 normally does that, with this script it crashes your game.
To the player it appears as if the game simply exited. In actuality, a new thread is launched, just as your code snippet is supposed to do, but the player doesn't automatically realize it. They see the old window go away.

I don't want F12 to pause. I want it to reset the game the way it did before I installed this script.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=71133