Skip to content

Commit

Permalink
Merge pull request #31 from hetulbhatt/develop
Browse files Browse the repository at this point in the history
MSVC and build changes
  • Loading branch information
hetulbhatt authored Jul 12, 2023
2 parents 024bf95 + 1c4c9f9 commit 4f39e48
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 72 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- build

jobs:
build:
Expand All @@ -24,14 +25,24 @@ jobs:
- name: Set up environment
run: echo "Running on Windows - ${{ matrix.architecture }}"

- uses: ilammy/msvc-dev-cmd@v1

# - name: Set up MSVC environment
# shell: cmd
# run: |
# call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

- name: Build
run: g++ -static -std=c++17 -I./include -o KeyFlow-${{ matrix.architecture }}.exe src/main.cpp
run: cl /EHsc KeyFlow\KeyFlow.cpp /link user32.lib /Fe:KeyFlow.exe

- name: Display structure of downloaded files
run: tree /f /a ..

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: KeyFlow-windows-${{ matrix.architecture }}-executable
path: KeyFlow-${{ matrix.architecture }}.exe
path: KeyFlow.exe

create_release:
needs: build
Expand All @@ -50,12 +61,12 @@ jobs:
path: workspace

- name: Display structure of downloaded files
run: tree .
run: tree /f /a ..

- name: Determine Alpha Version
id: determine_alpha_version
run: |
echo "::set-output name=ALPHA_VERSION::alpha.$(date +%Y%m%d).${{ github.run_number }}"
echo "::set-output name=ALPHA_VERSION::alpha.$(date +%Y%m%d).${{ github.run_number }}.msvc"
- name: Create Release
id: create_release
Expand All @@ -76,7 +87,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: workspace/KeyFlow-windows-x86-executable/KeyFlow-x86.exe
asset_path: workspace/KeyFlow-windows-x86-executable/KeyFlow.exe
asset_name: KeyFlow-x86.exe
asset_content_type: application/octet-stream

Expand All @@ -86,7 +97,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: workspace/KeyFlow-windows-x64-executable/KeyFlow-x64.exe
asset_path: workspace/KeyFlow-windows-x64-executable/KeyFlow.exe
asset_name: KeyFlow-x64.exe
asset_content_type: application/octet-stream

Expand All @@ -96,7 +107,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: workspace/KeyFlow-windows-ARM-executable/KeyFlow-ARM.exe
asset_path: workspace/KeyFlow-windows-ARM-executable/KeyFlow.exe
asset_name: KeyFlow-ARM.exe
asset_content_type: application/octet-stream

Expand All @@ -106,6 +117,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: workspace/KeyFlow-windows-ARM64-executable/KeyFlow-ARM64.exe
asset_path: workspace/KeyFlow-windows-ARM64-executable/KeyFlow.exe
asset_name: KeyFlow-ARM64.exe
asset_content_type: application/octet-stream
5 changes: 3 additions & 2 deletions src/main.cpp → KeyFlow/KeyFlow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../include/keyflow/keyhook.hpp"
#include "keyhook.hpp"

