RMMV If Mouseclick Then Press Z?

OgreLeg

Villager
Member
Joined
Nov 23, 2017
Messages
27
Reaction score
1
First Language
English
Primarily Uses
RMMV
I need a script call for a key input. I've scoured the forums, including that full script call page (which is crazy useful) but can't find this info anywhere.

Using conditional branch If TouchInput.isPressed(), how do I script call something like Input.isPressed("confirm")?

I'm running a parallel process that checks for mouse clicks but I want the mouse clicks to trigger a keyboard key. Nothing more, nothing less.

This is for a tool that shoots a projectile. I can shoot the projectile if I press Z or Spacebar. I want it to also be shot if I click a mouse button.
 

Hyouryuu-Na

Sapphire Sodium
Veteran
Joined
Jun 15, 2017
Messages
837
Reaction score
1,942
First Language
Not English
Primarily Uses
RMMV
Then you can just trigger the shooting of the projectile by checking for mouse clicks. Why tie it to a keyboard key?
It should be like if z key pressed OR mouse clicked: run projectile event.
Script:
JavaScript:
Input.keyMapper[90] = 'z'
if (Input.isTriggered('z') || TouchInput.isTriggered()){
    //common event script call or turn on switch to trigger common event. Upto you.
}
 
Last edited:

OgreLeg

Villager
Member
Joined
Nov 23, 2017
Messages
27
Reaction score
1
First Language
English
Primarily Uses
RMMV
I need it as I described it.

I am using a plugin that the author has asked not to modify in any way. The plugin works great when I keybind any keyboard key to "ok" or "confirm". I need the mouse click to trigger "ok" or "confirm" in the same way the keyboard does. It seemed the easiest way to accomplish that was to check for mouse click and then force an input.

I figured out the Input.keyMapper[] part but I can't figure out how to call a key press or set Input.isPressed("whatever") to "true".
 

Hyouryuu-Na

Sapphire Sodium
Veteran
Joined
Jun 15, 2017
Messages
837
Reaction score
1,942
First Language
Not English
Primarily Uses
RMMV
Afaik there's no way to force a key input. Besides, that seems unnecessarily complex to me. But I might be wrong and it could be possible.
 

OgreLeg

Villager
Member
Joined
Nov 23, 2017
Messages
27
Reaction score
1
First Language
English
Primarily Uses
RMMV
There must be a way. The conditional branch executes a check on the input and returns true or false right? Isn't there a way to skip the check and just return a true input?

Or is it possible to put the keyboard input and mouse input in an array that returns true for all if either is true?

Alternatively, is there a way to go into the RPG Maker JS files and make the mouse input trigger the 'ok' key instead?
 
Last edited:

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,572
Reaction score
875
First Language
Dutch
Primarily Uses
RMMV
if you cant modify the plugin in anyway, you can create an addon that override that
function and add
if (Input.isTriggered('z') || TouchInput.isTriggered()){
// code here
};

this way, you are NOT modifing the plugin in anyway, while you use a seperate plugin
that override the function in the plugin in the way you like ^^

Addon's are mostly safer than modifing the plugin, so you wont break it :)
 

OgreLeg

Villager
Member
Joined
Nov 23, 2017
Messages
27
Reaction score
1
First Language
English
Primarily Uses
RMMV
I'll give that a try ShadowDragon, thanks.

Also, I found this plugin >>> Keyboard Events - RPG Maker MV >>> so this is obviously doable.

//================================================================
// RS_KeyboardEvent.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2017 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
var Imported = Imported || {};
Imported.RS_KeyboardEvent = true;

