[RM2K3] [DYNRPG] SIMULATE KEYPRESS

Posts

Pages: 1
Hello!
I'm trying to make something akin to a point-and-click in 2003. I'm using Cherry's keyboard and mouse plugin, but I'd want to let my mouse be able to skip dialog when needed (so that the game is 100% mouse operated). In order to do this, I started using the SDK myself (I have absolutely zero knowledge of C++ in particular but oh well).

After a couple hours I came up with this:

#define AUTO_DLLMAIN
#include <DynRPG/DynRPG.h>

bool onComment(const char *text, const RPG::ParsedCommentData *parsedData,
RPG::EventScriptLine *nextScriptLine, RPG::EventScriptData *scriptData,
int eventId, int pageId, int lineId, int *nextLineId)
{
if(strcmp(parsedData->command, "simulatez") == 0)
{
keybd_event(VK_ESCAPE,0,0,0);
keybd_event(VK_ESCAPE,0,KEYEVENTF_KEYUP,0);
return false;
}
return true;
}


In this case I'm simulating vk_escape since it gives me a direct feedback of what I'm doing is working or not (menu opens if I'm doing it right, theoretically).

My problem: if I remove the second keybd_event the menu opens, but x\escape remain "stuck" until I press escape.
If I keep the second keybd (thus simulating a key tap) the menu doesn't open at all.

As for the game, it's just a test map with an event with a single comment @SimulateZ.
Out of curiousity, have you heard of Adventure Game Studio? It might be worth looking into if you're going to make an adventure game.

To answer your question, there's a number of ways you can do this for 2k3. This would simply simulate the keys:
#include <DynRPG/DynRPG.h>

bool onStartup (char *pluginName) {
configuration = RPG::loadConfiguration(pluginName);
confMouseInput = atoi(configuration["MouseInputSwitch"].c_str());

/* Add to DynRPG.ini:
[plugin_name]
MouseInputSwitch=1234
Change plugin_name to match filename of plugin dll without extension
Change MouseInputSwitch to whatever switch ID you want to use to enable/disable keypress checking
*/

return true;
}

void onFrame (RPG::Scene scene){
if (switches[confMouseInput]) { // IMPORTANT! This switch must be turned on in order to check for mouse clicks!
if (GetKeyState(VK_LBUTTON) & 0x8000) // Left mouse button
{
keybd_event(VK_RETURN,0,0,0);
keybd_event(VK_RETURN,0,KEYEVENTF_KEYUP,0);
}
else if (GetKeyState(VK_RBUTTON) & 0x8000) // Right mouse button
{
keybd_event(VK_ESCAPE,0,0,0);
keybd_event(VK_ESCAPE,0,KEYEVENTF_KEYUP,0);
}
else if (GetKeyState(VK_MBUTTON) & 0x8000) // Middle mouse button
{
keybd_event(VK_ESCAPE,0,0,0);
keybd_event(VK_ESCAPE,0,KEYEVENTF_KEYUP,0);
}
}
}

And this would turn on a switch each time you hit a mouse button, which might be more desirable since you could create your own menus/ui this way:
#include <DynRPG/DynRPG.h>

bool onStartup (char *pluginName) {
configuration = RPG::loadConfiguration(pluginName);
confMouseInput = atoi(configuration["MouseInputSwitch"].c_str());
confLButtonSwitch = atoi(configuration["LButtonSwitch"].c_str());
confRButtonSwitch = atoi(configuration["RButtonSwitch"].c_str());
confMButtonSwitch = atoi(configuration["MButtonSwitch"].c_str());

/* Add to DynRPG.ini:
[plugin_name]
MouseInputSwitch=1234
LButtonSwitch=1241
RButtonSwitch=1242
MButtonSwitch=1243
Change plugin_name to match filename of plugin dll without extension
Change MouseInputSwitch to whatever switch ID you want to use to enable/disable keypress checking
*/

return true;
}

void onFrame (RPG::Scene scene){
if (switches[confMouseInput]) { // IMPORTANT! This switch must be turned on in order to check for mouse clicks!
if (GetKeyState(VK_LBUTTON) & 0x8000) // Left mouse button
{
switches[confLButtonSwitch] = true;
}
else if (GetKeyState(VK_RBUTTON) & 0x8000) // Right mouse button
{
switches[confRButtonSwitch] = true;
}
else if (GetKeyState(VK_MBUTTON) & 0x8000) // Middle mouse button
{
switches[confMButtonSwitch] = true;
}
}
}
But... key bindings

void onInitFinished() {
( *reinterpret_cast<int ***> (0x4CDAEC) )[0][40] = 1;
}

There's about 4 unused/free key bindings for the [OK] keys.
32-39: Decision
32 = space
33 = return / enter
34 = none (for some reason)
35 = Z
36 = none
37 = none
38 = none
39 = none
I need to make the game in Rm2003. If I didn't have this restriction I'd use Game Maker.

Why doesn't the code I wrote work?

EDIT: Bugmenot's solution works too, but I'd still like to know why my snippet of code does not work.

EDIT: Weirdly enough, if I run the game from the Codeblocks IDE, it works flawlessly, but if I try starting the game from RpgMaker2003 or directly from the RPG_RT it tells me that "libgcc_s_dw2-1.dll" is missing and that the plug-in is invalid.

I just compiled Bugmenot's code.

#define AUTO_DLLMAIN
#include <DynRPG/DynRPG.h>

void onInitFinished() {
( *reinterpret_cast<int ***> (0x4CDAEC) )[0][40] = 1;
}
author=bugmenot
But... key bindings


Pssssshhhhhhh. Booo this man!

author=Annoyed_Grunt
I need to make the game in Rm2003. If I didn't have this restriction I'd use Game Maker.


Adventure Game Studio is neither though. It was designed for adventure games...

Why doesn't the code I wrote work?


I'm guessing it's how you're trying to call your comment. If you're forcing the menu open, it might interfere with the event script or something. Try calling it from a parallel process event of some kind.
Well Game Maker is designed for any kind of game :P. The point is that I'm making the game for a contest where only RpgMaker 2000\2003\VX\Ace are allowed, no other software.

EDIT: It doesn't matter what the plugin contains ( I also tried copy-pasting examples form Cherry's website) it will always say that I lack a DLL and that the plug-in is invalid if I run it from somewhere that is not codeblocks.
While we're on the topic of the key and mouse, is there a way to tweak it, possibly through the ini or c++ code, so that instead of selecting a point (which seems to happen, it selects the entire tile? I want to activate an event when mouse X is one thing, and Y is another, not X is between two and Y is between two. As in, there's a treasure chest on the roof of a building, you click on it and a character opens it with telekinesis.

