added a function to remotefortressreader.cpp to insert keyboard events

develop
Japa 2016-03-21 22:56:48 +05:30
parent 2f4a5e8449
commit 4d95395afc
2 changed files with 29 additions and 0 deletions

@ -470,4 +470,15 @@ message ScreenCapture
optional uint32 width = 1;
optional uint32 height = 2;
repeated ScreenTile tiles = 3;
}
message KeyboardEvent
{
optional uint32 type = 1;
optional uint32 which = 2;
optional uint32 state = 3;
optional uint32 scancode = 4;
optional uint32 sym = 5;
optional uint32 mod = 6;
optional uint32 unicode = 7;
}

@ -75,6 +75,9 @@
#include "modules/World.h"
#include "TileTypes.h"
#include "MiscUtils.h"
#include "Hooks.h"
#include "SDL_events.h"
#include "SDL_keyboard.h"
#include <vector>
#include <time.h>
@ -118,6 +121,7 @@ static command_result GetRegionMaps(color_ostream &stream, const EmptyMessage *i
static command_result GetCreatureRaws(color_ostream &stream, const EmptyMessage *in, CreatureRawList *out);
static command_result GetPlantRaws(color_ostream &stream, const EmptyMessage *in, PlantRawList *out);
static command_result CopyScreen(color_ostream &stream, const EmptyMessage *in, ScreenCapture *out);
static command_result PassKeyboardEvent(color_ostream &stream, const KeyboardEvent *in);
void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock, MapExtras::MapCache * MC, DFCoord pos);
@ -172,6 +176,7 @@ DFhackCExport RPCService *plugin_rpcconnect(color_ostream &)
svc->addFunction("GetWorldMapCenter", GetWorldMapCenter);
svc->addFunction("GetPlantRaws", GetPlantRaws);
svc->addFunction("CopyScreen", CopyScreen);
svc->addFunction("PassKeyboardEvent", PassKeyboardEvent);
return svc;
}
@ -2057,3 +2062,16 @@ static command_result CopyScreen(color_ostream &stream, const EmptyMessage *in,
return CR_OK;
}
static command_result PassKeyboardEvent(color_ostream &stream, const KeyboardEvent *in)
{
SDL::Event e;
e.key.type = in->type();
e.key.state = in->state();
e.key.ksym.mod = (SDL::Mod)in->mod();
e.key.ksym.scancode = in->scancode();
e.key.ksym.sym = (SDL::Key)in->sym();
e.key.ksym.unicode = in->unicode();
SDL_PushEvent(&e);
return CR_OK;
}