/*:ko
* @plugindesc (v1.01) 수동으로 키보드 이벤트를 만들고 브라우저에 키보드 입력 이벤트를 보냅니다.
* @Author biud436
* @Help
* =============================================================================
* 소개
* ============================================================================= *
* 실제 키를 입력된 것처럼 가상의 키보드 입력 매크로를 만듭니다.
*
* =============================================================================
* 플러그인 커맨드
* =============================================================================
* - 'keyCode' 인자 값은 0x58 또는 80처럼 16진수 또는 10진수 값이여야 합니다.
* - 'keyName' 인자 값은 Input.keyMapper에서 찾을 수없는 문자열 값이어야 합니다.
*
* - 사용자가 Input 클래스의 주요 로직에 가상 키 코드를 보낼 수있게 하는 명령입니다.
* KeyEvent executeString keyName
* KeyEvent executeKey keyCode
*
* - 이 명령은 사용자가 Input 클래스에 새로운 가상 키 코드를 추가 할 수있게합니다.
* KeyEvent addNewKey keyCode keyName
*
* - 예제 코드는 다음과 같습니다.
* KeyEvent executeString left
* KeyEvent executeString escape
* KeyEvent executeKey 0x58
* KeyEvent addNewKey 0x50 p
* =============================================================================
* 스크립트 호출
* =============================================================================
* 두 가지 자바스크립트 함수가 있습니다.
*
* 함수는 Input 클래스의 주요 로직에 가상 키 코드를 보낼 수있게합니다.
*
* Input._makeKeyTiming(keyCode);
*
* 이 함수는 사용자가 Input 클래스에 새로운 가상 키 코드를 추가 할 수있게 합니다.
* Input 클래스의 keyMapper는 JSON 객체이며, 키와 값을 쌍으로 갖습니다.
*
* - 'keyCode' 인자 값은 0x58 또는 80처럼 16진수 또는 10진수 값이여야 합니다.
* - 'keyName' 인자 값은 Input.keyMapper에서 찾을 수없는 문자열 값이어야 합니다.
*
* 성공하면 키 값과 버튼의 이름을 담고 있는 JSON 객체가 콜백 함수에 전달됩니다.
*
* Input._executeJson(keyCode, keyName, func);
*
* - 다음은 예제 코드입니다.
* Input._makeKeyTiming('left');
* Input._makeKeyTiming('escape');
* Input._makeKeyTiming('down');
* Input._makeKeyTiming('control');
* Input._makeKeyTiming(116);
*
*
* 아래 콜백 함수의 첫 번째 인자 값 retObj은 {0x58: 'p'}입니다.
*
* Input._executeJson(0x58, 'p', function (retObj) {
* Object.assign(Input.keyMapper, retObj);
* });
*
* =============================================================================
* Change Log
* =============================================================================
* 2017.01.02 (v1.0.0) - First Release.
* 2017.03.03 (v1.0.1) - Added new function that can add new keyCode.
*/
/*:
* @plugindesc (v1.01) This plugin allows you to send keyboard input events manually.
* @Author biud436
* @Help
* =============================================================================
* Introduction
* ============================================================================= *
* This plugin can process a keyboard event without pressing a real button within a keyboard.
*
* =============================================================================
* Plugin Commands
* =============================================================================
* - 'keyCode' must be number type like as 0x58 or 80
* - 'keyName' should be the value for a strings that could not found in Input.keyMapper
*
* - These commands allow user to send a virtual key code in main logic of Input class.
* KeyEvent executeString keyName
* KeyEvent executeKey keyCode
*
* - This command allows user to add a new virtual key code in global Input class.
* KeyEvent addNewKey keyCode keyName
*
* - There are example codes at the next line.
* KeyEvent executeString left
* KeyEvent executeString escape
* KeyEvent executeKey 0x58
* KeyEvent addNewKey 0x50 p
* =============================================================================
* Script Calls
* =============================================================================
* Here's two javascript functions.
*
* - This function allows user to send a virtual key code in main logic of Input class.
*
* Input._makeKeyTiming(keyCode);
*
* - This function allows user to add a new virtual key code in global Input class.
* 'keyCode' must be number type like as 0x58 or 80
* 'keyName' should be the value for a strings that could not found in Input.keyMapper
* 'func' object has executed if JSON object is successfully created.
* The first parameter of the callback function is the JSON object that created at the caller.
*
* Input._executeJson(keyCode, keyName, func);
*
* - There are example codes at the next line.
* Input._makeKeyTiming('left');
* Input._makeKeyTiming('escape');
* Input._makeKeyTiming('down');
* Input._makeKeyTiming('control');
* Input._makeKeyTiming(116);
* Input._executeJson(0x58, 'p', function (retObj) {
* Object.assign(Input.keyMapper, retObj);
* });
* =============================================================================
* Change Log
* =============================================================================
* 2017.01.02 (v1.0.0) - First Release.
* 2017.03.03 (v1.0.1) - Added new function that can add new keyCode.
*/