int main(int argc, char* argv[]) {
Logger::initialize();
Expand All @@ -7,7 +7,8 @@ int main(int argc, char* argv[]) {
FileLoader& fileLoader = keyHook.getKeystrokeHandler().getFileLoader();
if (argc == 3) {
fileLoader.loadFromFiles(argv[1], argv[2]);
} else {
}
else {
fileLoader.loadFromFiles();
}
keyHook.getKeystrokeHandler().resizeBuffer(fileLoader.getCodeLength());
Expand Down
146 changes: 146 additions & 0 deletions KeyFlow/KeyFlow.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{4b2f9e24-8657-49a8-adca-f94e0194b4b2}</ProjectGuid>
<RootNamespace>KeyFlow</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="KeyFlow.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="action_performer.hpp" />
<ClInclude Include="fileloader.hpp" />
<ClInclude Include="helper.hpp" />
<ClInclude Include="keyhook.hpp" />
<ClInclude Include="keystroke_handler.hpp" />
<ClInclude Include="logger.hpp" />
<ClInclude Include="systemtraymanager.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#ifndef ACTION_PERFORMER_H
#define ACTION_PERFORMER_H

Expand All @@ -15,7 +16,7 @@ class ActionPerformer
Logger::log("ActionPerformer()\n");
}

void simulate_paste(const std::string &stringToPaste)
void simulate_paste(const std::string& stringToPaste)
{
// Get the handle of the active window
HWND activeWindow = GetForegroundWindow();
Expand All @@ -24,7 +25,7 @@ class ActionPerformer
SetForegroundWindow(activeWindow);

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

for (size_t i = 0; i < stringToPaste.length(); i++)
Expand All @@ -45,16 +46,17 @@ class ActionPerformer
delete[] inputs;
}

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

ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);

if (!CreateProcess(NULL, const_cast<char *>(path.c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
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;
Expand All @@ -64,8 +66,8 @@ class ActionPerformer
// WaitForSingleObject(pi.hProcess, INFINITE);

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

Logger::log("Process execution completed for: " + path + "\n");
}
Expand Down
23 changes: 12 additions & 11 deletions include/keyflow/fileloader.hpp → KeyFlow/fileloader.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#ifndef FILELOADER_H
#define FILELOADER_H

Expand All @@ -24,22 +25,22 @@ class FileLoader
Logger::log("FileLoader()\n");
}

std::vector<std::pair<std::vector<int>, std::string>> &getDollarShortcuts()
std::vector<std::pair<std::vector<int>, std::string>>& getDollarShortcuts()
{
return this->dollar_shortcuts;
}

std::vector<std::pair<std::vector<int>, std::string>> &getColonShortcuts()
std::vector<std::pair<std::vector<int>, std::string>>& getColonShortcuts()
{
return this->colon_shortcuts;
}

std::unordered_map<std::string, std::string> &getDollarCodes()
std::unordered_map<std::string, std::string>& getDollarCodes()
{
return this->dollar_codes;
}

std::unordered_map<std::string, std::string> &getColonCodes()
std::unordered_map<std::string, std::string>& getColonCodes()
{
return this->colon_codes;
}
Expand Down Expand Up @@ -107,9 +108,9 @@ class FileLoader
}

Logger::log("Dollar Shortcuts:\n");
for (const auto &entry : dollar_shortcuts)
for (const auto& entry : dollar_shortcuts)
{
for (auto &num : entry.first)
for (auto& num : entry.first)
{
Logger::log(std::to_string(num) + ", ");
}
Expand All @@ -118,9 +119,9 @@ class FileLoader
Logger::log("\n");

Logger::log("Colon Shortcuts:\n");
for (const auto &entry : colon_shortcuts)
for (const auto& entry : colon_shortcuts)
{
for (auto &num : entry.first)
for (auto& num : entry.first)
{
Logger::log(std::to_string(num) + ", ");
}
Expand Down Expand Up @@ -151,7 +152,7 @@ class FileLoader
{
code_length = std::stoi(helper.trim(actual_length));
}
catch (const std::invalid_argument &e)
catch (const std::invalid_argument& e)
{
code_length = DEFAULT_CODE_LENGTH;
}
Expand Down Expand Up @@ -196,14 +197,14 @@ class FileLoader
}

Logger::log("Dollar Code:\n");
for (const auto &entry : dollar_codes)
for (const auto& entry : dollar_codes)
{
Logger::log(entry.first + " : " + entry.second + "\n");
}
Logger::log("\n");

Logger::log("Colon Code:\n");
for (const auto &entry : colon_codes)
for (const auto& entry : colon_codes)
{
Logger::log(entry.first + " : " + entry.second + "\n");
}
Expand Down
Loading

0 comments on commit 4f39e48

Please sign in to comment.