How to execute a common event from Javascript

Heyo! I'm putting together a simple plugin to let me map keyboard input to common events, but I'm struggling:

1. How do I call a common event from inside js? I know this is super basic, but I'm way rusty.
2. How do I find other ascii codes for keyboard input? the rpg_core.js stuff is pretty limited. I'm trying to map WASD and SHIFT + WASD

Thanks!
Hello!

1st question:
Try this:
$gameTemp.reserveCommonEvent(ID Common EVENT)

Example, common event 0003:
JavaScript:
$gameTemp.reserveCommonEvent(3)

Font:

2nd question:

More options in Google:

Good luck
Does appear to quite work. I'll keep fidding for now and come back if I can't figure it out. Currently, my code look like this:

] * @static * @property keyMapper * @type Object Input.keyMapper = { 199: 'slashUp', // lower w 97: 'slashLeft', // lower a 115: 'slashDown', // lower s 100: 'slashRight', // lower d 87: 'blockUp', // upper w 65: 'blockLeft', // upper a 83: 'blockDown', // upper s 68: 'blockRight', // upper d }; if (Input.isPressed('slashLeft')) { $gameTemp.reserveCommonEvent(15); };

EDIT: The plugin is enabled and I did include all the other Input.keyMapper lines from rpg_core.js. All the native common work fine, but the new lines don't seem to do anything.
that if isn't executing all the time, it runs once the plugin is loaded and thats it.

If you want the game to constantly verify if that input is pressed, you need to either place it inside a setInterval or make an alias to the scene_map update function and add your code there. Like this:


var keyconfig_alias = Scene_Map.prototype.updateScene; Scene_Map.prototype.updateScene = function() { keyconfig_alias.call(this); if (Input.isPressed('slashLeft')) { $gameTemp.reserveCommonEvent(15); }; }
Thanks! Sadly, this still isn't working. Here are screenshots of what I have. The plugin is active, but does nothing. It also isn't breaking anything.

When I triggered the common event 'slashLeft' by interacting with an enemy, it worked just fine. I fwas triggering the common event by flipping a switch called 'SlashingLeft.'
Instead of updateScene use just update. updateScene is only executed, if a scene change is requested.
It still isn't working. I wonder if the problem is with the core engine. I can't even get the console to open, for some reason. (I tried all the F keys, and '\' just in case, but no dice)

EDIT:
This works when 'ok' is triggered, but not when 'slashLeft' is triggered.
var keyconfig_alias = Scene_Map.prototype.update; Scene_Map.prototype.update = function() { keyconfig_alias.call(this); if (Input.isTriggered('slashLeft')) { SoundManager.playCursor(); $gameMessage.add("Hello World"); $gameTemp.reserveCommonEvent(15); }; }
Strange, when I use the 'blockLeft' condition it works, even without Shift or Capslock.
The Shift pressed condition has to be part of the code due to Capslock.
Weird. Also, it appears that remapping the keys isn't working at all. Even if I remap [32] into 'test', nothing happens. I'm definitely mapping the keys improperly.

EDIT:

JavaScript:
(function($) {
    $[87] = 'up';         // W
    $[65] = 'left';       // A
    $[83] = 'down';       // S
    $[68] = 'right';      // D
})(Input.keyMapper)

The above code successfuly lets me move with WASD keys, and...

JavaScript:
(function($) {
    $[87] = 'test';         // W
    $[65] = 'slashleft';       // A
    $[83] = 'test';       // S
    $[68] = 'test';      // D
})(Input.keyMapper)

var keyconfig_alias = Scene_Map.prototype.update;

Scene_Map.prototype.update = function() {
    keyconfig_alias.call(this);
    if (Input.isTriggered('slashleft')) {
        SoundManager.playCursor();
        $gameMessage.add("Hello World");
        $gameTemp.reserveCommonEvent(15);
    };
}

It looks like this is working just fine. However, DO NOT use capital letters in the keybind alias. It breaks for me, for some reason, if I do.
Please, use the BBCODE ICODE and CODE=Javascript:
BBCODE-ICODE1.png


However, DO NOT use capital letters in the keybind alias. It breaks for me, for some reason, if I do.
Take the test here, you should only consider the capital keys:
Javascript Key Event Test Script

You would need to create a separate mapping for key combinations.

But the most correct is to use the RPG_CORE function:
Shift: Input._currentState.shift
Control: Input._currentState.control

With this option it is not possible to differentiate left from right.
Out of curiosity I didn't find an option for the ALT Key.
I assume Shift key is for Dash and Ctrl key/Alt key is for Debug Mode to bypass the "walls" in the map.

Example:
Code:
◆If:Script:Input.isTriggered('ok') && Input._currentState.shift
  ◆Text:None, Window, Bottom
  :    :Shift + OK
  ◆
:End

Good luck!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-execute-a-common-event-from-javascript.141160/