• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Marin's Input Module

971
Posts
7
Years
  • Age 21
  • Seen Nov 28, 2022
I've wanted to make my own mouse module for a while, and I also felt like making my own, slightly different, Input module. Since these are both related to Input, I decided to combine them and call it MInput.

Features:
  • The ability to get input from every single button on a traditional keyboard;
  • Custom intervals for MInput.repeat?
  • Shortcut-methods for specific keys (e.g. MInput.confirm? and MInput.cancel?. These are completely customisable)
  • Mouse functionality

The Mouse module built-in (MInput::Mouse) has all functionality the normal buttons have (.trigger?, .press?, .repeat?), but you can pass them one of the following:
  • A Sprite (it will only return true if the mouse is within the area of that sprite)
  • A Rect object (only returns true if the mouse is within that area)
  • X, Y, Width, Height (only returns true if the mouse is within that area)

Installation

To use this plugin, simply paste the script underneath in a new section above the Main script:
MInput




Documentation

MInput is a module which has the following methods:


trigger?
When the button is first pressed down, this method will return true.

Example:
Code:
until MInput.trigger?(:C)
  Graphics.update
  Input.update
end



press?
Returns true if the button is currently being pressed/held down.

Example:
Code:
until MInput.press?(:C)
  Graphics.update
  Input.update
end



repeat?
Returns true once if the button is first pressed down. It then waits DefaultWaitTimeForInterval frames until it returns true again, and it will then return true once per interval frames. This interval defaults to 2.

Example:
Code:
loop do
  Graphics.update
  Input.update
  puts MInput.repeat?(:C,6)
end

# true
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# false
# true
# false
# false
# false
# false
# false
# true
# etc



There is also a hash that will create shortcut methods.
It looks like this:
Code:
SHORTCUTS = {
    :confirm? => [:C,:RETURN],
    :cancel? => [:X,:BACKSPACE,:ESC]
}
This will create a method call MInput.confirm? which acts exactly like MInput.trigger?(:C, :RETURN)
And also MInput.cancel? which is the same as MInput.trigger?(:X, :BACKSPACE, :ESC).


Furthermore, the MInput module also contains a submodule called Mouse. To reference this module and its methods, you should write down MInput::Mouse. This Mouse module contains the exact same methods as MInput itself, with .trigger?, .press? and .repeat?, but you can't give it buttons to check for. By default, the mouse will only respond to the LEFT mouse button.

To enable the right/middle mouse button as well, call:
MInput::Mouse.mouse_right = true
To disable the left/right/middle mouse button, you set it to false:
MInput::Mouse.mouse_left = false

You can pass any of the MInput::Mouse methods a Sprite, Rect, or 4 numbers which represent the area the mouse has to be in to return true in the input method. Additionally, you can also see if the mouse is WITHIN an area WITHOUT actually checking for a button press using MInput::Mouse.over?. This also takes either a Sprite, Rect, or 4 numbers.
 
Back
Top