Add GetAsyncKeyState

This commit is contained in:
Inori 2019-08-23 12:21:52 -04:00
parent 46f485a50a
commit 80e9291978
3 changed files with 24 additions and 1 deletions

View file

@ -63,6 +63,7 @@ MiniFFI_GetFunctionHandle(void *libhandle, const char *func)
CAPTURE(RtlMoveMemory);
CAPTURE(LoadLibrary);
CAPTURE(FreeLibrary);
CAPTURE(GetAsyncKeyState);
#endif
#endif
if (!libhandle) return 0;

View file

@ -55,7 +55,6 @@
// ===============================================================
#ifndef __WIN32__
#define m(vk,sc) { vk, SDL_SCANCODE_##sc }
#define n(vk) m(vk,-1)
std::map<int, int> vKeyToScancode{
// 0x01 LEFT MOUSE
// 0x02 RIGHT MOUSE
@ -411,4 +410,23 @@ MKXP_FreeLibrary(HMODULE hLibModule)
}
// Luckily, Essentials only cares about the high-order bit,
// so SDL's keystates will work perfectly fine
// Doesn't handle mouse clicks yet, but I'll do it later
PREFABI SHORT
MKXP_GetAsyncKeyState(int vKey)
{
SHORT result;
try {
result = shState->eThread().keyStates[vKeyToScancode[vKey]] << 15;
}
catch (...) {
result = 0;
}
return result;
}
#endif

View file

@ -16,6 +16,7 @@
#ifndef __WIN32__
typedef unsigned int DWORD, UINT, *LPDWORD;
typedef char *LPCSTR, *PBYTE;
typedef short SHORT;
typedef int LONG;
typedef bool BOOL;
typedef struct {
@ -104,4 +105,7 @@ MKXP_LoadLibrary(LPCSTR lpLibFileName);
PREFABI BOOL
MKXP_FreeLibrary(HMODULE hLibModule);
PREFABI SHORT
MKXP_GetAsyncKeyState(int vKey);
#endif