Mouse Input Module Version: 2.10
By: Glitchfinder
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.
Features- Check the mouse location!
- Check the mouse keys!
- Includes double clicking support!
- Includes dragging support!
- Doesn't break the default Input module!
- Does not break events or scripts that call the default Input module!
- Automatically updated by the default Input module!
- Allows you to check to see if a key has been released!
- Doesn't crash on F12!
- Can check more than one button at a time!
- Allows you to hide the mouse!
- Uses the famed Any key!
- Used the Any key's little brother, the Any button!
Screenshots Since this script has no visual elements, a screenshot cannot be taken.
Script
- #≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
- # ** Glitchfinder's Mouse Input Module [RPG Maker XP]
- # Version 2.10
- #------------------------------------------------------------------------------
- # This script helps scripters to use the mouse, without being limited by the
- # default Input Module.
- #==============================================================================
- # * Version History
- #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- # Version 1.00 ------------------------------------------------- (2010-03-18)
- # - Initial version
- # - Author: Glitchfinder
- # Version 1.10 ------------------------------------------------ (2010-06-02)
- # - Methods renamed for efficiency
- # - Modified to be updated by the Key module instead of the Input module
- # - Author: Glitchfinder
- # Version 2.10 ------------------------------------------------- (2011-03-17)
- # - Added the Mouse.toggle?() method
- # - Added the Mouse.array_press? method
- # - Added the Mouse.array_trigger? method
- # - Added the Mouse.array_repeat? method
- # - Added the Mouse.array_release? method
- # - Added the Mouse.array_toggle? method
- # - Added the Mouse.real_pos() method
- # - Added the Mouse.relative_pos() method
- # - Added the Mouse.tile_pos() method
- # - Added the Mouse.real_x() method
- # - Added the Mouse.real_y() method
- # - Added the Mouse.relative_x() method
- # - Added the Mouse.relative_y() method
- # - Added the Mouse.tile_x() method
- # - Added the Mouse.tile_y() method
- # - Added the Mouse.hide_cursor() method
- # - Added the Mouse.show_cursor() method
- # - Added the ANYKEY constant
- # - Added the ANYBUTTON constant
- # - Corrected calculations for x() method
- # - Corrected calculations for y() method
- # - Author: Glitchfinder
- #==============================================================================
- # * Instructions
- #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- # Place this script above Main, and below the default scripts. This script
- # must also be placed below Glitchfinder's Key Input Module.
- #
- # This script requires Glitchfinder's Key Input Module. This can be found at
- # his site, which is located at http://www.glitchkey.com
- #
- # 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.
- #
- # 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 ANYKEY will also return true. This only takes into
- # account keys on the mouse.
- #
- # This script has several additional methods, details of which are in the
- # method list below.
- #==============================================================================
- # * 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 RMXP 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
- # 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?
- # 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.
- #
- # Mouse.drag_rect
- # 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.
- #
- # Mouse.drag_coor
- # Checks to see if the mouse is dragging, and returns the starting
- # coordinates. If the mouse is not dragging, returns the current mouse
- # position. 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(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(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.
- #==============================================================================
- # *Glitchfinder's Advice
- #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- # This script is meant for people with a medium or advanced level of scripting
- # knowledge and ability, or for those using scripts that require this module.
- #==============================================================================
- # * Contact
- #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- # Glitchfinder, the author of this script, may be contacted through his
- # website, found at http://www.glitchkey.com
- #
- # You may also find Glitchfinder at http://www.hbgames.org
- #==============================================================================
- # * Usage
- #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- # This script may be used with the following terms and conditions:
- #
- # 1. This script is free to use in any noncommercial project. If you wish to
- # use this script in a commercial (paid) project, please contact
- # Glitchfinder at his website.
- # 2. This script may only be hosted at the following domains:
- # http://www.glitchkey.com
- # http://www.hbgames.org
- # 3. If you wish to host this script elsewhere, please contact Glitchfinder.
- # 4. If you wish to translate this script, please contact Glitchfinder. He
- # will need the web address that you plan to host the script at, as well
- # as the language this script is being translated to.
- # 5. This header must remain intact at all times.
- # 6. Glitchfinder remains the sole owner of this code. He may modify or
- # revoke this license at any time, for any reason.
- # 7. Any code derived from code within this script is owned by Glitchfinder,
- # and you must have his permission to publish, host, or distribute his
- # code.
- # 8. This license applies to all code derived from the code within this
- # script.
- # 9. If you use this script within your project, you must include visible
- # credit to Glitchfinder, within reason.
- #≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
-
- #==============================================================================
- # ** Mouse
- #------------------------------------------------------------------------------
- # This module performs mouse input processing
- #==============================================================================
-
- module Mouse
- #--------------------------------------------------------------------------
- # * Declare Module Variables
- #--------------------------------------------------------------------------
- # Declare API calls
- @metrics = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
- @getCursorPos = Win32API.new('user32', 'GetCursorPos', ['p'], 'v')
- @getWindowRect = Win32API.new('user32', 'GetWindowRect', 'lp', 'v')
- @showCursor = Win32API.new('user32', 'ShowCursor', 'i', 'i')
- # Get window thread
- findWindowEx = Win32API.new('user32', 'FindWindowEx', 'llpp', 'i')
- @window = findWindowEx.call(0,0,"RGSS Player",0)
- # Set up double click
- @double_click = false
- @double_click_frames = 20
- @double_click_pixels = 4
- @double_click_counter = 0
- # Set up drag
- @drag_pixels = 4
- @drag_hold = false
- @mouse_drag = [false, 0, 0, 0, 0]
- # Set up last click
- @last_click_x = 0
- @last_click_y = 0
- # Set mouse to visible
- @hidden = false
- #--------------------------------------------------------------------------
- # * Mouse Keys
- #--------------------------------------------------------------------------
- SWAPBUTTON = @metrics.call(23) == 0 ? false : true # Buttons Swapped
- LBUTTON = 0x01 # Physical Left Button
- RBUTTON = 0x02 # Physical Right Button
- MBUTTON = 0x04 # Middle Mouse Button
- XBUTTON1 = 0x05 # X1 Mouse Button
- XBUTTON2 = 0x06 # X2 Mouse Button
- PRIMARY = !SWAPBUTTON ? 0x01 : 0x02 # Primary Mouse Button
- SECONDARY = !SWAPBUTTON ? 0x02 : 0x01 # Secondary Mouse Button
- #--------------------------------------------------------------------------
- # * Special Keys
- #--------------------------------------------------------------------------
- ANYKEY = 0x100 # Any Key
- ANYBUTTON = [0x01, 0x02, 0x04, 0x05, 0x06]
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def self.update
- # create blank rect
- rect = '0'*16
- # Get window rect
- @getWindowRect.call(@window, rect)
- # Unpack rect data
- left, top, right, bottom = rect.unpack("LLLL")
- # Get window coordinates
- @window_x = left + @metrics.call(5) + @metrics.call(45)
- @window_y = top + @metrics.call(6) + @metrics.call(46) + @metrics.call(4)
- # Get window width
- @window_width = right - left
- @window_width -= (@metrics.call(5) + @metrics.call(45)) * 2
- # Get window height
- @window_height = bottom - top
- @window_height -= (@metrics.call(6) + @metrics.call(46)) * 2
- @window_height -= @metrics.call(4)
- # Set blank cursor position
- cursor_position = '0'*8
- # Get cursor position
- @getCursorPos.call(cursor_position)
- # Unpack cursor position data
- @real_x, @real_y = cursor_position.unpack('LL')
- # Set cursor position relative to the window
- @mouse_x = @real_x - @window_x
- @mouse_y = @real_y - @window_y
- # If the cursor is not over the window
- if (@mouse_x < 0 || @mouse_y < 0 || @mouse_x >= @window_width ||
- @mouse_y >= @window_height)
- # Set the mouse to off screen
- @in_screen = false
- # If the cursor is over the window
- else
- # Set the mouse to on screen
- @in_screen = true
- end
- # Correct mouse x coordinate
- @mouse_x = 0 if @mouse_x < 0
- @mouse_x = @window_width - 1 if @mouse_x >= @window_width
- # Correct mouse_y coordinate
- @mouse_y = 0 if @mouse_y < 0
- @mouse_y = @window_height - 1 if @mouse_y >= @window_height
- # Clear double click flag
- @double_click = false
- # Set up mouse deviance
- x_deviance = @last_click_x - @mouse_x
- y_deviance = @last_click_y - @mouse_y
- # Correct mouse deviance
- x_deviance *= -1 if x_deviance < 0
- y_deviance *= -1 if y_deviance < 0
- # If the primary key is triggered
- if self.trigger?(PRIMARY)
- # Set allowed deviance
- deviance = @double_click_pixels
- # If double click counter is running and deviance is within allowed range
- if (@double_click_counter > 0 && x_deviance <= deviance &&
- y_deviance <= deviance)
- # Set double click flag to true
- @double_click = true
- # If double click counter is not running or the cursor is out of bounds
- else
- # Reset double click counter
- @double_click_counter = @double_click_frames
- end
- # Set drag hold flag to true
- @drag_hold = true
- # Set drag start coordinates
- @mouse_drag[1] = @mouse_x
- @mouse_drag[2] = @mouse_y
- # Set last click coordinates
- @last_click_x = @mouse_x
- @last_click_y = @mouse_y
- # If the primary key is pressed
- elsif self.press?(PRIMARY)
- # If the mouse has moved beyond the required deviance
- if x_deviance >= @drag_pixels && y_deviance >= @drag_pixels
- # Set the mouse to dragging
- @mouse_drag[0] = true
- end
- # If the mouse is dragging
- if @mouse_drag[0] == true
- # Set current dragging corrdinates
- @mouse_drag[3] = @mouse_x
- @mouse_drag[4] = @mouse_y
- end
- # If the primary key is released
- elsif self.release?(PRIMARY)
- # Set drag hold flag to false
- @drag_hold = false
- # Reset drag data
- @mouse_drag[0] = false
- @mouse_drag[1] = 0
- @mouse_drag[2] = 0
- @mouse_drag[3] = 0
- @mouse_drag[4] = 0
- end
- # If the double click counter is running
- if @double_click_counter > 0
- # Cycle the double click counter down one frame
- @double_click_counter -= 1
- end
- # If the cursor is not in the screen and it is set to hidden
- if !@in_screen && @hidden
- # Set the mouse to visible
- show_cursor(false)
- # If the cursor is in the screen and it is set to hidden
- elsif @hidden
- # Hide the mouse cursor
- hide_cursor(false)
- # If the cursor is not set to hidden
- else
- # Set the mouse to visible
- show_cursor(false)
- end
- end
- #--------------------------------------------------------------------------
- # * Get Key Pressed State
- # key : key index
- #--------------------------------------------------------------------------
- def self.press?(key)
- # Return key pressed state
- return Keys.press?(key)
- end
- #--------------------------------------------------------------------------
- # * Get Key Triggered State
- # key : key index
- #--------------------------------------------------------------------------
- def self.trigger?(key)
- # Return key triggered state
- return Keys.trigger?(key)
- end
- #--------------------------------------------------------------------------
- # * Get Key Repeated State
- # key : key index
- #--------------------------------------------------------------------------
- def self.repeat?(key)
- # Return key repeated state
- return Keys.repeat?(key)
- end
- #--------------------------------------------------------------------------
- # * Get Key Released State
- # key : key index
- #--------------------------------------------------------------------------
- def self.release?(key)
- # Return key released state
- return Keys.release?(key)
- end
- #--------------------------------------------------------------------------
- # * Get Key Toggled State
- # key : key index
- #--------------------------------------------------------------------------
- def self.toggle?(key)
- # Return key toggled state
- return Keys.toggle?(key)
- end
- #--------------------------------------------------------------------------
- # * Get Key Pressed State (array)
- # keys : array of key indices
- #--------------------------------------------------------------------------
- def self.array_press?(keys)
- # Return key pressed state
- return Keys.array_press?(keys)
- end
- #--------------------------------------------------------------------------
- # * Get Key Triggered State (array)
- # keys : array of key indices
- #--------------------------------------------------------------------------
- def self.array_trigger?(keys)
- # Return key triggered state
- return Keys.array_trigger?(keys)
- end
- #--------------------------------------------------------------------------
- # * Get Key Repeated State (array)
- # keys : array of key indices
- #--------------------------------------------------------------------------
- def self.array_repeat?(keys)
- # Return key repeated state
- return Keys.array_repeat?(keys)
- end
- #--------------------------------------------------------------------------
- # * Get Key Released State (array)
- # keys : array of key indices
- #--------------------------------------------------------------------------
- def self.array_release?(keys)
- # Return key released state
- return Keys.array_release?(keys)
- end
- #--------------------------------------------------------------------------
- # * Get Key Toggled State (array)
- # keys : array of key indices
- #--------------------------------------------------------------------------
- def self.array_toggle?(keys)
- # Return key toggled state
- return Keys.array_toggle?(keys)
- end
- #--------------------------------------------------------------------------
- # * Is the Mouse on Screen?
- #--------------------------------------------------------------------------
- def self.in_screen?
- # Return mouse in screen flag
- return @in_screen
- end
- #--------------------------------------------------------------------------
- # * Get Mouse Position
- #--------------------------------------------------------------------------
- def self.pos
- # Return mouse position array
- return [@mouse_x, @mouse_y]
- end
- #--------------------------------------------------------------------------
- # * Get Real Mouse Position
- #--------------------------------------------------------------------------
- def self.real_pos
- # Return real mouse position array
- return [@real_x, @real_y]
- end
- #--------------------------------------------------------------------------
- # * Get Relative Mouse Position
- #--------------------------------------------------------------------------
- def self.relative_pos
- # Return relative mouse position array
- return [relative_x, relative_y]
- end
- #--------------------------------------------------------------------------
- # * Get Mouse Tile Position
- #--------------------------------------------------------------------------
- def self.tile_pos
- # Return mouse tile position array
- return [tile_x, tile_y]
- end
- #--------------------------------------------------------------------------
- # * Get Mouse X Position
- #--------------------------------------------------------------------------
- def self.x
- # Return mouse x position
- return @mouse_x
- end
- #--------------------------------------------------------------------------
- # * Get Mouse Y Position
- #--------------------------------------------------------------------------
- def self.y
- # Return mouse y position
- return @mouse_y
- end
- #--------------------------------------------------------------------------
- # * Get Real Mouse X Position
- #--------------------------------------------------------------------------
- def self.real_x
- # Return real mouse x position
- return @real_x
- end
- #--------------------------------------------------------------------------
- # * Get Real Mouse Y Position
- #--------------------------------------------------------------------------
- def self.real_y
- # Return real mouse y position
- return @real_y
- end
- #--------------------------------------------------------------------------
- # * Get Relative Mouse X Position
- #--------------------------------------------------------------------------
- def self.relative_x
- # Return mouse x position
- return (@real_x - @window_x)
- end
- #--------------------------------------------------------------------------
- # * Get Relative Mouse Y Position
- #--------------------------------------------------------------------------
- def self.relative_y
- # Return mouse y position
- return (@real_y - @window_y)
- end
- #--------------------------------------------------------------------------
- # * Get Mouse Tile X Position
- #--------------------------------------------------------------------------
- def self.tile_x
- # Return mouse x tile position
- return (@mouse_x / 32).to_i
- end
- #--------------------------------------------------------------------------
- # * Get Mouse Tile Y Position
- #--------------------------------------------------------------------------
- def self.tile_y
- # Return mouse y tile position
- return (@mouse_y / 32).to_i
- end
- #--------------------------------------------------------------------------
- # * Get Mouse Dragging Boolean
- #--------------------------------------------------------------------------
- def self.dragging?
- # Return mouse dragging flag
- return @mouse_drag[0]
- end
- #--------------------------------------------------------------------------
- # * Get Mouse Drag Rect
- #--------------------------------------------------------------------------
- def self.drag_rect
- # Return blank rect if the mouse is not dragging
- return Rect.new(0, 0, 0, 0) if !@mouse_drag[0]
- # Get drag rect coordinates
- x = @mouse_drag[1] <= @mouse_drag[3] ? @mouse_drag[1] : @mouse_drag[3]
- y = @mouse_drag[2] <= @mouse_drag[4] ? @mouse_drag[2] : @mouse_drag[4]
- # Get drag rect dimensions
- width = @mouse_drag[1] > @mouse_drag[3] ? @mouse_drag[1] : @mouse_drag[3]
- height = @mouse_drag[2] > @mouse_drag[4] ? @mouse_drag[2] : @mouse_drag[4]
- # Correct drag rect dimensions
- width -= x
- height -= y
- # Return drag rect
- return Rect.new(x, y, width, height)
- end
- #--------------------------------------------------------------------------
- # * Get Mouse Drag Coordinates
- #--------------------------------------------------------------------------
- def self.drag_coor
- # Return current coordinates if the mouse isn't dragging
- return [@mouse_x, @mouse_y] if !@mouse_drag[0]
- # return mouse drag starting coordinates
- return [@mouse_drag[1], @mouse_drag[2]]
- end
- #--------------------------------------------------------------------------
- # * Get Mouse in Area Flag
- #--------------------------------------------------------------------------
- def self.in_area?(*args)
- # return false if the mouse is not on screen
- return false if !@in_screen
- # If the argument is a rect
- if args[0].is_a?(Rect)
- # Return if the mouse is within the rect
- return (@mouse_x >= args[0].x && @mouse_y >= args[0].y &&
- @mouse_x < args[0].x + args[0].width &&
- @mouse_y < args[0].y + args[0].height)
- # If the arguments are seperate
- else
- # Return if the mouse is within the specified coordinates
- return (@mouse_x >= args[0] && @mouse_y >= args[1] &&
- @mouse_x < args[0] + args[2] && @mouse_y < args[1] + args[3])
- end
- end
- #--------------------------------------------------------------------------
- # * Hide Cursor
- # reset_state : if true, mouse is set to hidden, if false, it is not
- #--------------------------------------------------------------------------
- def self.hide_cursor(reset_state = true)
- # Hide the mouse cursor
- success = @showCursor.call(0)
- # If the display counter is less than negative one
- if success < -1
- # Loop until the display counter is negative one
- until success == -1
- # Increment the mouse display count
- success = @showCursor.call(1)
- end
- # If the display counter is zero or greater
- elsif success >= 0
- # Loop until the display counter is netagive one
- until success == -1
- # Decrement the mouse display count
- success = @showCursor.call(0)
- end
- end
- # Set the mouse to hidden
- @hidden = true if reset_state
- end
- #--------------------------------------------------------------------------
- # * Show Cursor
- # reset_state : if true, mouse is set to visible, if false, it is not
- #--------------------------------------------------------------------------
- def self.show_cursor(reset_state = true)
- # Show the mouse cursor
- success = @showCursor.call(1)
- # If the display counter is less than negative one
- if success < 0
- # Loop until the display counter is negative one
- until success == 0
- # Increment the mouse display count
- success = @showCursor.call(1)
- end
- # If the display counter is zero or greater
- elsif success > 0
- # Loop until the display counter is netagive one
- until success == 0
- # Decrement the mouse display count
- success = @showCursor.call(0)
- end
- end
- # Set the mouse to hidden
- @hidden = false if reset_state
- end
- #--------------------------------------------------------------------------
- # * Initialize Module
- #--------------------------------------------------------------------------
- begin
- self.update
- end
- end
-
- #==============================================================================
- # ** Keys
- #------------------------------------------------------------------------------
- # This module performs key input processing
- #==============================================================================
-
- module Keys
- # Add class data
- class << self
- #------------------------------------------------------------------------
- # * Alias Methods
- #------------------------------------------------------------------------
- # If the update method has not been aliased
- unless method_defined?(:mouseinputmodule_keys_update)
- # Alias the update method
- alias mouseinputmodule_keys_update update
- end
- #------------------------------------------------------------------------
- # * Frame Update
- #------------------------------------------------------------------------
- def update
- # Call original method
- mouseinputmodule_keys_update
- # Update Keys module
- Mouse.update
- end
- end
- end
Expand to see the code.
InstructionsPlace this script above Main, and below the default scripts. This script must also be placed below Glitchfinder's Key Input Module.
This script requires Glitchfinder's Key Input Module. This can be found at his site, which is located at
http://www.glitchkey.comThis 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.
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 ANYKEY will also return true. This only takes into account keys on the mouse.
This script has several additional methods, details of which are in the method list below.
RequirementsGlitchfinder's Key Input Module.Method ListMouse.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.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.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.in_screen?
This method returns true if the mouse is over the RMXP 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: [mouse_x, mouse_y] (If the mouse is not over the RMXP Game Window, the coordinates returned will reflect the nearest edge. So, if the mouse is above and to the left of the window, both coordinates will be 0)
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 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?
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.
Mouse.drag_rect
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.
Mouse.drag_coor
Checks to see if the mouse is dragging, and returns the starting coordinates. If the mouse is not dragging, returns the current mouse position. The return data is in the following format: [mouse_x, mouse_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(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(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.
Terms and Conditions- This script is free to use in any noncommercial project. If you wish to use this script in a commercial (paid) project, please contact Glitchfinder at his website.
- This script may only be hosted at the following domains:
http://www.glitchkey.com
http://www.hbgames.org - If you wish to host this script elsewhere, please contact Glitchfinder.
- If you wish to translate this script, please contact Glitchfinder. He will need the web address that you plan to host the script at, as well as the language this script is being translated to.
- The script header must remain intact at all times.
- Glitchfinder remains the sole owner of this code. He may modify or revoke this license at any time, for any reason.
- Any code derived from code within this script is owned by Glitchfinder, and you must have his permission to publish, host, or distribute his code.
- This license applies to all code derived from the code within this script.
- If you use this script within your project, you must include visible credit to Glitchfinder, within reason.