Skip to content

Commit

Permalink
Merge pull request #35 from hetulbhatt/develop
Browse files Browse the repository at this point in the history
Formatting and misc.
  • Loading branch information
hetulbhatt authored Aug 17, 2023
2 parents 4f39e48 + 2ef698b commit c2c03bf
Show file tree
Hide file tree
Showing 8 changed files with 723 additions and 722 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
build/*
src/*
!src/main.cpp
.vs
x64
KeyFlow/KeyFlow.vcxproj.user
KeyFlow/x64
KeyFlow/logs
28 changes: 14 additions & 14 deletions KeyFlow/KeyFlow.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "keyhook.hpp"

int main(int argc, char* argv[]) {
Logger::initialize();
Logger::log("OK!\n\n");
KeyHook& keyHook = KeyHookSingleton::getInstance();
FileLoader& fileLoader = keyHook.getKeystrokeHandler().getFileLoader();
if (argc == 3) {
fileLoader.loadFromFiles(argv[1], argv[2]);
}
else {
fileLoader.loadFromFiles();
}
keyHook.getKeystrokeHandler().resizeBuffer(fileLoader.getCodeLength());
keyHook.setup_hook();
Logger::shutdown();
return 0;
Logger::initialize();
Logger::log("OK!\n\n");
KeyHook& keyHook = KeyHookSingleton::getInstance();
FileLoader& fileLoader = keyHook.getKeystrokeHandler().getFileLoader();
if (argc == 3) {
fileLoader.loadFromFiles(argv[1], argv[2]);
}
else {
fileLoader.loadFromFiles();
}
keyHook.getKeystrokeHandler().resizeBuffer(fileLoader.getCodeLength());
keyHook.setup_hook();
Logger::shutdown();
return 0;
}
120 changes: 60 additions & 60 deletions KeyFlow/action_performer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,66 @@
class ActionPerformer
{
public:
ActionPerformer()
{
Logger::log("ActionPerformer()\n");
}

void simulate_paste(const std::string& stringToPaste)
{
// Get the handle of the active window
HWND activeWindow = GetForegroundWindow();

// Set the active window as the foreground window
SetForegroundWindow(activeWindow);

// Set up the datastructure
INPUT* inputs = new INPUT[stringToPaste.length() * 2];
memset(inputs, 0, stringToPaste.length() * 2 * sizeof(INPUT));

for (size_t i = 0; i < stringToPaste.length(); i++)
{
// Set up the INPUT structure for the character
inputs[i * 2].type = INPUT_KEYBOARD;
inputs[i * 2].ki.dwFlags = KEYEVENTF_UNICODE;
inputs[i * 2].ki.wScan = stringToPaste[i];

inputs[i * 2 + 1].type = INPUT_KEYBOARD;
inputs[i * 2 + 1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
inputs[i * 2 + 1].ki.wScan = stringToPaste[i];
}

// Send the input events to the active window
SendInput(stringToPaste.length() * 2, inputs, sizeof(INPUT));

delete[] inputs;
}

void execute_program(const std::string& path)
{
STARTUPINFOA startupInfo;
PROCESS_INFORMATION processInfo;

ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);

ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));

if (!CreateProcessA(NULL, const_cast<char*>(path.c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo))
{
std::cerr << "Failed to create process: " << GetLastError() << std::endl;
return;
}

// // Wait for the process to finish
// WaitForSingleObject(pi.hProcess, INFINITE);

// Close process and thread handles
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);

Logger::log("Process execution completed for: " + path + "\n");
}
ActionPerformer()
{
Logger::log("ActionPerformer()\n");
}

void simulate_paste(const std::string& stringToPaste)
{
// Get the handle of the active window
HWND activeWindow = GetForegroundWindow();

// Set the active window as the foreground window
SetForegroundWindow(activeWindow);

// Set up the datastructure
INPUT* inputs = new INPUT[stringToPaste.length() * 2];
memset(inputs, 0, stringToPaste.length() * 2 * sizeof(INPUT));

for (size_t i = 0; i < stringToPaste.length(); i++)
{
// Set up the INPUT structure for the character
inputs[i * 2].type = INPUT_KEYBOARD;
inputs[i * 2].ki.dwFlags = KEYEVENTF_UNICODE;
inputs[i * 2].ki.wScan = stringToPaste[i];

inputs[i * 2 + 1].type = INPUT_KEYBOARD;
inputs[i * 2 + 1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
inputs[i * 2 + 1].ki.wScan = stringToPaste[i];
}

// Send the input events to the active window
SendInput(stringToPaste.length() * 2, inputs, sizeof(INPUT));

delete[] inputs;
}

void execute_program(const std::string& path)
{
STARTUPINFOA startupInfo;
PROCESS_INFORMATION processInfo;

ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);

ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));

if (!CreateProcessA(NULL, const_cast<char*>(path.c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo))
{
std::cerr << "Failed to create process: " << GetLastError() << std::endl;
return;
}

// // Wait for the process to finish
// WaitForSingleObject(pi.hProcess, INFINITE);

// Close process and thread handles
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);

Logger::log("Process execution completed for: " + path + "\n");
}
};

#endif
Loading

0 comments on commit c2c03bf

Please sign in to comment.