diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1ff0c42..0000000 --- a/.gitattributes +++ /dev/null @@ -1,63 +0,0 @@ -############################################################################### -# Set default behavior to automatically normalize line endings. -############################################################################### -* text=auto - -############################################################################### -# Set default behavior for command prompt diff. -# -# This is need for earlier builds of msysgit that does not have it on by -# default for csharp files. -# Note: This is only used by command line -############################################################################### -#*.cs diff=csharp - -############################################################################### -# Set the merge driver for project and solution files -# -# Merging from the command prompt will add diff markers to the files if there -# are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following -# file extensions to fail to load in VS. An alternative would be to treat -# these files as binary and thus will always conflict and require user -# intervention with every merge. To do so, just uncomment the entries below -############################################################################### -#*.sln merge=binary -#*.csproj merge=binary -#*.vbproj merge=binary -#*.vcxproj merge=binary -#*.vcproj merge=binary -#*.dbproj merge=binary -#*.fsproj merge=binary -#*.lsproj merge=binary -#*.wixproj merge=binary -#*.modelproj merge=binary -#*.sqlproj merge=binary -#*.wwaproj merge=binary - -############################################################################### -# behavior for image files -# -# image files are treated as binary by default. -############################################################################### -#*.jpg binary -#*.png binary -#*.gif binary - -############################################################################### -# diff behavior for common document formats -# -# Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the -# entries below. -############################################################################### -#*.doc diff=astextplain -#*.DOC diff=astextplain -#*.docx diff=astextplain -#*.DOCX diff=astextplain -#*.dot diff=astextplain -#*.DOT diff=astextplain -#*.pdf diff=astextplain -#*.PDF diff=astextplain -#*.rtf diff=astextplain -#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 52cba31..6856362 100644 --- a/.gitignore +++ b/.gitignore @@ -1,365 +1,6 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +build/ +IbInputSimulator.dll -*.dll - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Oo]ut/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory .vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +out/ +CMakeSettings.json \ No newline at end of file diff --git a/AhkDll.Ahk/v1/IbAhkSend.ahk b/AhkDll.Ahk/v1/IbAhkSend.ahk deleted file mode 100644 index 348f060..0000000 --- a/AhkDll.Ahk/v1/IbAhkSend.ahk +++ /dev/null @@ -1,76 +0,0 @@ -; IbAhkSendLib (v1) -; Description: Enable AHK to send keystrokes by drivers. -; Author: Chaoses Ib -; Version: 0.3 -; Git: https://github.com/Chaoses-Ib/IbAhkSendLib - -IbSendInit(send_type := "AnyDriver", mode := 1, args*){ - workding_dir := A_WorkingDir - SetWorkingDir, %A_ScriptDir% - - static hModule := DllCall("LoadLibrary", "Str", A_ScriptDir "\IbAhkSend.dll", "Ptr") - if (hModule == 0){ - if (A_PtrSize == 4) - throw "SendLibLoadFailed: Please use AutoHotkey x64" - else if (!FileExist("IbAhkSend.dll")) - throw "SendLibLoadFailed: Please put IbAhkSend.dll with your script file (or use AHK v2 instead, which can locate those DLLs that are put with the library files)" - else - throw "SendLibLoadFailed" - } - - if (send_type == "AnyDriver") - result := DllCall("IbAhkSend\IbSendInit", "Int", 0, "Int", 0, "Ptr", 0, "Int") - else if (send_type == "SendInput") - result := DllCall("IbAhkSend\IbSendInit", "Int", 1, "Int", 0, "Ptr", 0, "Int") - else if (send_type == "Logitech") - result := DllCall("IbAhkSend\IbSendInit", "Int", 2, "Int", 0, "Ptr", 0, "Int") - else if (send_type == "Razer") - result := DllCall("IbAhkSend\IbSendInit", "Int", 3, "Int", 0, "Ptr", 0, "Int") - else if (send_type == "DD"){ - if (args.MaxIndex() == 1) - result := DllCall("IbAhkSend\IbSendInit", "Int", 4, "Int", 0, "WStr", args[1], "Int") - else - result := DllCall("IbAhkSend\IbSendInit", "Int", 4, "Int", 0, "Ptr", 0, "Int") - } else - throw "Invalid send type" - - SetWorkingDir, %workding_dir% - - if (result != 0){ - error_text := ["InvalidArgument", "LibraryNotFound", "LibraryLoadFailed", "LibraryError", "DeviceCreateFailed", "DeviceNotFound", "DeviceOpenFailed"] - throw error_text[result] - } - - if (mode != 0){ - IbSendMode(mode) - } -} - -IbSendMode(mode){ - static ahk_mode := "" - if (mode == 1){ - DllCall("IbAhkSend\IbSendInputHook", "Int", 1) - ahk_mode := A_SendMode - SendMode Input - } else if (mode == 0){ - SendMode %ahk_mode% - DllCall("IbAhkSend\IbSendInputHook", "Int", 0) - } else { - throw "Invalid send mode" - } -} - -IbSendDestroy(){ - DllCall("IbAhkSend\IbSendDestroy") - ;DllCall("FreeLibrary", "Ptr", hModule) -} - -IbSyncKeyStates(){ - DllCall("IbAhkSend\IbSendSyncKeyStates") -} - -IbSend(keys){ - DllCall("IbAhkSend\IbSendInputHook", "Int", 1) ;or IbSendMode(1) - SendInput %keys% - DllCall("IbAhkSend\IbSendInputHook", "Int", 0) ;or IbSendMode(0) -} \ No newline at end of file diff --git a/AhkDll.Ahk/v1/test/type Logitech.ahk b/AhkDll.Ahk/v1/test/type Logitech.ahk deleted file mode 100644 index a0ea735..0000000 --- a/AhkDll.Ahk/v1/test/type Logitech.ahk +++ /dev/null @@ -1,4 +0,0 @@ -#Include %A_ScriptDir% -#Include ..\IbAhkSend.ahk -IbSendInit("Logitech") -#include mode ahk.ahk \ No newline at end of file diff --git a/AhkDll.Ahk/v1/test/type Razer.ahk b/AhkDll.Ahk/v1/test/type Razer.ahk deleted file mode 100644 index e6a4796..0000000 --- a/AhkDll.Ahk/v1/test/type Razer.ahk +++ /dev/null @@ -1,4 +0,0 @@ -#Include %A_ScriptDir% -#Include ..\IbAhkSend.ahk -IbSendInit("Razer") -#include mode ahk.ahk \ No newline at end of file diff --git a/AhkDll.Ahk/v1/test/type SendInput.ahk b/AhkDll.Ahk/v1/test/type SendInput.ahk deleted file mode 100644 index 3ac4356..0000000 --- a/AhkDll.Ahk/v1/test/type SendInput.ahk +++ /dev/null @@ -1,4 +0,0 @@ -#Include %A_ScriptDir% -#Include ..\IbAhkSend.ahk -IbSendInit("SendInput") -#include mode ahk.ahk \ No newline at end of file diff --git a/AhkDll.Ahk/v2/test/type Logitech.ahk b/AhkDll.Ahk/v2/test/type Logitech.ahk deleted file mode 100644 index 01464d9..0000000 --- a/AhkDll.Ahk/v2/test/type Logitech.ahk +++ /dev/null @@ -1,3 +0,0 @@ -#Include "..\IbAhkSend.ahk" -IbSendInit("Logitech") -#include "mode ahk.ahk" \ No newline at end of file diff --git a/AhkDll.Ahk/v2/test/type Razer.ahk b/AhkDll.Ahk/v2/test/type Razer.ahk deleted file mode 100644 index 910fb02..0000000 --- a/AhkDll.Ahk/v2/test/type Razer.ahk +++ /dev/null @@ -1,3 +0,0 @@ -#Include "..\IbAhkSend.ahk" -IbSendInit("Razer") -#include "mode ahk.ahk" \ No newline at end of file diff --git a/AhkDll.Ahk/v2/test/type SendInput.ahk b/AhkDll.Ahk/v2/test/type SendInput.ahk deleted file mode 100644 index 0385f7e..0000000 --- a/AhkDll.Ahk/v2/test/type SendInput.ahk +++ /dev/null @@ -1,3 +0,0 @@ -#Include "..\IbAhkSend.ahk" -IbSendInit("SendInput") -#include "mode ahk.ahk" \ No newline at end of file diff --git a/AhkDll.Test/AhkDll.Test.vcxproj b/AhkDll.Test/AhkDll.Test.vcxproj deleted file mode 100644 index 2b46c66..0000000 --- a/AhkDll.Test/AhkDll.Test.vcxproj +++ /dev/null @@ -1,174 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {f5aa5311-dd5f-43f8-805a-d0f4bb19d32f} - AhkDllTest - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - - - false - - - x64-windows-static-md - - - x64-windows-static-md - - - x86-windows-static-md - - - x86-windows-static-md - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdcpplatest - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdcpplatest - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdcpplatest - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdcpplatest - - - Console - true - true - true - - - - - - - - {a8cc7e86-6e3f-4c18-bf47-f6aaf0afefa9} - - - - - - - - - - - - \ No newline at end of file diff --git a/AhkDll.Test/AhkDll.Test.vcxproj.filters b/AhkDll.Test/AhkDll.Test.vcxproj.filters deleted file mode 100644 index b8ccd0f..0000000 --- a/AhkDll.Test/AhkDll.Test.vcxproj.filters +++ /dev/null @@ -1,27 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - - - Header Files - - - \ No newline at end of file diff --git a/AhkDll/AhkDll.vcxproj b/AhkDll/AhkDll.vcxproj deleted file mode 100644 index 39fa493..0000000 --- a/AhkDll/AhkDll.vcxproj +++ /dev/null @@ -1,197 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {a8cc7e86-6e3f-4c18-bf47-f6aaf0afefa9} - AhkDll - 10.0 - - - - DynamicLibrary - true - v142 - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - - DynamicLibrary - true - v142 - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - IbAhkSend - - - false - IbAhkSend - - - true - IbAhkSend - - - false - IbAhkSend - - - x64-windows-static-md - - - x64-windows-static-md - - - - Level3 - true - IB_AHKSEND_DLLEXPORT;WIN32;_DEBUG;AHKDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - stdcpplatest - - - Windows - true - false - - - - - Level3 - true - true - true - IB_AHKSEND_DLLEXPORT;WIN32;NDEBUG;AHKDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - stdcpplatest - - - Windows - true - true - true - false - - - - - Level3 - true - IB_AHKSEND_DLLEXPORT;_DEBUG;AHKDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - stdcpplatest - - - Windows - true - false - - - - - Level3 - true - true - true - IB_AHKSEND_DLLEXPORT;NDEBUG;AHKDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - stdcpplatest - - - Windows - true - true - true - false - - - - - - - - - - - - - - - - - - - - - Create - Create - Create - Create - - - - - - - - - \ No newline at end of file diff --git a/AhkDll/AhkDll.vcxproj.filters b/AhkDll/AhkDll.vcxproj.filters deleted file mode 100644 index c584ac8..0000000 --- a/AhkDll/AhkDll.vcxproj.filters +++ /dev/null @@ -1,69 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {229d1540-5c12-4cc0-b2c5-98a5630b8472} - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files\SendTypes - - - Header Files\SendTypes - - - Header Files\SendTypes - - - Header Files\SendTypes - - - Header Files\SendTypes - - - Header Files\SendTypes - - - Header Files\SendTypes - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/AhkDll/SendTypes/Razer.hpp b/AhkDll/SendTypes/Razer.hpp deleted file mode 100644 index 7ae3ad6..0000000 --- a/AhkDll/SendTypes/Razer.hpp +++ /dev/null @@ -1,182 +0,0 @@ -#pragma once -#include "Base.hpp" -#include "Usb.hpp" - -namespace Send::Type::Internal { - class Razer final : virtual public Base, public VirtualKeyStates { - HANDLE device; - - KeyboardModifiers modifiers; - std::mutex keyboard_mutex; - public: - Razer() : VirtualKeyStates(modifiers, keyboard_mutex) {} - - Error create() { - std::wstring device_name = find_device([](std::wstring_view sv) { - using namespace std::literals; - - //RZCONTROL#VID_1532&PID_0306&MI_00#3&1c65d7f8&0#{e3be005d-d130-4910-88ff-09ae02f680e9} - return sv.starts_with(L"RZCONTROL#"sv) && sv.ends_with(L"#{e3be005d-d130-4910-88ff-09ae02f680e9}"sv); - }); - if (device_name.empty()) - return Error::DeviceNotFound; - - device = CreateFileW( - device_name.c_str(), - GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - OPEN_EXISTING, 0, NULL - ); - if (device == INVALID_HANDLE_VALUE) - return Error::DeviceOpenFailed; - - return Error::Success; - } - - void destroy() override { - CloseHandle(device); - } - - struct RzControl { - uint32_t unk1; - enum class Type : uint32_t { - Keyboard = 1, - Mouse = 2 - } type; - union { - struct { - uint32_t absolute_coord; - struct { - bool LButtonDown : 1; - bool LButtonUp : 1; - bool RButtonDown : 1; - bool RButtonUp : 1; - bool MButtonDown : 1; - bool MButtonUp : 1; - bool XButton1Down : 1; - bool XButton1Up : 1; - bool XButton2Down : 1; - bool XButton2Up : 1; - bool Wheel : 1; - bool HWheel : 1; - uint8_t unk : 4; - private: - void assert_size() { - static_assert(sizeof(*this) == 2); - } - } btn; - int16_t movement; - uint32_t unk1; - int32_t x; - int32_t y; - uint32_t unk2; - } mi; - struct { - uint16_t unk1; - int16_t key; - uint16_t action; - uint16_t unk2; - uint32_t unk3; - uint32_t unk4; - uint32_t unk5; - uint32_t unk6; - } ki; - }; - private: - void assert_size() { - static_assert(sizeof RzControl == 32); - } - }; - - bool send_mouse_input(const MOUSEINPUT& mi) override { - RzControl control{ .type = RzControl::Type::Mouse }; - - if (mi.dwFlags & MOUSEEVENTF_MOVE) { - POINT move{ mi.dx, mi.dy }; - if (mi.dwFlags & MOUSEEVENTF_ABSOLUTE) { - control.mi.absolute_coord = 0x10000; - } - control.mi.x = mi.dx; - control.mi.y = mi.dy; - } - -#define CODE_GENERATE(down, up, member) \ - control.mi.btn.##member##Down = mi.dwFlags & down; \ - control.mi.btn.##member##Up = mi.dwFlags & up; - - CODE_GENERATE(MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, LButton) //#TODO: may be switched? - CODE_GENERATE(MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP, RButton) - CODE_GENERATE(MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP, MButton) -#undef CODE_GENERATE - if (mi.dwFlags & MOUSEEVENTF_XDOWN) { - switch (mi.mouseData) { - case XBUTTON1: control.mi.btn.XButton1Down = 1; break; - case XBUTTON2: control.mi.btn.XButton2Down = 1; break; - } - } else if (mi.dwFlags & MOUSEEVENTF_XUP) { - switch (mi.mouseData) { - case XBUTTON1: control.mi.btn.XButton1Up = 1; break; - case XBUTTON2: control.mi.btn.XButton2Up = 1; break; - } - } else if (mi.dwFlags & MOUSEEVENTF_WHEEL || mi.dwFlags & MOUSEEVENTF_HWHEEL) { - if (mi.dwFlags & MOUSEEVENTF_WHEEL) - control.mi.btn.Wheel = 1; - else - control.mi.btn.HWheel = 1; - control.mi.movement = 120 * std::bit_cast(mi.mouseData); //#TODO - } - - if constexpr (debug) - DebugOStream() << L"send_mouse_input: " << *(uint16_t*)&control.mi.btn << L", (" << control.mi.x << L", " << control.mi.y << L") " << control.mi.absolute_coord << std::endl; - - DWORD bytes_returned; - return DeviceIoControl(device, 0x88883020, &control, sizeof control, nullptr, 0, &bytes_returned, nullptr); - } - - bool send_keyboard_input(const KEYBDINPUT& ki) override { - RzControl control{ .type = RzControl::Type::Keyboard }; - - if ((control.ki.key = keyboard_vk_to_key(ki.wVk)) < 0) - return false; - - std::lock_guard lock(keyboard_mutex); - - bool keydown = !(ki.dwFlags & KEYEVENTF_KEYUP); - if (is_modifier(ki.wVk)) - set_modifier_state(ki.wVk, keydown); - - if (ki.wVk == VK_LWIN || ki.wVk == VK_RWIN) //#TODO: Any other keys? - control.ki.action = keydown ? 2 : 3; - else - control.ki.action = keydown ? 0 : 1; - - if constexpr (debug) - DebugOStream() << L"send_keyboard_input: " << control.ki.key << ", " << control.ki.action << std::endl; - - DWORD bytes_returned; - return DeviceIoControl(device, 0x88883020, &control, sizeof control, nullptr, 0, &bytes_returned, nullptr); - } - - int16_t keyboard_vk_to_key(uint8_t vk) { - if constexpr (debug) - DebugOStream() << L"keyboard_vk_to_key: " << vk << L" -> " << Usb::keyboard_vk_to_usage(vk) << L" -> " << keyboard_usage_to_key(Usb::keyboard_vk_to_usage(vk)) << std::endl; - return keyboard_usage_to_key(Usb::keyboard_vk_to_usage(vk)); - } - - // RCtrl and RAlt will be treated as left ones. - constexpr int16_t keyboard_usage_to_key(uint16_t usage_id) { - if (usage_id <= 115) { - constexpr uint16_t table[] = { -1, 255, 252, -3, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26, 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 87, 88, 55, 70, 29, 82, 71, 73, 83, 79, 81, 77, 75, 80, 72, 69, 53, 55, 74, 78, 28, 79, 80, 81, 75, 76, 77, 71, 72, 73, 82, 83, 86, 93, 94, 89, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 118, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 94, 95, 99, -3, 126, -3, 115, 112, 125, 121, 123, 92, -3, -3, -3, 242, 241, 120, 119, 118 }; - return table[usage_id]; - } else if (181 <= usage_id && usage_id <= 183) { - constexpr uint16_t table[] = { 25,16,36 }; - return table[usage_id - 181]; - } else if (usage_id == 205) - return 34; - else if (224 <= usage_id && usage_id <= 234) { - constexpr uint16_t table[] = { 29, 42, 56, 91, 29, 54, 56, 92, -2, 48, 46 }; - return table[usage_id - 224]; - } - return -1; - } - }; -} \ No newline at end of file diff --git a/AhkDll/framework.h b/AhkDll/framework.h deleted file mode 100644 index f80ad8f..0000000 --- a/AhkDll/framework.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -// Windows Header Files -#include diff --git a/AhkDll/pch.cpp b/AhkDll/pch.cpp deleted file mode 100644 index 64b7eef..0000000 --- a/AhkDll/pch.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// pch.cpp: source file corresponding to the pre-compiled header - -#include "pch.h" - -// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/AhkDll/pch.h b/AhkDll/pch.h deleted file mode 100644 index 885d5d6..0000000 --- a/AhkDll/pch.h +++ /dev/null @@ -1,13 +0,0 @@ -// pch.h: This is a precompiled header file. -// Files listed below are compiled only once, improving build performance for future builds. -// This also affects IntelliSense performance, including code completion and many code browsing features. -// However, files listed here are ALL re-compiled if any one of them is updated between builds. -// Do not add files here that you will be updating frequently as this negates the performance advantage. - -#ifndef PCH_H -#define PCH_H - -// add headers that you want to pre-compile here -#include "framework.h" - -#endif //PCH_H diff --git a/Binding.AHK1/IbInputSimulator.ahk b/Binding.AHK1/IbInputSimulator.ahk new file mode 100644 index 0000000..5d6ef8f --- /dev/null +++ b/Binding.AHK1/IbInputSimulator.ahk @@ -0,0 +1,80 @@ +; IbInputSimulator (v1) +; Description: Enable AHK to send keystrokes by drivers. +; Author: Chaoses Ib +; Version: 0.4 +; Git: https://github.com/Chaoses-Ib/IbInputSimulator + +IbSendInit(send_type := "AnyDriver", mode := 1, args*){ + workding_dir := A_WorkingDir + SetWorkingDir, %A_ScriptDir% + + static hModule := DllCall("LoadLibrary", "Str", A_ScriptDir "\IbInputSimulator.dll", "Ptr") + if (hModule == 0){ + if (A_PtrSize == 4) + throw "SendLibLoadFailed: Please use AutoHotkey x64" + else if (!FileExist("IbInputSimulator.dll")) + throw "SendLibLoadFailed: Please put IbInputSimulator.dll with your script file (or use AHK v2 instead, which can locate those DLLs that are put with the library files)" + else + throw "SendLibLoadFailed: " A_LastError + } + + if (send_type == "AnyDriver") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 0, "Int", 0, "Ptr", 0, "Int") + else if (send_type == "SendInput") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 1, "Int", 0, "Ptr", 0, "Int") + else if (send_type == "Logitech") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 2, "Int", 0, "Ptr", 0, "Int") + else if (send_type == "Razer") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 3, "Int", 0, "Ptr", 0, "Int") + else if (send_type == "DD"){ + if (args.MaxIndex() == 1) + result := DllCall("IbInputSimulator\IbSendInit", "Int", 4, "Int", 0, "WStr", args[1], "Int") + else + result := DllCall("IbInputSimulator\IbSendInit", "Int", 4, "Int", 0, "Ptr", 0, "Int") + } else if (send_type == "MouClassInputInjection"){ + if (args.MaxIndex() != 1) + throw "MouClassInputInjection: Please specify the process ID of the target process" + result := DllCall("IbInputSimulator\IbSendInit", "Int", 5, "Int", 0, "UInt64", args[1], "Int") + } else + throw "Invalid send type" + + SetWorkingDir, %workding_dir% + + if (result != 0){ + error_text := ["InvalidArgument", "LibraryNotFound", "LibraryLoadFailed", "LibraryError", "DeviceCreateFailed", "DeviceNotFound", "DeviceOpenFailed"] + throw error_text[result] + } + + if (mode != 0){ + IbSendMode(mode) + } +} + +IbSendMode(mode){ + static ahk_mode := "" + if (mode == 1){ + DllCall("IbInputSimulator\IbSendInputHook", "Int", 1) + ahk_mode := A_SendMode + SendMode Input + } else if (mode == 0){ + SendMode %ahk_mode% + DllCall("IbInputSimulator\IbSendInputHook", "Int", 0) + } else { + throw "Invalid send mode" + } +} + +IbSendDestroy(){ + DllCall("IbInputSimulator\IbSendDestroy") + ;DllCall("FreeLibrary", "Ptr", hModule) +} + +IbSyncKeyStates(){ + DllCall("IbInputSimulator\IbSendSyncKeyStates") +} + +IbSend(keys){ + DllCall("IbInputSimulator\IbSendInputHook", "Int", 1) ;or IbSendMode(1) + SendInput %keys% + DllCall("IbInputSimulator\IbSendInputHook", "Int", 0) ;or IbSendMode(0) +} \ No newline at end of file diff --git a/AhkDll.Ahk/v1/test/KeyHistory.ahk b/Binding.AHK1/test/KeyHistory.ahk similarity index 100% rename from AhkDll.Ahk/v1/test/KeyHistory.ahk rename to Binding.AHK1/test/KeyHistory.ahk diff --git a/AhkDll.Ahk/v1/test/mode 0.ahk b/Binding.AHK1/test/mode 0.ahk similarity index 91% rename from AhkDll.Ahk/v1/test/mode 0.ahk rename to Binding.AHK1/test/mode 0.ahk index 7134b08..e3ae2b3 100644 --- a/AhkDll.Ahk/v1/test/mode 0.ahk +++ b/Binding.AHK1/test/mode 0.ahk @@ -2,7 +2,7 @@ ; Run Notepad, type "Hello world!" and then select all text by mouse. #Include %A_ScriptDir% -#Include ..\IbAhkSend.ahk +#Include ..\IbInputSimulator.ahk IbSendInit("AnyDriver", 0) diff --git a/AhkDll.Ahk/v1/test/mode 1.ahk b/Binding.AHK1/test/mode 1.ahk similarity index 90% rename from AhkDll.Ahk/v1/test/mode 1.ahk rename to Binding.AHK1/test/mode 1.ahk index b2d9d63..2d7c94a 100644 --- a/AhkDll.Ahk/v1/test/mode 1.ahk +++ b/Binding.AHK1/test/mode 1.ahk @@ -2,7 +2,7 @@ ; Run Notepad, type "Hello world!" and then select all text by mouse. #Include %A_ScriptDir% -#Include ..\IbAhkSend.ahk +#Include ..\IbInputSimulator.ahk IbSendInit() diff --git a/AhkDll.Ahk/v1/test/mode ahk.ahk b/Binding.AHK1/test/mode ahk.ahk similarity index 100% rename from AhkDll.Ahk/v1/test/mode ahk.ahk rename to Binding.AHK1/test/mode ahk.ahk diff --git a/AhkDll.Ahk/v1/test/type DD.ahk b/Binding.AHK1/test/type DD.ahk similarity index 61% rename from AhkDll.Ahk/v1/test/type DD.ahk rename to Binding.AHK1/test/type DD.ahk index 0c86aaf..d3f0785 100644 --- a/AhkDll.Ahk/v1/test/type DD.ahk +++ b/Binding.AHK1/test/type DD.ahk @@ -1,4 +1,4 @@ #Include %A_ScriptDir% -#Include ..\IbAhkSend.ahk +#Include ..\IbInputSimulator.ahk IbSendInit("DD") ;or IbSendInit("DD", 1, "C:\SomeDir\DD64.dll") -#include mode ahk.ahk \ No newline at end of file +#Include mode ahk.ahk \ No newline at end of file diff --git a/Binding.AHK1/test/type Logitech.ahk b/Binding.AHK1/test/type Logitech.ahk new file mode 100644 index 0000000..9a729a6 --- /dev/null +++ b/Binding.AHK1/test/type Logitech.ahk @@ -0,0 +1,4 @@ +#Include %A_ScriptDir% +#Include ..\IbInputSimulator.ahk +IbSendInit("Logitech") +#Include mode ahk.ahk \ No newline at end of file diff --git a/Binding.AHK1/test/type MouClassInputInjection.ahk b/Binding.AHK1/test/type MouClassInputInjection.ahk new file mode 100644 index 0000000..7532086 --- /dev/null +++ b/Binding.AHK1/test/type MouClassInputInjection.ahk @@ -0,0 +1,7 @@ +#Include %A_ScriptDir% +#Include ..\IbInputSimulator.ahk +InputBox, pid, , Please specify the process ID of the target process +IbSendInit("MouClassInputInjection", 1, pid) + +;MouseClickDrag, Left, 5, 5, 150, 50, 0, R +SendInput {Click 100 100} \ No newline at end of file diff --git a/Binding.AHK1/test/type Razer.ahk b/Binding.AHK1/test/type Razer.ahk new file mode 100644 index 0000000..6f8c7d3 --- /dev/null +++ b/Binding.AHK1/test/type Razer.ahk @@ -0,0 +1,4 @@ +#Include %A_ScriptDir% +#Include ..\IbInputSimulator.ahk +IbSendInit("Razer") +#Include mode ahk.ahk \ No newline at end of file diff --git a/Binding.AHK1/test/type SendInput.ahk b/Binding.AHK1/test/type SendInput.ahk new file mode 100644 index 0000000..a2983af --- /dev/null +++ b/Binding.AHK1/test/type SendInput.ahk @@ -0,0 +1,4 @@ +#Include %A_ScriptDir% +#Include ..\IbInputSimulator.ahk +IbSendInit("SendInput") +#Include mode ahk.ahk \ No newline at end of file diff --git a/AhkDll.Ahk/v2/IbAhkSend.ahk b/Binding.AHK2/IbInputSimulator.ahk similarity index 51% rename from AhkDll.Ahk/v2/IbAhkSend.ahk rename to Binding.AHK2/IbInputSimulator.ahk index 842962e..012eb6e 100644 --- a/AhkDll.Ahk/v2/IbAhkSend.ahk +++ b/Binding.AHK2/IbInputSimulator.ahk @@ -1,36 +1,42 @@ -; IbAhkSendLib +; IbInputSimulator ; Description: Enable AHK to send keystrokes by drivers. ; Author: Chaoses Ib -; Version: 0.3 -; Git: https://github.com/Chaoses-Ib/IbAhkSendLib +; Version: 0.4 +; Git: https://github.com/Chaoses-Ib/IbInputSimulator -#DllLoad "*i IbAhkSend.dll" ;DllCall("LoadLibrary") cannot locate DLL correctly +#Requires AutoHotkey v2.0 64-bit + +#DllLoad "*i IbInputSimulator.dll" ;DllCall("LoadLibrary") cannot locate DLL correctly IbSendInit(send_type := "AnyDriver", mode := 1, args*){ workding_dir := A_WorkingDir SetWorkingDir(A_ScriptDir) - static hModule := DllCall("GetModuleHandle", "Str", "IbAhkSend.dll", "Ptr") + static hModule := DllCall("GetModuleHandle", "Str", "IbInputSimulator.dll", "Ptr") if (hModule == 0){ if (A_PtrSize == 4) throw "SendLibLoadFailed: Please use AutoHotkey x64" else - throw "SendLibLoadFailed" + throw "SendLibLoadFailed: " A_LastError } if (send_type == "AnyDriver") - result := DllCall("IbAhkSend\IbSendInit", "Int", 0, "Int", 0, "Ptr", 0, "Int") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 0, "Int", 0, "Ptr", 0, "Int") else if (send_type == "SendInput") - result := DllCall("IbAhkSend\IbSendInit", "Int", 1, "Int", 0, "Ptr", 0, "Int") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 1, "Int", 0, "Ptr", 0, "Int") else if (send_type == "Logitech") - result := DllCall("IbAhkSend\IbSendInit", "Int", 2, "Int", 0, "Ptr", 0, "Int") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 2, "Int", 0, "Ptr", 0, "Int") else if (send_type == "Razer") - result := DllCall("IbAhkSend\IbSendInit", "Int", 3, "Int", 0, "Ptr", 0, "Int") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 3, "Int", 0, "Ptr", 0, "Int") else if (send_type == "DD"){ if (args.Length == 1) - result := DllCall("IbAhkSend\IbSendInit", "Int", 4, "Int", 0, "WStr", args[1], "Int") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 4, "Int", 0, "WStr", args[1], "Int") else - result := DllCall("IbAhkSend\IbSendInit", "Int", 4, "Int", 0, "Ptr", 0, "Int") + result := DllCall("IbInputSimulator\IbSendInit", "Int", 4, "Int", 0, "Ptr", 0, "Int") + } else if (send_type == "MouClassInputInjection"){ + if (args.Length != 1) + throw "MouClassInputInjection: Please specify the process ID of the target process" + result := DllCall("IbInputSimulator\IbSendInit", "Int", 5, "Int", 0, "UInt64", args[1], "Int") } else throw "Invalid send type" @@ -57,30 +63,30 @@ IbSendInit(send_type := "AnyDriver", mode := 1, args*){ IbSendMode(mode){ static ahk_mode := "" if (mode == 1){ - DllCall("IbAhkSend\IbSendInputHook", "Int", 1) + DllCall("IbInputSimulator\IbSendInputHook", "Int", 1) ahk_mode := A_SendMode SendMode("Input") } else if (mode == 0){ SendMode(ahk_mode) - DllCall("IbAhkSend\IbSendInputHook", "Int", 0) + DllCall("IbInputSimulator\IbSendInputHook", "Int", 0) } else { throw "Invalid send mode" } } IbSendDestroy(){ - DllCall("IbAhkSend\IbSendDestroy") + DllCall("IbInputSimulator\IbSendDestroy") ;DllCall("FreeLibrary", "Ptr", hModule) } IbSyncKeyStates(){ - DllCall("IbAhkSend\IbSendSyncKeyStates") + DllCall("IbInputSimulator\IbSendSyncKeyStates") } IbSend(keys){ - DllCall("IbAhkSend\IbSendInputHook", "Int", 1) ;or IbSendMode(1) + DllCall("IbInputSimulator\IbSendInputHook", "Int", 1) ;or IbSendMode(1) SendInput(keys) - DllCall("IbAhkSend\IbSendInputHook", "Int", 0) ;or IbSendMode(0) + DllCall("IbInputSimulator\IbSendInputHook", "Int", 0) ;or IbSendMode(0) } IbClick(args*){ diff --git a/AhkDll.Ahk/v2/test/KeyHistory.ahk b/Binding.AHK2/test/KeyHistory.ahk similarity index 100% rename from AhkDll.Ahk/v2/test/KeyHistory.ahk rename to Binding.AHK2/test/KeyHistory.ahk diff --git a/AhkDll.Ahk/v2/test/mode 0.ahk b/Binding.AHK2/test/mode 0.ahk similarity index 89% rename from AhkDll.Ahk/v2/test/mode 0.ahk rename to Binding.AHK2/test/mode 0.ahk index 98f3aa2..69ab367 100644 --- a/AhkDll.Ahk/v2/test/mode 0.ahk +++ b/Binding.AHK2/test/mode 0.ahk @@ -1,7 +1,7 @@ ; Mode 0 ; Run Notepad, type "Hello world!" and then select all text by mouse. -#Include "..\IbAhkSend.ahk" +#Include "..\IbInputSimulator.ahk" IbSendInit("AnyDriver", 0) diff --git a/AhkDll.Ahk/v2/test/mode 1.ahk b/Binding.AHK2/test/mode 1.ahk similarity index 88% rename from AhkDll.Ahk/v2/test/mode 1.ahk rename to Binding.AHK2/test/mode 1.ahk index 50b04c2..0371d57 100644 --- a/AhkDll.Ahk/v2/test/mode 1.ahk +++ b/Binding.AHK2/test/mode 1.ahk @@ -1,7 +1,7 @@ ; Mode 1 ; Run Notepad, type "Hello world!" and then select all text by mouse. -#Include "..\IbAhkSend.ahk" +#Include "..\IbInputSimulator.ahk" IbSendInit() diff --git a/AhkDll.Ahk/v2/test/mode ahk.ahk b/Binding.AHK2/test/mode ahk.ahk similarity index 100% rename from AhkDll.Ahk/v2/test/mode ahk.ahk rename to Binding.AHK2/test/mode ahk.ahk diff --git a/AhkDll.Ahk/v2/test/type DD.ahk b/Binding.AHK2/test/type DD.ahk similarity index 52% rename from AhkDll.Ahk/v2/test/type DD.ahk rename to Binding.AHK2/test/type DD.ahk index b68fe6f..040fdb3 100644 --- a/AhkDll.Ahk/v2/test/type DD.ahk +++ b/Binding.AHK2/test/type DD.ahk @@ -1,3 +1,3 @@ -#Include "..\IbAhkSend.ahk" +#Include "..\IbInputSimulator.ahk" IbSendInit("DD") ;or IbSendInit("DD", 1, "C:\SomeDir\DD64.dll") -#include "mode ahk.ahk" \ No newline at end of file +#Include "mode ahk.ahk" \ No newline at end of file diff --git a/Binding.AHK2/test/type Logitech.ahk b/Binding.AHK2/test/type Logitech.ahk new file mode 100644 index 0000000..e1a275d --- /dev/null +++ b/Binding.AHK2/test/type Logitech.ahk @@ -0,0 +1,3 @@ +#Include "..\IbInputSimulator.ahk" +IbSendInit("Logitech") +#Include "mode ahk.ahk" \ No newline at end of file diff --git a/Binding.AHK2/test/type MouClassInputInjection.ahk b/Binding.AHK2/test/type MouClassInputInjection.ahk new file mode 100644 index 0000000..9ea3647 --- /dev/null +++ b/Binding.AHK2/test/type MouClassInputInjection.ahk @@ -0,0 +1,4 @@ +#Include "..\IbInputSimulator.ahk" +pid := InputBox("Please specify the process ID of the target process") +IbSendInit("MouClassInputInjection", 1, pid) +#Include "mode ahk.ahk" \ No newline at end of file diff --git a/Binding.AHK2/test/type Razer.ahk b/Binding.AHK2/test/type Razer.ahk new file mode 100644 index 0000000..8bac062 --- /dev/null +++ b/Binding.AHK2/test/type Razer.ahk @@ -0,0 +1,3 @@ +#Include "..\IbInputSimulator.ahk" +IbSendInit("Razer") +#Include "mode ahk.ahk" \ No newline at end of file diff --git a/Binding.AHK2/test/type SendInput.ahk b/Binding.AHK2/test/type SendInput.ahk new file mode 100644 index 0000000..31431b7 --- /dev/null +++ b/Binding.AHK2/test/type SendInput.ahk @@ -0,0 +1,3 @@ +#Include "..\IbInputSimulator.ahk" +IbSendInit("SendInput") +#Include "mode ahk.ahk" \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1a6d253 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.15) + +project(IbInputSimulator) + +add_subdirectory(Simulator) \ No newline at end of file diff --git a/IbAhkSendLib.sln b/IbAhkSendLib.sln deleted file mode 100644 index d40dc90..0000000 --- a/IbAhkSendLib.sln +++ /dev/null @@ -1,41 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31424.327 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AhkDll", "AhkDll\AhkDll.vcxproj", "{A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AhkDll.Test", "AhkDll.Test\AhkDll.Test.vcxproj", "{F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}.Debug|x64.ActiveCfg = Debug|x64 - {A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}.Debug|x64.Build.0 = Debug|x64 - {A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}.Debug|x86.ActiveCfg = Debug|Win32 - {A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}.Debug|x86.Build.0 = Debug|Win32 - {A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}.Release|x64.ActiveCfg = Release|x64 - {A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}.Release|x64.Build.0 = Release|x64 - {A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}.Release|x86.ActiveCfg = Release|Win32 - {A8CC7E86-6E3F-4C18-BF47-F6AAF0AFEFA9}.Release|x86.Build.0 = Release|Win32 - {F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}.Debug|x64.ActiveCfg = Debug|x64 - {F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}.Debug|x64.Build.0 = Debug|x64 - {F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}.Debug|x86.ActiveCfg = Debug|Win32 - {F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}.Debug|x86.Build.0 = Debug|Win32 - {F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}.Release|x64.ActiveCfg = Release|x64 - {F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}.Release|x64.Build.0 = Release|x64 - {F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}.Release|x86.ActiveCfg = Release|Win32 - {F5AA5311-DD5F-43F8-805A-D0F4BB19D32F}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {DFCAC607-BB86-42CE-8EE7-54D7FE8BAA13} - EndGlobalSection -EndGlobal diff --git a/README.md b/README.md index 06fa8dc..79a9146 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,36 @@ -# IbAhkSendLib -Languages: [English](README.md), [简体中文](README.zh-Hans.md) -An [AutoHotkey](https://www.autohotkey.com/) library that enables AHK to send keystrokes by drivers. +# IbInputSimulator +A library for simulating keyboard and mouse input with drivers. + +## Download +[Releases](https://github.com/Chaoses-Ib/IbInputSimulator/releases) + +## Supported drivers +- [Logitech Gaming Software](https://support.logi.com/hc/en-gb/articles/360025298053-Logitech-Gaming-Software) + + No Logitech hardware required. However, in the new versions of LGS, the mouse driver has been removed ([#8](https://github.com/Chaoses-Ib/IbInputSimulator/issues/8)). You can install [v9.02.65](https://github.com/Chaoses-Ib/IbLogiSoftExt/releases/download/v0.1/LGS.v9.02.65_x64.exe) to make the mouse driver available. -## Supported Drivers -* [Logitech G HUB](https://www.logitechg.com/innovation/g-hub.html) - No Logitech hardware required. e.g. `IbSendInit("Logitech")` -* [Logitech Gaming Software](https://support.logi.com/hc/en-gb/articles/360025298053-Logitech-Gaming-Software) - No Logitech hardware required. + +- [Logitech G HUB](https://www.logitechg.com/innovation/g-hub.html) + + No Logitech hardware required. However, in the new versions of G HUB, the mouse driver has been removed ([#8](https://github.com/Chaoses-Ib/IbInputSimulator/issues/8)). Unfortunately, there is currently no known way to install an old version. + e.g. `IbSendInit("Logitech")` -* [Razer Synapse 3](https://www.razer.com/synapse-3) - No Razer hardware required, but it will be safer if you have one. + +- [Razer Synapse 3](https://www.razer.com/synapse-3) + + In the new versions of Razer Synapse, Razer hardware is required to make the driver available. The old versions do not require Razer hardware, but the online installer of Razer Synapse can only install the newest version. To install an old version manually, see [#7](https://github.com/Chaoses-Ib/IbInputSimulator/issues/7) for details. + e.g. `IbSendInit("Razer")` -* [DD Virtual Mouse & Virtual Keyboard](https://github.com/ddxoft/master) - May cause a blue screen; difficult to uninstall cleanly; need network. + +- [MouClassInputInjection](https://github.com/Chaoses-Ib/MouClassInputInjection) + + e.g. `IbSendInit("MouClassInputInjection", 1, process_id)` + +- [DD Virtual Mouse & Virtual Keyboard](https://github.com/ddxoft/master) + + May cause a blue screen; difficult to uninstall cleanly; need network. + To use it, put the DLL (`DD94687.64.dll`/`DD64.dll`/`DDHID64.dll`) with your script file, and then: ```ahk IbSendInit("DD") @@ -23,18 +40,29 @@ An [AutoHotkey](https://www.autohotkey.com/) library that enables AHK to send ke IbSendInit("DD", 1, "C:\SomeDir\DD64.dll") ``` -## Example +- [EDI](https://t.me/Chaoses_Ib) (private, not for sale) + +## Software compatibility +Software | SendInput | Logitech | Razer | MCII | DD | EDI | DM | Other +--- | --- | --- | --- | --- | --- | --- | --- | --- +Blade & Soul (Korean) | | ✔️ | | | ❗ | ✔️ | ✔️ | ❌ SendInput hook +Genshin | [High](https://meta.appinn.net/t/topic/44865/10?u=chaoses_ib) + +For SendInput, software with `High` indicates that the target process usually has a high integrity level, which may block SendInput due to UIPI. To put it simply, this means that you need to run the input simulator with administrator privileges. + +## Supported languages +### AutoHotkey - - + + ; and then select all text by mouse.
#Include %A_ScriptDir% -
-#Include IbAhkSend.ahk +#Include IbInputSimulator.ahk
IbSendInit() ; IbSendInit("AnyDriver", 1)
@@ -68,22 +95,41 @@ MouseClickDrag, Left, 5, 5, 150, 50
AHK v2AHK v1AutoHotkey v2AutoHotkey v1
; Run Notepad, type "Hello world!"
 ; and then select all text by mouse.
 