(function() {

Input._startTime = 0;

Input._makeKeyEvent = function(type, keyCode) {
var isShift = Boolean(keyCode === 0x10);
var isCtrl = Boolean(keyCode === 0x11);
var isAlt = Boolean(keyCode === 0x12);
var evt = new KeyboardEvent(type, {bubbles:true, shiftKey: isShift, ctrlKey: isCtrl, altKey: isAlt});
Object.defineProperty(evt, 'keyCode', {get: function() {return keyCode;}});
document.dispatchEvent(evt);
};

/**
* Swap between key/value
* @param {String}
* @return {Number}
*/
Input._makeVirtualKey = function (keyCode) {
if(typeof keyCode === 'string') {
var tempMapper = [];
var vkCode = 0;
var mapper = JsonEx.makeDeepCopy(Input.keyMapper);
var length = Object.keys(mapper).length;
var keys = Object.keys(mapper);
for(var i =0; i < length; i++) {
tempMapper[mapper[keys]] = keys;
}
mapper = null;
vkCode = tempMapper[keyCode];
return vkCode;
}
};

Input._makeKeyTiming = function(keyCode) {
if(typeof keyCode === 'string') {
keyCode = this._makeVirtualKey(keyCode);
}
requestAnimationFrame(function(timestamp) {
Input._startTime = timestamp;
var progress = timestamp - Input._startTime;
Input._makeKeyEvent('keydown', keyCode);
if(progress < 2000) {
requestAnimationFrame(function() {
Input._makeKeyEvent('keyup', keyCode);
});
}
});
};

Input._executeJson = function (keyInt, keyName, func) {
var retObj, type, json;
json = {keyInt: keyName};
if(typeof json === 'object') retObj = JSON.parse(json);
if(retObj) {
type = Object.keys(retObj);
if(typeof type[0] === 'number') {
if(typeof func === 'function') func(retObj);
}
}
};

//============================================================================
// Game_Interpreter
//
//

var alias_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
alias_Game_Interpreter_pluginCommand.call(this, command, args);
if(command === "KeyEvent") {
switch (args[0]) {
case 'executeString':
var keyCode = Input._makeVirtualKey(args[1]) || 0;
Input._makeKeyTiming(keyCode);
break;
case 'executeKey':
var keyCode = parseInt(args[1] || 0);
Input._makeKeyTiming(keyCode);
break;
case 'addNewKey':
Input._executeJson(parseInt(args[1]), args[2], function (retObj) {
Object.assign(Input.keyMapper, retObj);
});
break;
}

}
};


})();

I would just use this fellow's plugin except it doesn't seem to work all that well. It will only execute a few times before it stops working but it does let you simulate keyboard inputs, so there must be a way.
 
Last edited:

OgreLeg

Villager
Member
Joined
Nov 23, 2017
Messages
27
Reaction score
1
First Language
English
Primarily Uses
RMMV
Surely someone knows something. Maybe someone could read this plugin code and at least point me in the right direction as to how they did it.
 

OgreLeg

Villager
Member
Joined
Nov 23, 2017
Messages
27
Reaction score
1
First Language
English
Primarily Uses
RMMV
Woot! I got it!

I was hoping to just script it out but I was able to get exactly what I needed by pairing biud436's Keyboard Event Plugin with CT_Bolt's Touch Input Plugin.

You've got to place the Keyboard Event's script call on both the down click and the up click otherwise it performs choppy but if you do it this way, it works flawlessly.

Force Key Input achieved!

If anyone knows the script call, though, I'm all ears. I don't mind using the plugins but I was hoping to learn something new.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Stream will be live shortly with some Darkest Dungeon! Feel free to drop by!
Made a HUGE (YYOOOOJJ) Update to Monstructs and moving towards a Steam Early Access release!
A skill type called: "Rumagic". The intention is Magic with Rum(that pirates drink)
Does it sound strange in English?
So I'm having issues with my steam account... so I can't use MZ right now, so I can't work on my game until its solved, so it be harder to be ready for 31... guess I'll get ice cream :kaopride:
Motivation! Inspiration! There you are. I was worried you guys weren't going to show up today. Let's get this thing going!

Forum statistics

Threads
104,219
Messages
1,004,759
Members
135,725
Latest member
Sark1017
Top