Chaos Project

RPG Maker => RPG Maker Scripts => RMMV Script Database => Topic started by: Crixus on April 08, 2019, 09:10:53 pm

Title: [MV] More keys to Conditions
Post by: Crixus on April 08, 2019, 09:10:53 pm
Keys Module
Authors: Crixus/RpgBoss
Version: 0.1
Type: Tool
Key Term: Scripting Tool



Introduction

There are three types of events for conditions with keyboard buttons.


Features




Screenshots

(https://img.youtube.com/vi/-IMNR-BI7Uw/hqdefault.jpg)

Video - How to use:
https://www.youtube.com/watch?v=-IMNR-BI7Uw

Video - First tests:
https://www.youtube.com/watch?v=XHRxAhbvfjQ


Demo
NONE



Script

Spoiler: ShowHide
//=============================================================================
// KeysModule.js
//=============================================================================

/*:
* @plugindesc More key options from If Conditions of Events
* Version: 0.1 - Beta
*
* @author Crixus (http://rpgmaker.000webhostapp.com)
*
* @help There are three types of events for conditions with keyboard buttons:
*
*  js_keyDown  - When you press the key, if holding the command will not
*                repeat, it will only happen once
*
*  js_keyPress - For key pressed, this works for all letters, digits and
*                calc keys, but does not work on others because they are
*                for the exclusive use of the Rpg Maker System
*               
*  js_keyUp    - This works after using the KeyDown, you do not need to
*                create a KeyDown condition, just hold the key for a short
*                time and release
*               
*  Here are the examples of how to use it, just like IF in Javascript for
*  browsers:
*
*  js_keyDown == "KeyJ"
*
*  js_keyUp == "Space"
*
*  js_keyPress == "KeyH"
*
*  If you need more examples of this system see the complete manual (help.html)
*
*
*  Veja abaixo a lista das teclas recomendadas:
*
*  Keys       Script     Pressed       |      Functions     Script     Pressed
*  [Up]       ArrowUp                  |      [F1]          F1
*  [Down]     ArrowDown                |      [F2] --------- Show FPS --------
*  [Left]     ArrowLeft                |      [F3] -- Responsive or Normal ---
*  [Right]    ArrowRight               |      [F4] -------- FullScreen -------
*  [Insert]   Insert                   |      [F5] -------- Goto Title -------
*  [Home]     Home                     |      [F6]          F6
*  [End]      End                      |      [F7]          F7
*  [Delete]   Delete                   |      [F8]          F8
*  [Ctrl]     CtrlLeft                 |      [F9]          F9
*  [Ctrl]     CtrlRight                |      [F10]         F10
*  [Shift]    ShiftLeft                |      [F11]         F11
*  [Shift]    ShiftRight               |      [F12]--- Console (Debug Mode) --
*  [Alt]      AltLeft                  |
*  [Alt]      AltRight                 |
*  [Esc]      Escape       (Yes)       |      Numbers       Script     Pressed
*  [Space]    Space                    |      [1]           Digit1     (Yes)
*  [Caps]     CapsLock                 |      [2]           Digit2     (Yes)
*  [PageUp]   PageUp                   |      [3]           Digit3     (Yes)
*  [PageDown] PageDown                 |      [4]           Digit4     (Yes)
*  [Enter]    Enter        (Yes)       |      [5]           Digit5     (Yes)
*                                      |      [6]           Digit6     (Yes)
*                                      |      [7]           Digit7     (Yes)
*  Letter     Script      Pressed      |      [8]           Digit8     (Yes)
*  [A]        KeyA         (Yes)       |      [9]           Digit9     (Yes)
*  [B]        KeyB         (Yes)       |      [0]           Digit0     (Yes)
*  [C]        KeyC         (Yes)       |      [-]           Minus      (Yes)
*  [D]        KeyD         (Yes)       |      [=]           Equal      (Yes)
*  [E]        KeyE         (Yes)       |
*  [F]        KeyF         (Yes)       |
*  [G]        KeyG         (Yes)       |      Numeric Pad   Script     Pressed
*  [H]        KeyH         (Yes)       |      [Num Lock]    NumLock     (Yes)
*  [I]        KeyI         (Yes)       |      [1]           Numpad1     (Yes)
*  [J]        KeyJ         (Yes)       |      [2]           Numpad2     (Yes)
*  [K]        KeyK         (Yes)       |      [3]           Numpad3     (Yes)
*  [L]        KeyL         (Yes)       |      [4]           Numpad4     (Yes)
*  [M]        KeyM         (Yes)       |      [5]           Numpad5     (Yes)
*  [N]        KeyN         (Yes)       |      [6]           Numpad6     (Yes)
*  [O]        KeyO         (Yes)       |      [7]           Numpad7     (Yes)
*  [P]        KeyP         (Yes)       |      [8]           Numpad8     (Yes)
*  [Q]        KeyQ         (Yes)       |      [9]           Numpad9     (Yes)
*  [R]        KeyR         (Yes)       |      [0]           Numpad0     (Yes)
*  [S]        KeyS         (Yes)       |      [-]           Subtract    (Yes)
*  [T]        KeyT         (Yes)       |      [+]           Add         (Yes)
*  [U]        KeyU         (Yes)       |      [*]           Multiply    (Yes)
*  [V]        KeyV         (Yes)       |      [/]           Divide      (Yes)
*  [W]        KeyW         (Yes)       |      [.]           Comma       (Yes)
*  [X]        KeyX         (Yes)       |      [,]           Decimal     (Yes)
*  [Y]        KeyY         (Yes)       |
*  [Z]        KeyZ         (Yes)       |
*                                      |
*                                      |
*  Others                              |
*  [P.Screen] PrintScreen (Only keyUp) |
*  [S.Lock]   ScrollLock               |
*  [Pause]    Pause                    |
*/

/*:pt
* @plugindesc Mais teclas para "Condições" de Eventos
* Versão: 0.1 - Beta (Testes)
*
* @author Crixus (http://rpgmaker.000webhostapp.com)
*
* @help Neste Plugin temos três tipos de condições de teclado:
*
*  js_keyDown  - Para quando aperta a tecla, se manter segurando o comando não
*                ficará em Loop, acontecerá apenas uma vez.
*
*  js_keyPress - Para tecla pressionada, este funciona para todas teclas de
*                letras, digitos e do teclado numérico, porém não funciona nas
*                outras por que são de uso exclusivo do sistema do Rpg Maker.
*               
*  js_keyUp    - E para caso a tecla seja solta, funciona após o uso do KeyDown
*                Não precisa criar uma Condição do KeyDown, basta segugar a
*                tecla correpondente por um curto tempo e soltar.
*               
*  Aqui segue os exemplos de como se deve usar, é exatamente como IF em
*  Javascript para navegadores de Internet:
*
*  js_keyDown == "KeyJ"
*
*  js_keyUp == "Space"
*
*  js_keyPress == "KeyH"
*
*  Se precisar de mais métodos deste sistema veja o manual completo (help.html).
*
*
*  Veja abaixo a lista das teclas recomendadas, todas foram testadas:
*
*  Teclas     Script     Pressed       |      Funções       Script     Pressed
*  [Up]       ArrowUp                  |      [F1]          F1
*  [Down]     ArrowDown                |      [F2] -------- Show FPS ---------
*  [Left]     ArrowLeft                |      [F3] --- Responsivo ou Normal --
*  [Right]    ArrowRight               |      [F4] ------- FullScreen --------
*  [Insert]   Insert                   |      [F5] ------- Goto Title --------
*  [Home]     Home                     |      [F6]          F6
*  [End]      End                      |      [F7]          F7
*  [Delete]   Delete                   |      [F8]          F8
*  [Ctrl]     CtrlLeft                 |      [F9]          F9
*  [Ctrl]     CtrlRight                |      [F10]         F10
*  [Shift]    ShiftLeft                |      [F11]         F11
*  [Shift]    ShiftRight               |      [F12] -- Console (Debug Mode) --
*  [Alt]      AltLeft                  |                                     
*  [Alt]      AltRight                 |                                     
*  [Esc]      Escape       (Sim)       |      Números       Script     Pressed
*  [Space]    Space                    |      [1]           Digit1     (Sim)
*  [Caps]     CapsLock                 |      [2]           Digit2     (Sim)
*  [PageUp]   PageUp                   |      [3]           Digit3     (Sim)
*  [PageDown] PageDown                 |      [4]           Digit4     (Sim)
*  [Enter]    Enter        (Sim)       |      [5]           Digit5     (Sim)
*                                      |      [6]           Digit6     (Sim)
*                                      |      [7]           Digit7     (Sim)
*  Letras     Script      Pressed      |      [8]           Digit8     (Sim)
*  [A]        KeyA         (Sim)       |      [9]           Digit9     (Sim)
*  [B]        KeyB         (Sim)       |      [0]           Digit0     (Sim)
*  [C]        KeyC         (Sim)       |      [-]           Minus      (Sim)
*  [D]        KeyD         (Sim)       |      [=]           Equal      (Sim)
*  [E]        KeyE         (Sim)       |                                     
*  [F]        KeyF         (Sim)       |                                     
*  [G]        KeyG         (Sim)       |      Calculadora   Script     Pressed
*  [H]        KeyH         (Sim)       |      [Num Lock]    NumLock     (Sim)
*  [I]        KeyI         (Sim)       |      [1]           Numpad1     (Sim)
*  [J]        KeyJ         (Sim)       |      [2]           Numpad2     (Sim)
*  [K]        KeyK         (Sim)       |      [3]           Numpad3     (Sim)
*  [L]        KeyL         (Sim)       |      [4]           Numpad4     (Sim)
*  [M]        KeyM         (Sim)       |      [5]           Numpad5     (Sim)
*  [N]        KeyN         (Sim)       |      [6]           Numpad6     (Sim)
*  [O]        KeyO         (Sim)       |      [7]           Numpad7     (Sim)
*  [P]        KeyP         (Sim)       |      [8]           Numpad8     (Sim)
*  [Q]        KeyQ         (Sim)       |      [9]           Numpad9     (Sim)
*  [R]        KeyR         (Sim)       |      [0]           Numpad0     (Sim)
*  [S]        KeyS         (Sim)       |      [-]           Subtract    (Sim)
*  [T]        KeyT         (Sim)       |      [+]           Add         (Sim)
*  [U]        KeyU         (Sim)       |      [*]           Multiply    (Sim)
*  [V]        KeyV         (Sim)       |      [/]           Divide      (Sim)
*  [W]        KeyW         (Sim)       |      [.]           Comma       (Sim)
*  [X]        KeyX         (Sim)       |      [,]           Decimal     (Sim)
*  [Y]        KeyY         (Sim)       |                                     
*  [Z]        KeyZ         (Sim)       |                                     
*                                      |                                     
*                                      |                                     
*  Outras                              |                                     
*  [P.Screen] PrintScreen (Only keyUp) |                                     
*  [S.Lock]   ScrollLock               |                                     
*  [Pause]    Pause                    |                                     
*/

var js_keyDown = false;
var js_keyPress = false;
var js_keyUp = false;

document.onkeydown = function(k){
if(js_keyDown == false){
js_keyDown = k.code;
console.log('js_keyDown: ' + js_keyDown);
setTimeout(function(){js_keyDown = true;},60);
}
}

document.onkeypress = function(k){
js_keyPress = k.code;
console.log('js_keyPress: ' + js_keyPress);
}

document.onkeyup = function(k){
js_keyDown = false;
js_keyPress = false;
js_keyUp = k.code;
console.log('js_keyUp: ' + js_keyUp);
setTimeout(function(){js_keyUp = false;},35);
}



Instructions
In the event command "Script" you must put the Global variable of your preference.

Here is an example of creating a keydown that will have a only action when pressed but may have another action when released.
Due to the "timer" the action will only occur if it is held for 0.4 seconds (40% of 1 second):
Quote
<>IF: Script : js_keyDown == "KeyJ"
   <>//Comment: Only Action
   <>
:END
<>IF: Script : js_keyUp == "KeyJ"
   <>//Comment: After Only Action - Optional
   <>
:END
<>


This is the best way to use a pressed key that loads some value or animation:
Quote
<>IF: Script : js_keyPress == "KeyH"
   <>//Comment: Charging Power
   <>
:END
<>


An example of Skill in map (ABS):
Quote
<>IF: Script : js_keyPress == "KeyH"
   <>Animation: ki-charging, Wait
   <>Op Variable: [xxxx:Kamehame-ha!] += 1
   <>
:Else
   <>IF: Variable[xxxx:Kamahame-ha!] >= 5
      <>Animation: Kamename-HA!!!!, Wait
      <>Op Variable: [xxxx:Kamehame-ha!] == 0
   :End
   <>
:End
<>

In GITHub you have the menu for tests of keyboad:
https://github.com/BossRpg/keys_module


Compatibility

None so far.


Credits and Thanks




Author's Notes

The system itself does not work perfectly with the standard Rpg Maker directional keys.
For more support:
Title: Re: MV - Plugin - More keys to Conditions
Post by: Blizzard on April 12, 2019, 08:09:02 am
Please use this template (https://forum.chaos-project.com/index.php/topic,17.0.html) so your script can appear properly in the Script Database (https://forum.chaos-project.com/index.php?action=script_database&rm=rmmv).
Title: Re: MV - Plugin - More keys to Conditions
Post by: Crixus on April 12, 2019, 05:34:15 pm
It was my mistake.
See if you agree with the model.
Title: Re: [MV] More keys to Conditions
Post by: Blizzard on April 16, 2019, 04:40:59 am
Just had to change the topic title and remove a key term (only one key term is supported) and now it works fine. :)
Title: Re: [MV] More keys to Conditions
Post by: Crixus on April 16, 2019, 11:17:19 am
Thank you.