This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37a4b2d
commit e2e2496
Showing
6 changed files
with
440 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FNFBot", "FNFBot\FNFBot.csproj", "{7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{7A9C6B6A-07AA-4E23-BD8F-A8CB29810205}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>FNFBot</RootNamespace> | ||
<AssemblyName>FNFBot</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="FNFDataAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<HintPath>..\..\FNFDataAPI\FNFDataAPI\bin\Debug\FNFDataAPI.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"> | ||
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="WindowsInput, Version=1.0.4.0, Culture=neutral, PublicKeyToken=9b287f7dc5073cad"> | ||
<HintPath>..\packages\InputSimulator.1.0.4.0\lib\net20\WindowsInput.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="KeyboardHook.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
using System.Windows.Forms; | ||
|
||
// | ||
// Not created by KadeDev, all rights go to rqnn (https://stackoverflow.com/a/46014022) | ||
// | ||
|
||
|
||
public class LowLevelKeyboardHook | ||
{ | ||
private const int WH_KEYBOARD_LL = 13; | ||
private const int WM_KEYDOWN = 0x0100; | ||
private const int WM_SYSKEYDOWN = 0x0104; | ||
private const int WM_KEYUP = 0x101; | ||
private const int WM_SYSKEYUP = 0x105; | ||
|
||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | ||
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); | ||
|
||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
private static extern bool UnhookWindowsHookEx(IntPtr hhk); | ||
|
||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | ||
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); | ||
|
||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] | ||
private static extern IntPtr GetModuleHandle(string lpModuleName); | ||
|
||
public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); | ||
|
||
public event EventHandler<Keys> OnKeyPressed; | ||
public event EventHandler<Keys> OnKeyUnpressed; | ||
|
||
private LowLevelKeyboardProc _proc; | ||
private IntPtr _hookID = IntPtr.Zero; | ||
|
||
public LowLevelKeyboardHook() | ||
{ | ||
_proc = HookCallback; | ||
} | ||
|
||
public void HookKeyboard() | ||
{ | ||
_hookID = SetHook(_proc); | ||
} | ||
|
||
public void UnHookKeyboard() | ||
{ | ||
UnhookWindowsHookEx(_hookID); | ||
} | ||
|
||
private IntPtr SetHook(LowLevelKeyboardProc proc) | ||
{ | ||
using (Process curProcess = Process.GetCurrentProcess()) | ||
using (ProcessModule curModule = curProcess.MainModule) | ||
{ | ||
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0); | ||
} | ||
} | ||
|
||
private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) | ||
{ | ||
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN) | ||
{ | ||
int vkCode = Marshal.ReadInt32(lParam); | ||
|
||
OnKeyPressed.Invoke(this, ((Keys)vkCode)); | ||
} | ||
|
||
return CallNextHookEx(_hookID, nCode, wParam, lParam); | ||
} | ||
} |
Oops, something went wrong.