Skip to content

Commit

Permalink
Wait in keyboard simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
kitswas committed Jul 14, 2023
1 parent 67a8c6f commit acfde1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/simulation/keyboardSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ void pressKey(WORD key)
input.type = INPUT_KEYBOARD;
input.ki.wVk = key;
SendInput(1, &input, sizeof(INPUT));

// Wait
Sleep(PRESS_INTERVAL);
// Release the key
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &input, sizeof(INPUT));
Expand All @@ -20,6 +21,8 @@ void pressKeyCombo(std::vector<WORD> keys)
inputs[i].type = INPUT_KEYBOARD;
inputs[i].ki.wVk = keys[i];
}
// Wait
Sleep(PRESS_INTERVAL);
for (size_t i = 0; i < keys.size(); i++)
{
inputs[i + keys.size()].type = INPUT_KEYBOARD;
Expand Down
3 changes: 3 additions & 0 deletions src/simulation/keyboardSim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <string>
#include <vector>

// How long, in milliseconds, to wait between pressing and releasing a key
#define PRESS_INTERVAL 10

void pressKey(WORD key);
void pressKeyCombo(std::vector<WORD> keys);
void keyUp(WORD key);
Expand Down

0 comments on commit acfde1a

Please sign in to comment.