Skip to content

Commit

Permalink
Added "logging". will need development such as adding functions to pr…
Browse files Browse the repository at this point in the history
…int the logs and etc
  • Loading branch information
Noscka committed May 19, 2022
1 parent c766b48 commit 5b1866f
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 44 deletions.
56 changes: 51 additions & 5 deletions SWT/Features/Features.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "Features.h"
#include <iostream>

#pragma region Equation Region
bool EquationClass::Enabled = false;
char* EquationClass::InputStorageArray = new char[InputStorageArraySize]();
int EquationClass::InputStorageArrayIndexPointer = 0;
int EquationClass::InputStorageArraySize = 128;
int EquationClass::ArrayStep = 20;
bool EquationClass::AddToDynamicCharArray(char CharaterToAdd)
{
try
Expand All @@ -18,14 +20,14 @@ bool EquationClass::AddToDynamicCharArray(char CharaterToAdd)
TempArray[i] = InputStorageArray[i];
}

InputStorageArraySize += 20; // expand the Array size
InputStorageArraySize += ArrayStep; // expand the Array size
InputStorageArray = new char[InputStorageArraySize](); // over ride CharArray with new, bigger, array

/*
ArraySize-2 calculates TempArray size
Copy all values from Temp array to "old" expanded array
*/
for (int i = 0; i < InputStorageArraySize - 20; i++)
for (int i = 0; i < InputStorageArraySize - ArrayStep; i++)
{
InputStorageArray[i] = TempArray[i];
}
Expand All @@ -42,11 +44,14 @@ bool EquationClass::AddToDynamicCharArray(char CharaterToAdd)
}
return true;
}
#pragma endregion

#pragma region Auto Select Region
bool AutoSelectClass::Enabled = false;
char *AutoSelectClass::InputStorageArray = new char[InputStorageArraySize]();
int AutoSelectClass::InputStorageArrayIndexPointer = 0;
int AutoSelectClass::InputStorageArraySize = 128;
int AutoSelectClass::ArrayStep = 20;
bool AutoSelectClass::AddToDynamicCharArray(char CharaterToAdd)
{
try
Expand All @@ -60,14 +65,14 @@ bool AutoSelectClass::AddToDynamicCharArray(char CharaterToAdd)
TempArray[i] = InputStorageArray[i];
}

InputStorageArraySize += 20; // expand the Array size
InputStorageArraySize += ArrayStep; // expand the Array size
InputStorageArray = new char[InputStorageArraySize](); // over ride CharArray with new, bigger, array

/*
ArraySize-2 calculates TempArray size
Copy all values from Temp array to "old" expanded array
*/
for (int i = 0; i < InputStorageArraySize - 20; i++)
for (int i = 0; i < InputStorageArraySize - ArrayStep; i++)
{
InputStorageArray[i] = TempArray[i];
}
Expand All @@ -83,4 +88,45 @@ bool AutoSelectClass::AddToDynamicCharArray(char CharaterToAdd)
return false;
}
return true;
}
}
#pragma endregion

#pragma region Logging Region
char** LoggingClass::LoggingArray = new char*[LoggingArraySize];
int LoggingClass::LoggingArrayIndexPointer = 0;
int LoggingClass::LoggingArraySize = 8;
int LoggingClass::ArrayStep = 10;
bool LoggingClass::LogEvent(char* StringToAdd)
{
try
{
if (LoggingArrayIndexPointer >= LoggingArraySize)
{
char** TwoDimensionalTemp = new char* [LoggingArraySize](); // create temp pointer array of pointer arrays

for (int i = 0; i < LoggingArraySize; i++) // copy data
{
TwoDimensionalTemp[i] = LoggingArray[i];
}

LoggingArraySize += ArrayStep;
LoggingArray = new char* [LoggingArraySize](); // increase array

for (int i = 0; i < LoggingArraySize - ArrayStep; i++) // copy data back
{
LoggingArray[i] = TwoDimensionalTemp[i];
}

delete[] TwoDimensionalTemp; //delete array of temp
}

LoggingArray[LoggingArrayIndexPointer] = StringToAdd;
LoggingArrayIndexPointer++;
}
catch (...)
{
return false;
}
return true;
}
#pragma endregion
22 changes: 18 additions & 4 deletions SWT/Features/Features.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#pragma once
#include <string>

static class EquationClass
{
public:
static bool Enabled;

// InputStorageArray Char Array
static char* InputStorageArray;
static char* InputStorageArray; // Equation Char Array
static int InputStorageArraySize; // InputStorageArray Array Size
static int InputStorageArrayIndexPointer; // InputStorageArray Array Index Pointer
static int ArrayStep; // how much the array will get increased by when it reaches the limit

static bool AddToDynamicCharArray(char Character);
};
Expand All @@ -17,10 +19,22 @@ static class AutoSelectClass
public:
static bool Enabled;

// Auto Select Char Array
static char* InputStorageArray;
static char* InputStorageArray; // Auto Select Char Array
static int InputStorageArraySize; // InputStorageArray Array Size
static int InputStorageArrayIndexPointer; // Auto Select Array Index Pointer
static int ArrayStep; // how much the array will get increased by when it reaches the limit


static bool AddToDynamicCharArray(char Character);
};

