Added a new return value to HOOK_KEYPRESS to override the pressed key (from Crafty)

Added check for map being loaded to KeyPress/MouseClick hooks.
This commit is contained in:
NovaRain
2018-10-28 08:51:01 +08:00
parent 9f689863d7
commit a3b456cf0a
4 changed files with 25 additions and 5 deletions
+3
View File
@@ -340,11 +340,14 @@ HOOK_KEYPRESS (hs_keypress.int)
Runs once every time when any key was pressed or released.
DX codes: (see dik.h header)
VK codes: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx
NOTE: if you want to override a key, the new key DX scancode should be the same for both pressed and released events.
int arg1 - event type: 1 - pressed, 0 - released
int arg2 - key DX scancode
int arg3 - key VK code (very similar to ASCII codes)
int ret1 - overrides the pressed key (a new key DX scancode or 0 for no override)
-------------------------------------------
HOOK_MOUSECLICK (hs_mouseclick.int)
+12 -2
View File
@@ -25,6 +25,7 @@
#include "FalloutEngine.h"
#include "HookScripts.h"
#include "Inventory.h"
#include "LoadGameHook.h"
#include "Logging.h"
#include "PartyControl.h"
#include "ScriptExtender.h"
@@ -761,18 +762,27 @@ void __declspec(naked) AmmoCostHookWrapper() {
}
}
void _stdcall KeyPressHook( DWORD dxKey, bool pressed, DWORD vKey )
{
DWORD _stdcall KeyPressHook(DWORD dxKey, bool pressed, DWORD vKey) {
if (!IsMapLoaded()) {
return 0;
}
DWORD result = 0;
BeginHook();
ArgCount = 3;
args[0] = (DWORD)pressed;
args[1] = dxKey;
args[2] = vKey;
RunHookScript(HOOK_KEYPRESS);
if (cRet != 0) dxKey = result = rets[0];
InventoryKeyPressedHook(dxKey, pressed, vKey);
EndHook();
return result;
}
void _stdcall MouseClickHook(DWORD button, bool pressed) {
if (!IsMapLoaded()) {
return;
}
BeginHook();
ArgCount = 2;
args[0] = (DWORD)pressed;
+1 -1
View File
@@ -63,5 +63,5 @@ void HookScriptClear();
extern DWORD InitingHookScripts;
extern void __declspec() AmmoCostHookWrapper();
void _stdcall MouseClickHook(DWORD button, bool pressed);
void _stdcall KeyPressHook(DWORD dxKey, bool pressed, DWORD vKey);
DWORD _stdcall KeyPressHook(DWORD dxKey, bool pressed, DWORD vKey);
void _stdcall RunHookScriptsAtProc(DWORD procId);
+9 -2
View File
@@ -257,12 +257,19 @@ public:
RunGlobalScripts2();
if (!b || bufferedPresses.empty() || (d&DIGDD_PEEK)) {
if (!b || bufferedPresses.empty() || (d & DIGDD_PEEK)) {
HRESULT hr = RealDevice->GetDeviceData(a, b, c, d);
if (FAILED(hr) || !b || !(*c)) return hr;
DWORD keyOverride, oldState;
for (DWORD i = 0; i < *c; i++) {
oldState = KeysDown[b[i].dwOfs];
KeysDown[b[i].dwOfs] = b[i].dwData & 0x80;
KeyPressHook(b[i].dwOfs, (b[i].dwData & 0x80) > 0, MapVirtualKeyEx(b[i].dwOfs, MAPVK_VSC_TO_VK, keyboardLayout));
keyOverride = KeyPressHook(b[i].dwOfs, (b[i].dwData & 0x80) > 0, MapVirtualKeyEx(b[i].dwOfs, MAPVK_VSC_TO_VK, keyboardLayout));
if (keyOverride != 0) {
KeysDown[b[i].dwOfs] = oldState;
b[i].dwOfs = keyOverride;
KeysDown[b[i].dwOfs] = b[i].dwData & 0x80;
}
}
if (KeysDown[DebugEditorKey]) RunDebugEditor();
return hr;