Skip to content

Commit afc5c92

Browse files
authored
Add GetPressedKeys function (#242)
* Add GetPressedKeys function * Include mouse buttons in GetDisabledKeys
1 parent fa1ab4d commit afc5c92

4 files changed

Lines changed: 32 additions & 4 deletions

File tree

nvse/nvse/CommandTable.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,10 @@ void CommandTable::AddCommandsV6()
22672267
ADD_CMD_RET(GetDisabledKeys, kRetnType_Array);
22682268

22692269
ADD_CMD(ReloadPluginConfig);
2270+
2271+
// 6.4 beta 06
2272+
ADD_CMD_RET(GetPressedKeys, kRetnType_Array);
2273+
22702274
}
22712275

22722276
namespace PluginAPI

nvse/nvse/Commands_Input.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ bool Cmd_GetDisabledKeys_Execute(COMMAND_ARGS)
506506
*result = arr->ID();
507507
double arrIndex = 0;
508508

509-
for(UInt32 d = 0; d < 256; d++)
509+
for(UInt32 d = 0; d < kMaxMacros - 2; d++)
510510
{
511511
if(IsKeycodeValid(d) && DIHookControl::GetSingleton().IsKeyDisabled(d))
512512
{
@@ -519,6 +519,30 @@ bool Cmd_GetDisabledKeys_Execute(COMMAND_ARGS)
519519
}
520520

521521

522+
bool Cmd_GetPressedKeys_Execute(COMMAND_ARGS)
523+
{
524+
525+
UInt32 flags=0;
526+
527+
if(!ExtractArgs(EXTRACT_ARGS, &flags))
528+
return true;
529+
530+
ArrayVar *arr = g_ArrayMap.Create(kDataType_Numeric, true, scriptObj->GetModIndex());
531+
*result = arr->ID();
532+
double arrIndex = 0;
533+
534+
for(UInt32 d = 0; d < kMaxMacros - 2; d++)
535+
{
536+
if(IsKeycodeValid(d) && DIHookControl::GetSingleton().IsKeyPressed(d, flags))
537+
{
538+
arr->SetElementNumber(arrIndex, d);
539+
arrIndex += 1;
540+
}
541+
}
542+
543+
return true;
544+
}
545+
522546
#if RUNTIME
523547

524548
void Commands_Input_Init(void)

nvse/nvse/Commands_Input.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ DEFINE_COMMAND(IsControl, returns 1 if key is a game control or 2 if a custom co
3232
DEFINE_COMMAND(IsKeyDisabled, returns 1 if the key has been disabled by a script, 0, 1, kParams_OneInt);
3333
DEFINE_COMMAND(IsControlDisabled, returns 1 if the control has been disabled by a script, 0, 1, kParams_OneInt);
3434
DEFINE_CMD_COND(IsControlPressed, returns 1 if the control is pressed, 0, kParams_OneInt_OneOptionalInt);
35+
DEFINE_CMD(GetDisabledKeys, returns an array of all disabled key scancodes, 0, NULL);
36+
DEFINE_COMMAND(GetPressedKeys, returns an array of all pressed key scancodes, 0, 1, kParams_OneOptionalInt);
3537

3638
#undef DEFINE_INPUT
3739

nvse/nvse/Commands_Misc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,4 @@ static ParamInfo kNVSEParams_FireChallenge[] = {
103103
{ "Value 3", kNVSEParamType_Number, 0 }
104104
};
105105

106-
DEFINE_COMMAND_EXP(FireChallenge, Increment a challenge using specified params, 0, kNVSEParams_FireChallenge)
107-
108-
DEFINE_CMD(GetDisabledKeys, returns an array of all disabled key scancodes, 0, NULL);
106+
DEFINE_COMMAND_EXP(FireChallenge, Increment a challenge using specified params, 0, kNVSEParams_FireChallenge)

0 commit comments

Comments
 (0)