Keyboard Input Module (Revised) - Printable Version +- Save-Point (https://www.save-point.org) +-- Forum: Material Development (https://www.save-point.org/forum-8.html) +--- Forum: Scripts Database (https://www.save-point.org/forum-39.html) +---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html) +---- Thread: Keyboard Input Module (Revised) (/thread-2776.html) |
Keyboard Input Module (Revised) - Near Fantastica - 03-02-2008 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] 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 |