-#Include "IbAhkSend.ahk" +#Include "IbInputSimulator.ahk"
IbSendInit() ; IbSendInit("AnyDriver", 1)
@@ -50,8 +78,7 @@ MouseClickDrag("Left", 5, 5, 150, 50)
-## Downloading -[Releases](../../releases) - -## See Also -* [IbLogiSoftExt](https://github.com/Chaoses-Ib/IbLogiSoftExt) - -## For Developers -### Building -1. Put [IbWinCppLib](https://github.com/Chaoses-Ib/IbWinCppLib/tree/master/WinCppLib/IbWinCppLib) in `C:\L\C++\packages` (in other locations you need to modify the .vcxproj files). -1. [vcpkg](https://github.com/microsoft/vcpkg) - ``` - set VCPKG_DEFAULT_TRIPLET=x64-windows-static-md - vcpkg install detours rapidjson - ``` - For Test project you also need: - ``` - vcpkg install boost-test fmt - ``` - Change VCPKG_DEFAULT_TRIPLET to x86-windows-static-md if you need x86 version. \ No newline at end of file +## Build +[vcpkg](https://github.com/microsoft/vcpkg): +``` +vcpkg install detours rapidjson --triplet=x64-windows-static +``` +CMake (or open the directory with Visual Studio and config it manually): +``` +mkdir build +cd build +cmake .. -DCMAKE_TOOLCHAIN_FILE="C:\...\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows-static +cmake --build . --config Release +``` + +For the test you also need: +``` +vcpkg install boost-test fmt +``` +And add `-DBUILD_TESTING=ON` when calling `cmake ..` . + +## See also +- [IbLogiSoftExt](https://github.com/Chaoses-Ib/IbLogiSoftExt) + +## Credits +- Logitech + - @Eagle1020 + - [ekknod/logitech-cve](https://github.com/ekknod/logitech-cve) for learning that Logitech devices can be opened directly +- Razer + - [Sadmeme/rzctl](https://github.com/Sadmeme/rzctl) + - @任性 for providing test environment + +Sponsors: + +Date | Sponsor | Comment +--- | --- | --- +2022-04-03 | 任性 | MouClassInputInjection +2023-04-22 | 任性 | Logitech +2023-02-28 | - | +2021-08-28 | 任性 | Razer \ No newline at end of file diff --git a/README.zh-Hans.md b/README.zh-Hans.md deleted file mode 100644 index b2818fe..0000000 --- a/README.zh-Hans.md +++ /dev/null @@ -1,87 +0,0 @@ -# IbAhkSendLib -语言:[English](README.md),[简体中文](README.zh-Hans.md) -[AutoHotkey](https://www.autohotkey.com/) 驱动按键库。 - -## 支持驱动 -* [罗技 G HUB](https://www.logitechg.com.cn/zh-cn/innovation/g-hub.html) - 不需要罗技硬件。 - 用例:`IbSendInit("Logitech")` -* [罗技游戏软件](https://support.logi.com/hc/zh-cn/articles/360025298053) - 不需要罗技硬件。 - 用例:`IbSendInit("Logitech")` -* [雷蛇雷云3](http://cn.razerzone.com/synapse-3) - 不需要雷蛇硬件,不过如果有的话会更安全。 - 用例:`IbSendInit("Razer")` -* [DD 虚拟鼠标 & 虚拟键盘](https://github.com/ddxoft/master) - 可能会导致蓝屏;难以卸载干净;需要联网。 - 使用时需要把 DLL 文件(`DD94687.64.dll`/`DD64.dll`/`DDHID64.dll`)与你的脚本文件放到一起,然后: - ```ahk - IbSendInit("DD") - ``` - 或者在调用 IbSendInit 时指定 DLL 路径: - ```ahk - IbSendInit("DD", 1, "C:\SomeDir\DD64.dll") - ``` - -## 例子 - - - - - - - - - - - -
AHK v2AHK v1
; 运行记事本,输入“Hello world!”并通过鼠标全选文本。
-
-#Include "IbAhkSend.ahk" -
-IbSendInit() ; IbSendInit("AnyDriver", 1) -
-Send("#r") -WinWaitActive("ahk_class #32770") -Send("notepad`n") -
-WinWaitActive("ahk_exe notepad.exe") -Send("Hello world+1") -Sleep(100) -MouseClickDrag("Left", 5, 5, 150, 50)
; 运行记事本,输入“Hello world!”并通过鼠标全选文本。
-
-#Include %A_ScriptDir% -
-#Include IbAhkSend.ahk -
-IbSendInit() ; IbSendInit("AnyDriver", 1) -
-Send #r -WinWaitActive, ahk_class #32770 -Send notepad`n -
-WinWaitActive, ahk_exe notepad.exe -Send Hello world+1 -Sleep 100 -CoordMode, Mouse, Client -MouseClickDrag, Left, 5, 5, 150, 50
- -## 下载 -[Releases](../../releases) - -## 相关推荐 -* [IbLogiSoftExt](https://github.com/Chaoses-Ib/IbLogiSoftExt) - -## 开发者 -### 构建 -1. 将 [IbWinCppLib](https://github.com/Chaoses-Ib/IbWinCppLib/tree/master/WinCppLib/IbWinCppLib) 放入 `C:\L\C++\packages`(其它位置需要修改 .vcxproj 文件)。 -1. [vcpkg](https://github.com/microsoft/vcpkg) - ``` - set VCPKG_DEFAULT_TRIPLET=x64-windows-static-md - vcpkg install detours rapidjson - ``` - Test 项目还需要: - ``` - vcpkg install boost-test fmt - ``` - 如果需要 x86 版本就把 VCPKG_DEFAULT_TRIPLET 改为 x86-windows-static-md。 \ No newline at end of file diff --git a/Simulator/CMakeLists.txt b/Simulator/CMakeLists.txt new file mode 100644 index 0000000..ab1e24d --- /dev/null +++ b/Simulator/CMakeLists.txt @@ -0,0 +1,64 @@ +cmake_minimum_required(VERSION 3.15) + +project(IbInputSimulator) + +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + +# IbWinCppLib +include(FetchContent) +FetchContent_Declare(IbWinCpp + GIT_REPOSITORY https://github.com/Chaoses-Ib/IbWinCppLib.git + GIT_TAG a29ac95537f403ac5ae221cb744d3e82076efbf7 +) +FetchContent_MakeAvailable(IbWinCpp) + +# Detours +find_path(DETOURS_INCLUDE_DIR detours/detours.h) +find_library(DETOURS_LIBRARY detours) + +# RapidJSON +find_package(RapidJSON CONFIG REQUIRED) + + +set(sourceFiles + dllmain.cpp + "API 2.cpp" + "API 3.cpp" +) +list(TRANSFORM sourceFiles PREPEND source/) +add_library(IbInputSimulator SHARED ${sourceFiles}) +target_compile_features(IbInputSimulator PUBLIC cxx_std_20) +target_compile_definitions(IbInputSimulator PRIVATE IB_INPUT_DLLEXPORT) + +target_include_directories(IbInputSimulator + PUBLIC include + PRIVATE ${DETOURS_INCLUDE_DIR} +) +target_link_libraries(IbInputSimulator + PRIVATE IbWinCpp + PRIVATE ${DETOURS_LIBRARY} + PRIVATE rapidjson +) + +# Test +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + option(BUILD_TESTING "Build the testing tree." OFF) + include(CTest) + if(BUILD_TESTING) + find_package(Boost REQUIRED COMPONENTS unit_test_framework) + find_package(fmt CONFIG REQUIRED) + + set(testFiles + test.cpp + ) + list(TRANSFORM testFiles PREPEND test/) + + add_executable(IbInputSimulator_Test ${testFiles}) + target_link_libraries(IbInputSimulator_Test + PRIVATE IbInputSimulator + PRIVATE Boost::unit_test_framework + PRIVATE IbWinCpp + PRIVATE fmt::fmt + ) + endif() +endif() \ No newline at end of file diff --git a/AhkDll/IbAhkSend.hpp b/Simulator/include/IbInputSimulator/InputSimulator.hpp similarity index 96% rename from AhkDll/IbAhkSend.hpp rename to Simulator/include/IbInputSimulator/InputSimulator.hpp index b5290f3..1cb443b 100644 --- a/AhkDll/IbAhkSend.hpp +++ b/Simulator/include/IbInputSimulator/InputSimulator.hpp @@ -1,8 +1,8 @@ -#pragma once +#pragma once #include #include -#ifdef IB_AHKSEND_DLLEXPORT +#ifdef IB_INPUT_DLLEXPORT #define DLLAPI extern "C" __declspec(dllexport) #else #define DLLAPI extern "C" __declspec(dllimport) @@ -25,7 +25,8 @@ namespace Send { SendInput, Logitech, Razer, - DD + DD, + MouClassInputInjection }; using InitFlags = const uint32_t; @@ -83,8 +84,8 @@ DLLAPI VOID WINAPI IbSend_keybd_event( namespace Send { enum class MoveMode : uint32_t { - Absolute, //1 - Relative //2 + Absolute, //0 + Relative //1 }; enum class MouseButton : uint32_t { diff --git a/AhkDll/SendTypes/DD.hpp b/Simulator/include/IbInputSimulator/SendTypes/DD.hpp similarity index 95% rename from AhkDll/SendTypes/DD.hpp rename to Simulator/include/IbInputSimulator/SendTypes/DD.hpp index 503a019..269eddd 100644 --- a/AhkDll/SendTypes/DD.hpp +++ b/Simulator/include/IbInputSimulator/SendTypes/DD.hpp @@ -1,10 +1,10 @@ #pragma once -#include +#include -#include "Base.hpp" +#include "base.hpp" namespace Send::Type::Internal { - class DD final : virtual public Base, public VirtualKeyStates { + class DD final : public VirtualKeyStates { KeyboardModifiers modifiers; std::mutex keyboard_mutex; @@ -64,6 +64,11 @@ namespace Send::Type::Internal { FreeLibrary(dd); } + uint32_t send_mouse_input(const INPUT inputs[], uint32_t n) override { + update_screen_resolution(); + return Base::send_mouse_input(inputs, n); + } + bool send_mouse_input(const MOUSEINPUT& mi) override { //#TODO: MOUSEEVENTF_MOVE_NOCOALESCE, MOUSEEVENTF_VIRTUALDESK if (mi.dwFlags & MOUSEEVENTF_MOVE) { diff --git a/AhkDll/SendTypes/Logitech.hpp b/Simulator/include/IbInputSimulator/SendTypes/Logitech.hpp similarity index 97% rename from AhkDll/SendTypes/Logitech.hpp rename to Simulator/include/IbInputSimulator/SendTypes/Logitech.hpp index 1f2d381..43401b1 100644 --- a/AhkDll/SendTypes/Logitech.hpp +++ b/Simulator/include/IbInputSimulator/SendTypes/Logitech.hpp @@ -3,8 +3,8 @@ #include #include #include "../common.hpp" -#include "Base.hpp" -#include "Usb.hpp" +#include "base.hpp" +#include "usb.hpp" namespace Send::Type::Internal { class LogitechDriver { @@ -229,7 +229,7 @@ namespace Send::Type::Internal { } }; - class Logitech final : virtual public Base, public VirtualKeyStates { + class Logitech final : public VirtualKeyStates { LogitechDriver driver; public: Logitech() : VirtualKeyStates(keyboard_report.modifiers, keyboard_mutex) {} @@ -248,6 +248,11 @@ namespace Send::Type::Internal { std::mutex mouse_mutex; public: + uint32_t send_mouse_input(const INPUT inputs[], uint32_t n) override { + update_screen_resolution(); + return Base::send_mouse_input(inputs, n); + } + bool send_mouse_input(const MOUSEINPUT& mi) override { std::lock_guard lock(mouse_mutex); diff --git a/Simulator/include/IbInputSimulator/SendTypes/MouClassInputInjection.hpp b/Simulator/include/IbInputSimulator/SendTypes/MouClassInputInjection.hpp new file mode 100644 index 0000000..c473e38 --- /dev/null +++ b/Simulator/include/IbInputSimulator/SendTypes/MouClassInputInjection.hpp @@ -0,0 +1,144 @@ +#pragma once +#include "base.hpp" +#include "MouClassInputInjection/ioctl.h" + +namespace Send::Type::Internal { + class MouClassInputInjection final : virtual public Base { + public: + MouClassInputInjection() {} + + Error create(ULONG_PTR pid) { + device = CreateFileW( + LOCAL_DEVICE_PATH_U, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + nullptr, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + nullptr + ); + if (device == INVALID_HANDLE_VALUE) + return Error::DeviceNotFound; + + DWORD bytes_returned; + if (!DeviceIoControl( + device, + IOCTL_INITIALIZE_MOUSE_DEVICE_STACK_CONTEXT, + nullptr, 0, + &device_info, sizeof(device_info), + &bytes_returned, + nullptr + )) { + CloseHandle(device); + return Error::DeviceOpenFailed; + } + + this->pid = pid; + + return Error::Success; + } + + void destroy() override { + CloseHandle(device); + } + + bool send_mouse_input(const MOUSEINPUT& mi) override { + if (mi.dwFlags & MOUSEEVENTF_MOVE) { + USHORT flags = 0; + POINT move{ mi.dx, mi.dy }; + + // MOUSE_MOVE_RELATIVE: 0 + if (device_info.MovementDevice.AbsoluteMovement) { + flags |= MOUSE_MOVE_ABSOLUTE; + if (!(mi.dwFlags & MOUSEEVENTF_ABSOLUTE)) { + POINT cursor; + GetCursorPos(&cursor); + move.x += cursor.x; + move.y += cursor.y; + } + else { + //@todo mouse_absolute_to_screen(move); + } + } + else { + if (mi.dwFlags & MOUSEEVENTF_ABSOLUTE) { + mouse_absolute_to_screen(move); + mouse_screen_to_relative(move); + } + } + + //@todo mi.dwFlags & MOUSEEVENTF_VIRTUALDESK + if (device_info.MovementDevice.VirtualDesktop) + flags |= MOUSE_VIRTUAL_DESKTOP; + + // MOUSE_ATTRIBUTES_CHANGED + + if (mi.dwFlags & MOUSEEVENTF_MOVE_NOCOALESCE) + flags |= MOUSE_MOVE_NOCOALESCE; + + // MOUSE_TERMSRV_SRC_SHADOW: unknown + + INJECT_MOUSE_MOVEMENT_INPUT_REQUEST request{ + .ProcessId = pid, + .IndicatorFlags = flags, + .MovementX = move.x, + .MovementY = move.y + }; + DWORD bytes_returned; + DeviceIoControl( + device, + IOCTL_INJECT_MOUSE_MOVEMENT_INPUT, + &request, sizeof(request), + nullptr, 0, + &bytes_returned, + nullptr + ); + } + + if (mi.dwFlags & 0x7E) { + DWORD keys[] = { MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP, MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP }; + for (DWORD key : keys) + if (mi.dwFlags & key) + inject_button(key >> 1); + } + if (mi.dwFlags & (MOUSEEVENTF_XDOWN | MOUSEEVENTF_XUP)) { + bool down = mi.dwFlags & MOUSEEVENTF_XDOWN; + switch (mi.mouseData) { + case XBUTTON1: inject_button(down ? MOUSE_BUTTON_4_DOWN : MOUSE_BUTTON_4_UP); break; + case XBUTTON2: inject_button(down ? MOUSE_BUTTON_5_DOWN : MOUSE_BUTTON_5_UP); break; + } + } + else if (mi.dwFlags & MOUSEEVENTF_WHEEL) + return false; + + //@todo + return true; + } + + bool send_keyboard_input(const KEYBDINPUT& ki) override { + return false; + } + + private: + HANDLE device; + MOUSE_DEVICE_STACK_INFORMATION device_info; + ULONG_PTR pid; + + bool inject_button(USHORT button) { + INJECT_MOUSE_BUTTON_INPUT_REQUEST request{ + .ProcessId = pid, + .ButtonFlags = button, + .ButtonData = 0 + }; + DWORD bytes_returned; + return DeviceIoControl( + device, + IOCTL_INJECT_MOUSE_BUTTON_INPUT, + &request, sizeof(request), + nullptr, 0, + &bytes_returned, + nullptr + ); + } + }; +} \ No newline at end of file diff --git a/Simulator/include/IbInputSimulator/SendTypes/MouClassInputInjection/ioctl.h b/Simulator/include/IbInputSimulator/SendTypes/MouClassInputInjection/ioctl.h new file mode 100644 index 0000000..9a5a010 --- /dev/null +++ b/Simulator/include/IbInputSimulator/SendTypes/MouClassInputInjection/ioctl.h @@ -0,0 +1,113 @@ +/*++ + +Copyright (c) 2019 changeofpace. All rights reserved. + +Use of this source code is governed by the MIT license. See the 'LICENSE' file +for more information. + +--*/ + +#pragma once + +#if defined(_KERNEL_MODE) +#include +#else +#include +#endif + +#include +#include + +//============================================================================= +// Names +//============================================================================= +#define DRIVER_NAME_U L"MouClassInputInjection" +#define LOCAL_DEVICE_PATH_U (L"\\\\.\\" DRIVER_NAME_U) +#define NT_DEVICE_NAME_U (L"\\Device\\" DRIVER_NAME_U) +#define SYMBOLIC_LINK_NAME_U (L"\\DosDevices\\" DRIVER_NAME_U) + +//============================================================================= +// Ioctls +//============================================================================= +#define FILE_DEVICE_MOUCLASS_INPUT_INJECTION 48781ul + +#define IOCTL_INITIALIZE_MOUSE_DEVICE_STACK_CONTEXT \ + CTL_CODE( \ + FILE_DEVICE_MOUCLASS_INPUT_INJECTION, \ + 2600, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define IOCTL_INJECT_MOUSE_BUTTON_INPUT \ + CTL_CODE( \ + FILE_DEVICE_MOUCLASS_INPUT_INJECTION, \ + 2850, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define IOCTL_INJECT_MOUSE_MOVEMENT_INPUT \ + CTL_CODE( \ + FILE_DEVICE_MOUCLASS_INPUT_INJECTION, \ + 2851, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +#define IOCTL_INJECT_MOUSE_INPUT_PACKET \ + CTL_CODE( \ + FILE_DEVICE_MOUCLASS_INPUT_INJECTION, \ + 2870, \ + METHOD_BUFFERED, \ + FILE_ANY_ACCESS) + +//============================================================================= +// IOCTL_INITIALIZE_MOUSE_DEVICE_STACK_CONTEXT +//============================================================================= +typedef struct _MOUSE_CLASS_BUTTON_DEVICE_INFORMATION { + USHORT UnitId; +} MOUSE_CLASS_BUTTON_DEVICE_INFORMATION, +*PMOUSE_CLASS_BUTTON_DEVICE_INFORMATION; + +typedef struct _MOUSE_CLASS_MOVEMENT_DEVICE_INFORMATION { + USHORT UnitId; + BOOLEAN AbsoluteMovement; + BOOLEAN VirtualDesktop; +} MOUSE_CLASS_MOVEMENT_DEVICE_INFORMATION, +*PMOUSE_CLASS_MOVEMENT_DEVICE_INFORMATION; + +typedef struct _MOUSE_DEVICE_STACK_INFORMATION { + MOUSE_CLASS_BUTTON_DEVICE_INFORMATION ButtonDevice; + MOUSE_CLASS_MOVEMENT_DEVICE_INFORMATION MovementDevice; +} MOUSE_DEVICE_STACK_INFORMATION, *PMOUSE_DEVICE_STACK_INFORMATION; + +typedef struct _INITIALIZE_MOUSE_DEVICE_STACK_CONTEXT_REPLY { + MOUSE_DEVICE_STACK_INFORMATION DeviceStackInformation; +} INITIALIZE_MOUSE_DEVICE_STACK_CONTEXT_REPLY, +*PINITIALIZE_MOUSE_DEVICE_STACK_CONTEXT_REPLY; + +//============================================================================= +// IOCTL_INJECT_MOUSE_BUTTON_INPUT +//============================================================================= +typedef struct _INJECT_MOUSE_BUTTON_INPUT_REQUEST { + ULONG_PTR ProcessId; + USHORT ButtonFlags; + USHORT ButtonData; +} INJECT_MOUSE_BUTTON_INPUT_REQUEST, *PINJECT_MOUSE_BUTTON_INPUT_REQUEST; + +//============================================================================= +// IOCTL_INJECT_MOUSE_MOVEMENT_INPUT +//============================================================================= +typedef struct _INJECT_MOUSE_MOVEMENT_INPUT_REQUEST { + ULONG_PTR ProcessId; + USHORT IndicatorFlags; + LONG MovementX; + LONG MovementY; +} INJECT_MOUSE_MOVEMENT_INPUT_REQUEST, *PINJECT_MOUSE_MOVEMENT_INPUT_REQUEST; + +//============================================================================= +// IOCTL_INJECT_MOUSE_INPUT_PACKET +//============================================================================= +typedef struct _INJECT_MOUSE_INPUT_PACKET_REQUEST { + ULONG_PTR ProcessId; + BOOLEAN UseButtonDevice; + MOUSE_INPUT_DATA InputPacket; +} INJECT_MOUSE_INPUT_PACKET_REQUEST, *PINJECT_MOUSE_INPUT_PACKET_REQUEST; diff --git a/Simulator/include/IbInputSimulator/SendTypes/Razer.hpp b/Simulator/include/IbInputSimulator/SendTypes/Razer.hpp new file mode 100644 index 0000000..0c800ad --- /dev/null +++ b/Simulator/include/IbInputSimulator/SendTypes/Razer.hpp @@ -0,0 +1,227 @@ +#pragma once +#include +#include +#include "base.hpp" +#include "usb.hpp" + +namespace Send::Type::Internal { + class Razer final : public VirtualKeyStates { + HANDLE device; + + KeyboardModifiers modifiers; + std::mutex keyboard_mutex; + public: + Razer() : VirtualKeyStates(modifiers, keyboard_mutex) {} + + Error create() { + std::wstring device_name = find_device([](std::wstring_view sv) { + using namespace std::literals; + + //RZCONTROL#VID_1532&PID_0306&MI_00#3&1c65d7f8&0#{e3be005d-d130-4910-88ff-09ae02f680e9} + return sv.starts_with(L"RZCONTROL#"sv) && sv.ends_with(L"#{e3be005d-d130-4910-88ff-09ae02f680e9}"sv); + }); + if (device_name.empty()) + return Error::DeviceNotFound; + + device = CreateFileW( + device_name.c_str(), + GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL + ); + if (device == INVALID_HANDLE_VALUE) + return Error::DeviceOpenFailed; + + return Error::Success; + } + + void destroy() override { + CloseHandle(device); + } + + struct RzControl { + uint32_t unk1; + enum class Type : uint32_t { + Keyboard = 1, + Mouse = 2 + } type; + union { + //struct { + // uint32_t absolute_coord; + // struct { + // bool LButtonDown : 1; + // bool LButtonUp : 1; + // bool RButtonDown : 1; + // bool RButtonUp : 1; + // bool MButtonDown : 1; + // bool MButtonUp : 1; + // bool XButton1Down : 1; + // bool XButton1Up : 1; + // bool XButton2Down : 1; + // bool XButton2Up : 1; + // bool Wheel : 1; + // bool HWheel : 1; + // uint8_t unk : 4; + // private: + // void assert_size() { + // static_assert(sizeof(*this) == 2); + // } + // } btn; + // int16_t movement; + // uint32_t unk1; + // int32_t x; + // int32_t y; + // uint32_t unk2; + //} mi; + + MOUSE_INPUT_DATA mi; + + //struct { + // uint16_t unk1; + // int16_t key; + // uint16_t action; + // uint16_t unk2; + // uint32_t unk3; + // uint32_t unk4; + // uint32_t unk5; + // uint32_t unk6; + //} ki; + + /// The high byte of MakeCode has no effect, extended keys are supported by Flags + KEYBOARD_INPUT_DATA ki; + }; + private: + void assert_size() { + static_assert(sizeof RzControl == 32); + } + }; + + bool send_mouse_input(const MOUSEINPUT& mi) override { + RzControl control{ .type = RzControl::Type::Mouse }; + + if (mi.dwFlags & MOUSEEVENTF_MOVE) { + POINT move{ mi.dx, mi.dy }; + if (mi.dwFlags & MOUSEEVENTF_ABSOLUTE) { + control.mi.Flags = MOUSE_MOVE_ABSOLUTE; + } + control.mi.LastX = mi.dx; + control.mi.LastY = mi.dy; + } + + if (mi.dwFlags & MOUSEEVENTF_LEFTDOWN) + control.mi.ButtonFlags |= MOUSE_LEFT_BUTTON_DOWN; + if (mi.dwFlags & MOUSEEVENTF_LEFTUP) + control.mi.ButtonFlags |= MOUSE_LEFT_BUTTON_UP; + if (mi.dwFlags & MOUSEEVENTF_RIGHTDOWN) + control.mi.ButtonFlags |= MOUSE_RIGHT_BUTTON_DOWN; + if (mi.dwFlags & MOUSEEVENTF_RIGHTUP) + control.mi.ButtonFlags |= MOUSE_RIGHT_BUTTON_UP; + if (mi.dwFlags & MOUSEEVENTF_MIDDLEDOWN) + control.mi.ButtonFlags |= MOUSE_MIDDLE_BUTTON_DOWN; + if (mi.dwFlags & MOUSEEVENTF_MIDDLEUP) + control.mi.ButtonFlags |= MOUSE_MIDDLE_BUTTON_UP; + + if (mi.dwFlags & MOUSEEVENTF_XDOWN) { + switch (mi.mouseData) { + case XBUTTON1: control.mi.ButtonFlags |= MOUSE_BUTTON_4_DOWN; break; + case XBUTTON2: control.mi.ButtonFlags |= MOUSE_BUTTON_5_DOWN; break; + } + } + if (mi.dwFlags & MOUSEEVENTF_XUP) { + switch (mi.mouseData) { + case XBUTTON1: control.mi.ButtonFlags |= MOUSE_BUTTON_4_UP; break; + case XBUTTON2: control.mi.ButtonFlags |= MOUSE_BUTTON_5_UP; break; + } + } + + if (mi.dwFlags & MOUSEEVENTF_WHEEL || mi.dwFlags & MOUSEEVENTF_HWHEEL) { + if (mi.dwFlags & MOUSEEVENTF_WHEEL) + control.mi.ButtonFlags |= MOUSE_WHEEL; + else + control.mi.ButtonFlags |= MOUSE_HWHEEL; + control.mi.ButtonData = 120 * std::bit_cast(mi.mouseData); //#TODO + } + + if constexpr (debug) + DebugOStream() << L"send_mouse_input: " << *(uint16_t*)&control.mi.ButtonFlags << L", (" << control.mi.LastX << L", " << control.mi.LastY << L") " << control.mi.Flags << std::endl; + + DWORD bytes_returned; + return DeviceIoControl(device, 0x88883020, &control, sizeof control, nullptr, 0, &bytes_returned, nullptr); + } + + bool send_keyboard_input(const KEYBDINPUT& ki) override { + RzControl control{ .type = RzControl::Type::Keyboard }; + + if ((control.ki.MakeCode = keyboard_vk_to_key(ki.wVk)) < 0) + return false; + + std::lock_guard lock(keyboard_mutex); + + bool keydown = !(ki.dwFlags & KEYEVENTF_KEYUP); + if (is_modifier(ki.wVk)) + set_modifier_state(ki.wVk, keydown); + + control.ki.Flags = keydown ? KEY_MAKE : KEY_BREAK; + + // Extended keys + // TODO: E1 + switch (ki.wVk) + { + case VK_SNAPSHOT: + case VK_INSERT: + case VK_HOME: + case VK_PRIOR: + case VK_DELETE: + case VK_END: + case VK_NEXT: + case VK_RIGHT: + case VK_LEFT: + case VK_DOWN: + case VK_UP: + case VK_LWIN: + case VK_RWIN: + control.ki.Flags |= KEY_E0; + break; + default: + break; + } + + if constexpr (debug) + DebugOStream() << L"send_keyboard_input: " << control.ki.MakeCode << ", " << control.ki.Flags << std::endl; + + DWORD bytes_returned; + return DeviceIoControl(device, 0x88883020, &control, sizeof control, nullptr, 0, &bytes_returned, nullptr); + } + + int16_t keyboard_vk_to_key(uint8_t vk) { + if constexpr (debug) + DebugOStream() << L"keyboard_vk_to_key: " << vk << L" -> " << Usb::keyboard_vk_to_usage(vk) << L" -> " << keyboard_usage_to_key(Usb::keyboard_vk_to_usage(vk)) << std::endl; + return keyboard_usage_to_key(Usb::keyboard_vk_to_usage(vk)); + } + + /// - For extended keys, only the lowest byte is returned. + /// - RCtrl and RAlt will be treated as left ones. + constexpr int16_t keyboard_usage_to_key(uint16_t usage_id) { + // Extracted from kbddef.dat in Razer Synapse + // + // Differences from HidP_TranslateUsagesToI8042ScanCodes() and MapVirtualKey(): + // vk | razer | HidP_TranslateUsagesToI8042ScanCodes | MapVirtualKey + // --- | --- | --- | --- + // VK_PAUSE (0x13) | 0x1D | 0x1D | MAPVK_VK_TO_VSC: 0 / MAPVK_VK_TO_VSC_EX: 0x1D + // VK_SNAPSHOT (0x2C) | 0x37 | 0x2A / 0x37 | 0x54 + + if (usage_id <= 115) { + constexpr uint16_t table[] = { -1, 255, 252, -3, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26, 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 87, 88, 55, 70, 29, 82, 71, 73, 83, 79, 81, 77, 75, 80, 72, 69, 53, 55, 74, 78, 28, 79, 80, 81, 75, 76, 77, 71, 72, 73, 82, 83, 86, 93, 94, 89, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 118, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 94, 95, 99, -3, 126, -3, 115, 112, 125, 121, 123, 92, -3, -3, -3, 242, 241, 120, 119, 118 }; + return table[usage_id]; + } else if (181 <= usage_id && usage_id <= 183) { + constexpr uint16_t table[] = { 25,16,36 }; + return table[usage_id - 181]; + } else if (usage_id == 205) + return 34; + else if (224 <= usage_id && usage_id <= 234) { + constexpr uint16_t table[] = { 29, 42, 56, 91, 29, 54, 56, 92, -2, 48, 46 }; + return table[usage_id - 224]; + } + return -1; + } + }; +} \ No newline at end of file diff --git a/AhkDll/SendTypes/SendInput.hpp b/Simulator/include/IbInputSimulator/SendTypes/SendInput.hpp similarity index 98% rename from AhkDll/SendTypes/SendInput.hpp rename to Simulator/include/IbInputSimulator/SendTypes/SendInput.hpp index 4309b96..dfaf406 100644 --- a/AhkDll/SendTypes/SendInput.hpp +++ b/Simulator/include/IbInputSimulator/SendTypes/SendInput.hpp @@ -1,5 +1,5 @@ #pragma once -#include "Base.hpp" +#include "base.hpp" namespace Send::Type::Internal { class SendInput final : virtual public Base { diff --git a/AhkDll/SendTypes/Base.hpp b/Simulator/include/IbInputSimulator/SendTypes/base.hpp similarity index 94% rename from AhkDll/SendTypes/Base.hpp rename to Simulator/include/IbInputSimulator/SendTypes/base.hpp index 5555855..1e631aa 100644 --- a/AhkDll/SendTypes/Base.hpp +++ b/Simulator/include/IbInputSimulator/SendTypes/base.hpp @@ -1,7 +1,7 @@ #pragma once #include "../common.hpp" #include -#include +#include #include #pragma comment(lib, "ntdll.lib") @@ -54,22 +54,29 @@ namespace Send::Type::Internal { absolute.y = absolute.y * screen.y / 65536; } + void update_screen_resolution() { + screen.x = GetSystemMetrics(SM_CXSCREEN); //#TODO: SM_CXVIRTUALSCREEN? + screen.y = GetSystemMetrics(SM_CYSCREEN); + + // the overhead of WM_DISPLAYCHANGE is a bit high + } + + // need to call update_screen_resolution first static void mouse_screen_to_relative(POINT& screen_point) { POINT point; GetCursorPos(&point); if constexpr (debug) - ib::DebugOStream() << L"mouse_screen_to_relative: cursor (" << point.x << L", " << point.y << L") to point (" << screen_point.x << L", " << screen_point.y << L")\n"; + DebugOStream() << L"mouse_screen_to_relative: cursor (" << point.x << L", " << point.y << L") to point (" << screen_point.x << L", " << screen_point.y << L")\n"; screen_point.x -= point.x; screen_point.y -= point.y; } + public: void create_base(decltype(&::GetAsyncKeyState)* get_key_state_fallback) { this->get_key_state_fallback = get_key_state_fallback; - - screen.x = GetSystemMetrics(SM_CXSCREEN); //#TODO: may change - screen.y = GetSystemMetrics(SM_CYSCREEN); } + virtual ~Base() = default; virtual void destroy() = 0; virtual uint32_t send_input(const INPUT inputs[], uint32_t n) { @@ -133,7 +140,7 @@ namespace Send::Type::Internal { bool RGui : 1; }; - class VirtualKeyStates : virtual public Base { + class VirtualKeyStates : public Base { KeyboardModifiers& modifiers; std::mutex& mutex; diff --git a/AhkDll/SendTypes/Types.hpp b/Simulator/include/IbInputSimulator/SendTypes/types.hpp similarity index 74% rename from AhkDll/SendTypes/Types.hpp rename to Simulator/include/IbInputSimulator/SendTypes/types.hpp index 83861c1..b641435 100644 --- a/AhkDll/SendTypes/Types.hpp +++ b/Simulator/include/IbInputSimulator/SendTypes/types.hpp @@ -1,9 +1,10 @@ #pragma once -#include "Base.hpp" +#include "base.hpp" #include "SendInput.hpp" #include "Logitech.hpp" #include "Razer.hpp" #include "DD.hpp" +#include "MouClassInputInjection.hpp" namespace Send { @@ -14,5 +15,6 @@ namespace Send using Internal::Logitech; using Internal::Razer; using Internal::DD; + using Internal::MouClassInputInjection; } } \ No newline at end of file diff --git a/AhkDll/SendTypes/Usb.hpp b/Simulator/include/IbInputSimulator/SendTypes/usb.hpp similarity index 97% rename from AhkDll/SendTypes/Usb.hpp rename to Simulator/include/IbInputSimulator/SendTypes/usb.hpp index 02300ae..32fbca5 100644 --- a/AhkDll/SendTypes/Usb.hpp +++ b/Simulator/include/IbInputSimulator/SendTypes/usb.hpp @@ -198,13 +198,13 @@ namespace Send::Type::Internal { case 0xFE: return 0x0000; //VK_OEM_CLEAR case 0xFF: return 0x0000; default: - if ('A' <= vkCode and vkCode <= 'Z') + if ('A' <= vkCode && vkCode <= 'Z') return 0x04 + vkCode - 'A'; - else if ('0' <= vkCode and vkCode <= '9') + else if ('0' <= vkCode && vkCode <= '9') return vkCode == '0' ? 0x27 : 0x1E + vkCode - '1'; - else if (VK_NUMPAD0 <= vkCode and vkCode <= VK_NUMPAD9) + else if (VK_NUMPAD0 <= vkCode && vkCode <= VK_NUMPAD9) return vkCode == VK_NUMPAD0 ? 0x62 : 0x59 + vkCode - VK_NUMPAD1; - else if (VK_F1 <= vkCode and vkCode <= VK_F24) + else if (VK_F1 <= vkCode && vkCode <= VK_F24) return vkCode <= VK_F12 ? 0x3A + vkCode - VK_F1 : 0x68 + vkCode - VK_F13; diff --git a/AhkDll/common.hpp b/Simulator/include/IbInputSimulator/common.hpp similarity index 86% rename from AhkDll/common.hpp rename to Simulator/include/IbInputSimulator/common.hpp index ab07ffd..25cff88 100644 --- a/AhkDll/common.hpp +++ b/Simulator/include/IbInputSimulator/common.hpp @@ -1,15 +1,15 @@ #pragma once -#include "IbAhkSend.hpp" +#include "InputSimulator.hpp" using namespace Send; #include -#include +#include using ib::Byte; constexpr int debug = ib::debug_runtime; ib::DebugOStream<> DebugOStream() { - return { L"IbAhkSendLib: " }; + return { L"IbInputSimulator: " }; } template diff --git a/AhkDll/API 2.cpp b/Simulator/source/API 2.cpp similarity index 93% rename from AhkDll/API 2.cpp rename to Simulator/source/API 2.cpp index 8ee3732..04926f8 100644 --- a/AhkDll/API 2.cpp +++ b/Simulator/source/API 2.cpp @@ -1,6 +1,5 @@ -#include "pch.h" -#include -#include "IbAhkSend.hpp" +#include +#include using namespace Send; diff --git a/AhkDll/API 3.cpp b/Simulator/source/API 3.cpp similarity index 98% rename from AhkDll/API 3.cpp rename to Simulator/source/API 3.cpp index 2abd7c4..da42f4d 100644 --- a/AhkDll/API 3.cpp +++ b/Simulator/source/API 3.cpp @@ -1,7 +1,6 @@ -#include "pch.h" -#include +#include #include -#include "IbAhkSend.hpp" +#include using namespace Send; diff --git a/AhkDll/dllmain.cpp b/Simulator/source/dllmain.cpp similarity index 77% rename from AhkDll/dllmain.cpp rename to Simulator/source/dllmain.cpp index d3a2b81..053b797 100644 --- a/AhkDll/dllmain.cpp +++ b/Simulator/source/dllmain.cpp @@ -1,8 +1,7 @@ -#include "pch.h" -#include "IbAhkSend.hpp" +#include using namespace Send; -#include "SendTypes/Types.hpp" +#include BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, @@ -24,7 +23,9 @@ BOOL APIENTRY DllMain( HMODULE hModule, return TRUE; } -static std::unique_ptr send; +namespace main { + static std::unique_ptr send; +} class SendInputHook { public: @@ -33,7 +34,7 @@ class SendInputHook { if (!hook) return SendInput_real(cInputs, pInputs, cbSize); - return send->send_input(pInputs, cInputs); + return main::send->send_input(pInputs, cInputs); } //#TODO: only needed when two or more AHK processes exist? @@ -43,8 +44,8 @@ class SendInputHook { return GetAsyncKeyState_real(vKey); if constexpr (debug) - DebugOStream() << L"GetAsyncKeyState: " << vKey << ", " << send->get_key_state(vKey) << std::endl; - return send->get_key_state(vKey); + DebugOStream() << L"GetAsyncKeyState: " << vKey << ", " << main::send->get_key_state(vKey) << std::endl; + return main::send->get_key_state(vKey); } public: @@ -72,7 +73,7 @@ DLLAPI void __stdcall IbSendInputHook(HookCode code) { sendinput_hook.destroy(); break; case HookCode::On: - if (!sendinput_hook.has_created()) + if (!sendinput_hook.created()) sendinput_hook.create(); sendinput_hook->hook = true; break; @@ -94,6 +95,9 @@ DLLAPI Send::Error __stdcall IbSendInit(SendType type, InitFlags flags, void* ar error = IbSendInit(SendType::DD, flags, nullptr); if (error == Error::Success) return Error::Success; + error = IbSendInit(SendType::MouClassInputInjection, flags, nullptr); + if (error == Error::Success) return Error::Success; + return Error::DeviceNotFound; } else { @@ -105,7 +109,7 @@ DLLAPI Send::Error __stdcall IbSendInit(SendType type, InitFlags flags, void* ar Error error = type->create(&SendInputHook::SendInput_real); if (error != Error::Success) return error; - send = std::move(type); + main::send = std::move(type); } break; case SendType::Logitech: @@ -115,7 +119,7 @@ DLLAPI Send::Error __stdcall IbSendInit(SendType type, InitFlags flags, void* ar Error error = type->create(); if (error != Error::Success) return error; - send = std::move(type); + main::send = std::move(type); } break; case SendType::Razer: @@ -125,7 +129,7 @@ DLLAPI Send::Error __stdcall IbSendInit(SendType type, InitFlags flags, void* ar Error error = type->create(); if (error != Error::Success) return error; - send = std::move(type); + main::send = std::move(type); } break; case SendType::DD: @@ -135,7 +139,17 @@ DLLAPI Send::Error __stdcall IbSendInit(SendType type, InitFlags flags, void* ar Error error = type->create(ib::Addr(argument)); if (error != Error::Success) return error; - send = std::move(type); + main::send = std::move(type); + } + break; + case SendType::MouClassInputInjection: + { + auto type = std::make_unique(); + type->create_base(&SendInputHook::GetAsyncKeyState_real); + Error error = type->create((ULONG_PTR)argument); + if (error != Error::Success) + return error; + main::send = std::move(type); } break; default: @@ -148,14 +162,14 @@ DLLAPI Send::Error __stdcall IbSendInit(SendType type, InitFlags flags, void* ar DLLAPI void __stdcall IbSendDestroy() { IbSendInputHook(HookCode::Destroy); - if (!send) + if (!main::send) return; - send->destroy(); - send.release(); + main::send->destroy(); + main::send.reset(); } DLLAPI void __stdcall IbSendSyncKeyStates() { - send->sync_key_states(); + main::send->sync_key_states(); } DLLAPI UINT WINAPI IbSendInput( @@ -163,5 +177,5 @@ DLLAPI UINT WINAPI IbSendInput( _In_reads_(cInputs) LPINPUT pInputs, _In_ int cbSize ) { - return send->send_input(pInputs, cInputs); + return main::send->send_input(pInputs, cInputs); } \ No newline at end of file diff --git a/AhkDll.Test/AhkDll.Test.cpp b/Simulator/test/test.cpp similarity index 98% rename from AhkDll.Test/AhkDll.Test.cpp rename to Simulator/test/test.cpp index 7ac097a..c325f0b 100644 --- a/AhkDll.Test/AhkDll.Test.cpp +++ b/Simulator/test/test.cpp @@ -1,7 +1,7 @@ -#include "../AhkDll/IbAhkSend.hpp" +#include using namespace Send; -#define BOOST_TEST_MODULE AhkDll.Test +#define BOOST_TEST_MODULE Test #include #include @@ -9,7 +9,7 @@ using namespace Send; #include #include #include -#include +#include #include "Vk.hpp" diff --git a/AhkDll.Test/Vk.hpp b/Simulator/test/vk.hpp similarity index 100% rename from AhkDll.Test/Vk.hpp rename to Simulator/test/vk.hpp