• Hi, Guest!
    Some images might be missing as we move away from using embedded images, sorry for the mess!
    From now on, you'll be required to use a third party to host images. You can learn how to add images here, and if your thread is missing images you can request them here.
    Do not use Discord to host any images you post, these links expire quickly!
Marin's Input Module

Marin's Input Module v1.0

Pokémon Essentials Version
v18 ➖
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.
Credits
  • Marin
Author
Marin
Views
1,041
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Marin

Latest updates

  1. Update v1.3

    You can now have multiple calls to MInput::Mouse.click? and MInput::Mouse.repeat? - These were...
  2. Update v1.2

    Added an alias for MInput::Mouse.trigger? : MInput::Mouse.click? Added an alias for...
  3. Update v1.1

    Made press? the primary function for determining if the given key is held down rather than down...
Back
Top