Normally when I click, my mouse seems off center, and I need a range to even hit the event, event when clicking like crazy.

I can alter it myself, if I knew what to alter and how.
author=bulmabriefs144
While we're on the topic of the key and mouse, is there a way to tweak it, possibly through the ini or c++ code, so that instead of selecting a point (which seems to happen, it selects the entire tile? I want to activate an event when mouse X is one thing, and Y is another, not X is between two and Y is between two. As in, there's a treasure chest on the roof of a building, you click on it and a character opens it with telekinesis.

Normally when I click, my mouse seems off center, and I need a range to even hit the event, event when clicking like crazy.

I can alter it myself, if I knew what to alter and how.


If you are using Cherry's plug-in, take your Mouse X and Mouse Y variables and assign them to two other variables. Divide those by 16. Use Store Event ID with those coordinates. On mouse click, check if the stored event id is not zero, and if it is not, execute a Call Event to execute it.
The mouse X & Y might be the screen's X & Y though, so you might need to do something trickier than that.

author=Annoyed_Grunt
Well Game Maker is designed for any kind of game :P

Maybe I'm mis-understanding you here, but it sounds like you're confusing Adventure Game Studio with Game Maker. You can indeed make any kind of game with game maker, but Adventure Game Studio was designed specifically for adventure games, so it would be less work.

I can see why you'd want to do it in 2k3 for the contest though. What's the timeframe you have for it?
It'd be kind of hard to misunderstand GM for AGS, since I've been using Game Maker for the last five years!

Using AGS would not be less work as it's something I've never used while I'm pretty knowledgeable in Game Maker.

As for the time-frame, the deadline is July 11th.

EDIT: Anyway I just bundled the missing DLL with the game and it works now.
Pages: 1