Keyboard Input Module (Revised)
#1
Keyboard Input Module (Revised)
Revision 1.2
based on Jaime 'Near Fantastica' Webster's system


Introduction
"I know there is a few keyboard input scripts out there but not like this one... this one works fundamentally different then the others you press and key and it returns what was pressed... which lets you easily have string input for names, conversations, or what ever you see fit." - Near Fantastica

Pretty much what he said. :thumb:

This system is not a name input module, a message system or menu system that uses keyboard input. This is the basic module that you would use to CREATE such systems. It reads keyboard presses, be they letter characters, shift keys, or whatnot and allows you to access them in place of the default systems' routines.

Now far be it from me to just post my own system without acknowleding Near Fantastica's original work. Without his work, this wouldn't be available. As such, I am posting his script in this topic along with the newly revised system.


Script
Keyboard Input Module (Revised)
NOTE:
In this 'revised' version, I have included [Caps Lock] for determining capital letters and [NumLock] for changing the functions on the numeric keypad. I have also revised the code and added the ability to detect individual 'left' and 'right' function keys (left shift, right shift, left alt, etc.). Even with the inclusions, it is still smaller than Near Fantastica's system.

...and the original v3 script
Keyboard Input Module (Original Version)
NOTE:
This system (when acquired) referred to a 'wow' method that was not included in this system. It was used to generate the actual alphanumeric character/number (from the ascii value) to be returned. Somehow it was a 'mis'-copy and the actual method used was a 'chr'. This has been corrected.

Presented in the original format (minus the 'wow' error) I was able to obtain from 'Creation Asylum.'


Instructions
This script is used to detect keys being pressed and return them for use in your scripts... whether it is a message script, a custom menu system or advanced battlesystem. This script alone accomplishes nothing unless you create a system that utilizes the calls within:

Syntax (Just like Near Fantastica's - with one addition.)
Code:
if Input.get_function   == "function"  # Keys like [Esc], [Ctrl], [Tab]
if Input.get_letters    == "letter"    # The alphabet keys (augmented by (Shift] or [Caps])
if Input.get_numbers    == "number"    # The number keys (disabled if [Shift] is being pressed)
if Input.get_key        == "char"      # All other printable keys (and top-row number keys [shift]ed)
if Input.get_direction  == "number"    # Number Pad & [Home], [PgUp] and etc.
and
if Input.get_individual == "function"  # Keys like [Left Alt], [Right Alt], [Left Shift]

Input.get_function
[SIZE="1]This call allows you to detect specialized keys such as 'Esc', 'Ctrl', 'Backspace' , 'Print Screen' and the 'F1 to F12' keys
[/SIZE]
Input.get_letters
This call allows you to detect the alphabetic characters being returned, and whether they are 'shifted' or not. Unlike cybersam's system, this detects whether the left and/or right shift buttons are being pressed so generation of capital and lowercase characters can be produced.

Input.get_numbers
This call allows you to detect the number keys (0 to 9) along the TOP of the keyboard. It does not detect any 'shifted' characters and does not detect the number keys on the keypad.

Input.get_key
This call returns most other alpha-numeric characters such as the space key, brackets and parenthesis, equals and the 'shifted' characters along the top of the keyboard.

Input.get_direction
This call returns the number keys on the directional keypad when the Numberlock is on and directional keys when it is off. It also returns keys such as PgUp, PgDown, Home and etc.

Input.get_individual
This call returns the specialized function keys of [CapsLock], [NumberLock] and [ScrollLock]. But it also detects the unique keys such as [Lf Ctrl] and [Rt Cntl] and matching ones for Alt and Shift. The pressing of [CapsLock] and [NumberLock] automatically alters the returned values of the other functions, but this function is useful if you want to detect and return the button as part of your special menu/battle/whatever system.


FAQ
Again, this system is used to detect keypresses but it is up to the end-user to create system(s) that use these key-detection functions.


Keys to NOT Consider (Unless you're real good)
As the [F1], [F2] and [F12] keys are most likely hardwired into Game.Exe or cleverly concealed within the RGSS default coding, I would not recommend testing and writing code for these. This is under the assumption that an advanced script has not been made that could disable these key's built-in functions.

Also, while detection of the Left and Right Windows key (for the Microsoft Natural keyboard) is now available, these are not recommended given as well. Not unless you can disable Windows's key reactions themselves.


Compatibility
As it adds routines to the INPUT module, it should be compatible with nearly any system. The only exception being systems that also add or edit the INPUT module that may use the same routine names... rare instances.


Example Code
Based on a small submission by GoldenShadow in N.F's post in Creation Asylum, this example shows how you can detect certain keys with this system. Just press [Esc] from the field map to bring up a 'butchered' main menu screen and press keys to your heart's content. :D

Example
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Aleworks Input Mouse Sprite Add-On DerVVulfman 2 1,888 09-21-2023, 02:56 PM
Last Post: DerVVulfman
   Keyboard Name Input - Updated DerVVulfman 0 1,928 01-05-2022, 04:25 AM
Last Post: DerVVulfman
   Audio Module Rewrite mcisendstring DerVVulfman 25 42,187 05-03-2020, 08:08 PM
Last Post: MikiIsAway
   MicKo's Skill Tree - Revised DerVVulfman 49 66,865 12-17-2019, 04:13 AM
Last Post: DerVVulfman
   GPLAT Pixel Platformer Revised DerVVulfman 0 4,708 10-02-2014, 04:14 AM
Last Post: DerVVulfman
   NRGSS Module Function Library Narzew 2 8,319 05-12-2012, 11:07 AM
Last Post: Narzew
   JEM: Jennifer's Entry Module DerVVulfman 0 5,582 10-14-2010, 04:30 AM
Last Post: DerVVulfman
   Module VirtualKeys zecomeia 0 5,312 03-14-2010, 01:25 AM
Last Post: zecomeia
   Profession/Offices Module EX-PLUS! Mephistox 0 5,075 03-07-2008, 06:54 AM
Last Post: Mephistox
   Geometry Module Trickster 0 4,340 03-02-2008, 05:52 AM
Last Post: Trickster



Users browsing this thread: 1 Guest(s)