static class LoggingClass
{
public:
static char** LoggingArray; // Logging Array Char Array
static int LoggingArraySize; // InputStorageArray Array Size
static int LoggingArrayIndexPointer; // Auto Select Array Index Pointer
static int ArrayStep; // how much the array will get increased by when it reaches the limit

static bool LogEvent(char Character[]);
};
71 changes: 36 additions & 35 deletions SWT/SWT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,25 +173,32 @@ LRESULT CALLBACK HookCallback(int nCode, WPARAM wParam, LPARAM lParam)

double EquationDoubleOutput = te_interp(EquationClass::InputStorageArray, 0); // intepret and solve the equation

std::cout << EquationClass::InputStorageArray << " = " << EquationDoubleOutput << "\n"; // display full equation with answer

// clear InputStorageArray array and zero Array Index Pointer
//std::fill(std::begin(EquationClass::InputStorageArray), std::end(EquationClass::InputStorageArray), NULL);
EquationClass::InputStorageArray = new char[EquationClass::InputStorageArraySize]();
EquationClass::InputStorageArrayIndexPointer = 0;
//std::cout << EquationClass::InputStorageArray << " = " << EquationDoubleOutput << "\n"; // display full equation with answer

// convert InputStorageArray Answer to string with removing trailing 0s
std::string EquationOutput = std::to_string(EquationDoubleOutput);
EquationOutput.erase(EquationOutput.find_last_not_of('0') + 1, std::string::npos);
EquationOutput.erase(EquationOutput.find_last_not_of('.') + 1, std::string::npos);

std::string temp = "Calculated " + std::string(EquationClass::InputStorageArray) + " = " + EquationOutput + '\n';
LoggingClass::LogEvent((char*)temp.c_str());

// clear InputStorageArray array and zero Array Index Pointer
EquationClass::InputStorageArray = new char[EquationClass::InputStorageArraySize]();
EquationClass::InputStorageArrayIndexPointer = 0;

// for loop for each character in equation answer and simulate keyboard event
for(char ch : EquationOutput)
{
keybd_event(VkKeyScanExA(ch, GetKeyboardLayout(0)), (UINT)kbdStruct.scanCode, 0, 0);
keybd_event(VkKeyScanExA(ch, GetKeyboardLayout(0)), (UINT)kbdStruct.scanCode, KEYEVENTF_KEYUP,0);
}

printf("====Logs====\n");
for (int i = 0; i < LoggingClass::LoggingArrayIndexPointer; i++)
{
printf(LoggingClass::LoggingArray[i]);
}
return -1;
}
}
Expand Down Expand Up @@ -245,44 +252,38 @@ LRESULT CALLBACK HookCallback(int nCode, WPARAM wParam, LPARAM lParam)

if (!StrInput.empty())
{
if (isNumber(StrInput)) // check if input string is just numbers
{
DirectionCount = std::stoi(StrInput);
if (!(DirectionCount < 0))
{
// clear Auto Select array and zero Array Index Pointer
//std::fill(std::begin(AutoSelectClass::InputStorageArray), std::end(AutoSelectClass::InputStorageArray), NULL);
AutoSelectClass::InputStorageArray = new char[AutoSelectClass::InputStorageArraySize]();
AutoSelectClass::InputStorageArrayIndexPointer = 0;

//keybd_event(VK_SHIFT, (UINT)kbdStruct.scanCode, 0, 0);

for (int i = 1; i <= DirectionCount; i++)
{
keybd_event(VK_RIGHT, (UINT)kbdStruct.scanCode, 0, 0);
keybd_event(VK_RIGHT, (UINT)kbdStruct.scanCode, KEYEVENTF_KEYUP, 0);
}

//keybd_event(VK_SHIFT, (UINT)kbdStruct.scanCode, KEYEVENTF_KEYUP, 0);

std::cout << "Moved " << DirectionCount << " Spaces Right" << std::endl;
}
else
{
printf("Input has to be a positive number");
}
}
else
DirectionCount = std::stoi(StrInput);
// clear Auto Select array and zero Array Index Pointer
AutoSelectClass::InputStorageArray = new char[AutoSelectClass::InputStorageArraySize]();
AutoSelectClass::InputStorageArrayIndexPointer = 0;

//keybd_event(VK_SHIFT, (UINT)kbdStruct.scanCode, 0, 0);

for (int i = 1; i <= DirectionCount; i++)
{
printf("Input has to be a interger\n");
keybd_event(VK_RIGHT, (UINT)kbdStruct.scanCode, 0, 0);
keybd_event(VK_RIGHT, (UINT)kbdStruct.scanCode, KEYEVENTF_KEYUP, 0);
}

//keybd_event(VK_SHIFT, (UINT)kbdStruct.scanCode, KEYEVENTF_KEYUP, 0);

//std::cout << "Moved " << DirectionCount << " Spaces Right" << std::endl;
}
else
{
printf("Input cannot be empty\n");
}

AutoSelectClass::Enabled = false;

std::string temp = "Moved " + std::to_string(DirectionCount) + " Spaces Right" + '\n';
LoggingClass::LogEvent((char*)temp.c_str());

printf("====Logs====\n");
for (int i = 0; i < LoggingClass::LoggingArrayIndexPointer; i++)
{
printf(LoggingClass::LoggingArray[i]);
}
return -1;
}

Expand Down

0 comments on commit 5b1866f

Please sign in to comment.