Compare commits
24 Commits
go-rework
...
458a466c15
Author | SHA1 | Date | |
---|---|---|---|
458a466c15 | |||
5e95937ae9 | |||
48d3af7c94 | |||
603bc488e8 | |||
cf804a6c8b | |||
9de3ae43d5 | |||
886258e4c3 | |||
b5446516e4 | |||
c28bc4ac69 | |||
04cb6c1e38 | |||
50f7c777b3 | |||
740d3d8b01 | |||
6a766a5441 | |||
be2c6f7829 | |||
7beb55e3ce | |||
4aaedac17c | |||
6a4e25cdb8 | |||
a9024539a4 | |||
6cee7038bd | |||
197f098f67 | |||
bd24acde46 | |||
3872c5181f | |||
fd68adaff8 | |||
289f03fbfc |
3
.clang-format
Normal file
3
.clang-format
Normal file
@@ -0,0 +1,3 @@
|
||||
BasedOnStyle: Google
|
||||
IndentWidth: 4
|
||||
ColumnLimit: 120
|
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,5 +1,4 @@
|
||||
.idea
|
||||
**/Debug
|
||||
**/Properties
|
||||
obj
|
||||
bin
|
||||
bin
|
||||
.vs
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
@@ -1,88 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" 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>{2AC26899-8E27-4B96-85A9-C387186EAD27}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>DD2Switcher</RootNamespace>
|
||||
<AssemblyName>DD2Switcher</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<LangVersion>10</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32bit>false</Prefer32bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32bit>false</Prefer32bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System"/>
|
||||
<Reference Include="System.Core"/>
|
||||
<Reference Include="System.Xml.Linq"/>
|
||||
<Reference Include="System.Data.DataSetExtensions"/>
|
||||
<Reference Include="Microsoft.CSharp"/>
|
||||
<Reference Include="System.Data"/>
|
||||
<Reference Include="System.Deployment"/>
|
||||
<Reference Include="System.Drawing"/>
|
||||
<Reference Include="System.Net.Http"/>
|
||||
<Reference Include="System.Windows.Forms"/>
|
||||
<Reference Include="System.Xml"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="HotKeyManager.cs"/>
|
||||
<Compile Include="Pixel.cs"/>
|
||||
<Compile Include="Program.cs"/>
|
||||
<Compile Include="Properties\AssemblyInfo.cs"/>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="beep.wav"/>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
|
||||
<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>{2AC26899-8E27-4B96-85A9-C387186EAD27}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>DD2Switcher</RootNamespace>
|
||||
<AssemblyName>DD2Switcher</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32bit>false</Prefer32bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32bit>false</Prefer32bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="HotKeyManager.cs" />
|
||||
<Compile Include="KeyboardHook.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="beep.wav" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
22
DD2Switcher/Form1.Designer.cs
generated
22
DD2Switcher/Form1.Designer.cs
generated
@@ -1,7 +1,5 @@
|
||||
namespace DD2Switcher
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
namespace DD2Switcher {
|
||||
partial class Form1 {
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
@@ -10,31 +8,29 @@
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
/// <param name="disposing">true if managed resources should be disposed;
|
||||
/// otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) {
|
||||
if (disposing && (components != null)) {
|
||||
components.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
private void InitializeComponent() {
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DD2Switcher;
|
||||
|
||||
public partial class Form1 : Form {
|
||||
public Form1() {
|
||||
InitializeComponent();
|
||||
namespace DD2Switcher {
|
||||
public partial class Form1 : Form {
|
||||
public Form1() {
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,103 +3,98 @@ using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DD2Switcher;
|
||||
namespace DD2Switcher {
|
||||
public static class HotKeyManager {
|
||||
private static volatile MessageWindow _wnd;
|
||||
private static volatile IntPtr _hwnd;
|
||||
private static readonly ManualResetEvent _windowReadyEvent = new(false);
|
||||
|
||||
public static class HotKeyManager {
|
||||
private static volatile MessageWindow _wnd;
|
||||
private static volatile IntPtr _hwnd;
|
||||
private static readonly ManualResetEvent _windowReadyEvent = new(false);
|
||||
private static int _id;
|
||||
|
||||
private static int _id;
|
||||
|
||||
static HotKeyManager() {
|
||||
var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
|
||||
messageLoop.Name = "MessageLoopThread";
|
||||
messageLoop.IsBackground = true;
|
||||
messageLoop.Start();
|
||||
}
|
||||
|
||||
public static event EventHandler<HotKeyEventArgs> HotKeyPressed;
|
||||
|
||||
public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
|
||||
_windowReadyEvent.WaitOne();
|
||||
var id = Interlocked.Increment(ref _id);
|
||||
_wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key);
|
||||
return id;
|
||||
}
|
||||
|
||||
public static void UnregisterHotKey(int id) {
|
||||
_wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
|
||||
}
|
||||
|
||||
private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) {
|
||||
RegisterHotKey(hwnd, id, modifiers, key);
|
||||
}
|
||||
|
||||
private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) {
|
||||
UnregisterHotKey(_hwnd, id);
|
||||
}
|
||||
|
||||
private static void OnHotKeyPressed(HotKeyEventArgs e) {
|
||||
if (HotKeyPressed != null) HotKeyPressed(null, e);
|
||||
}
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
|
||||
|
||||
private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
|
||||
|
||||
private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
|
||||
|
||||
private class MessageWindow : Form {
|
||||
private const int WM_HOTKEY = 0x312;
|
||||
|
||||
public MessageWindow() {
|
||||
_wnd = this;
|
||||
_hwnd = Handle;
|
||||
_windowReadyEvent.Set();
|
||||
static HotKeyManager() {
|
||||
var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
|
||||
messageLoop.Name = "MessageLoopThread";
|
||||
messageLoop.IsBackground = true;
|
||||
messageLoop.Start();
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m) {
|
||||
if (m.Msg == WM_HOTKEY) {
|
||||
var e = new HotKeyEventArgs(m.LParam);
|
||||
OnHotKeyPressed(e);
|
||||
public static event EventHandler<HotKeyEventArgs> HotKeyPressed;
|
||||
|
||||
public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
|
||||
_windowReadyEvent.WaitOne();
|
||||
var id = Interlocked.Increment(ref _id);
|
||||
_wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key);
|
||||
return id;
|
||||
}
|
||||
|
||||
public static void UnregisterHotKey(int id) {
|
||||
_wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
|
||||
}
|
||||
|
||||
private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) {
|
||||
RegisterHotKey(hwnd, id, modifiers, key);
|
||||
}
|
||||
|
||||
private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) {
|
||||
UnregisterHotKey(_hwnd, id);
|
||||
}
|
||||
|
||||
private static void OnHotKeyPressed(HotKeyEventArgs e) {
|
||||
if (HotKeyPressed != null)
|
||||
HotKeyPressed(null, e);
|
||||
}
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
|
||||
|
||||
private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
|
||||
|
||||
private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
|
||||
|
||||
private class MessageWindow : Form {
|
||||
private const int WM_HOTKEY = 0x312;
|
||||
|
||||
public MessageWindow() {
|
||||
_wnd = this;
|
||||
_hwnd = Handle;
|
||||
_windowReadyEvent.Set();
|
||||
}
|
||||
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
protected override void WndProc(ref Message m) {
|
||||
if (m.Msg == WM_HOTKEY) {
|
||||
var e = new HotKeyEventArgs(m.LParam);
|
||||
OnHotKeyPressed(e);
|
||||
}
|
||||
|
||||
protected override void SetVisibleCore(bool value) {
|
||||
// Ensure the window never becomes visible
|
||||
base.SetVisibleCore(false);
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
|
||||
protected override void SetVisibleCore(bool value) {
|
||||
// Ensure the window never becomes visible
|
||||
base.SetVisibleCore(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class HotKeyEventArgs : EventArgs {
|
||||
public readonly Keys Key;
|
||||
public readonly KeyModifiers Modifiers;
|
||||
public class HotKeyEventArgs : EventArgs {
|
||||
public readonly Keys Key;
|
||||
public readonly KeyModifiers Modifiers;
|
||||
|
||||
public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
|
||||
Key = key;
|
||||
Modifiers = modifiers;
|
||||
public HotKeyEventArgs(Keys key, KeyModifiers modifiers) {
|
||||
Key = key;
|
||||
Modifiers = modifiers;
|
||||
}
|
||||
|
||||
public HotKeyEventArgs(IntPtr hotKeyParam) {
|
||||
var param = (uint)hotKeyParam.ToInt64();
|
||||
Key = (Keys)((param & 0xffff0000) >> 16);
|
||||
Modifiers = (KeyModifiers)(param & 0x0000ffff);
|
||||
}
|
||||
}
|
||||
|
||||
public HotKeyEventArgs(IntPtr hotKeyParam) {
|
||||
var param = (uint)hotKeyParam.ToInt64();
|
||||
Key = (Keys)((param & 0xffff0000) >> 16);
|
||||
Modifiers = (KeyModifiers)(param & 0x0000ffff);
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum KeyModifiers {
|
||||
Alt = 1,
|
||||
Control = 2,
|
||||
Shift = 4,
|
||||
Windows = 8,
|
||||
NoRepeat = 0x4000
|
||||
[Flags]
|
||||
public enum KeyModifiers { Alt = 1, Control = 2, Shift = 4, Windows = 8, NoRepeat = 0x4000 }
|
||||
}
|
64
DD2Switcher/KeyboardHook.cs
Normal file
64
DD2Switcher/KeyboardHook.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
class KeyboardHook {
|
||||
private const int WH_KEYBOARD_LL = 13;
|
||||
private const int WM_KEYDOWN = 0x0104;
|
||||
private const int WM_KEYUP = 0x0101;
|
||||
private static LowLevelKeyboardProc _proc = HookCallback;
|
||||
private static IntPtr _hookID = IntPtr.Zero;
|
||||
|
||||
public static int previousEvent = 0;
|
||||
public static event EventHandler<int> KeyDown;
|
||||
public static event EventHandler<int> KeyUp;
|
||||
|
||||
public static void Start() {
|
||||
_hookID = SetHook(_proc);
|
||||
}
|
||||
|
||||
public static void Stop() {
|
||||
UnhookWindowsHookEx(_hookID);
|
||||
}
|
||||
|
||||
private static 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 delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) {
|
||||
if (nCode >= 0) {
|
||||
int vkCode = Marshal.ReadInt32(lParam);
|
||||
int pero = (int)wParam * 1000 + vkCode;
|
||||
if (pero != previousEvent) {
|
||||
if (wParam == (IntPtr)WM_KEYDOWN) {
|
||||
KeyDown?.Invoke(null, vkCode);
|
||||
} else if (wParam == (IntPtr)WM_KEYUP) {
|
||||
KeyUp?.Invoke(null, vkCode);
|
||||
}
|
||||
previousEvent = pero;
|
||||
} else {
|
||||
Console.WriteLine("Same event");
|
||||
}
|
||||
}
|
||||
return CallNextHookEx(_hookID, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
|
||||
namespace DD2Switcher;
|
||||
|
||||
public class Pixel {
|
||||
public Pixel(int x, int y, int R, int G, int B) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.R = R;
|
||||
this.G = G;
|
||||
this.B = B;
|
||||
}
|
||||
|
||||
private int x { get; }
|
||||
private int y { get; }
|
||||
private int R { get; }
|
||||
private int G { get; }
|
||||
private int B { get; }
|
||||
|
||||
public bool ProcessBitmap(Bitmap bmp) {
|
||||
var tempPixel = bmp.GetPixel(x, y);
|
||||
return tempPixel.R >= R && tempPixel.B >= B && tempPixel.G >= G;
|
||||
}
|
||||
}
|
@@ -1,211 +1,360 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DD2Switcher;
|
||||
|
||||
internal static class Program {
|
||||
private static List<Process> processes = new();
|
||||
|
||||
private static Process activeProcess;
|
||||
private static readonly IntPtr defaultAffinity = new(0xFF000000);
|
||||
private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetForegroundWindow();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
static extern bool AllocConsole();
|
||||
|
||||
private static void AdjustAffinities() {
|
||||
List<Process> fuckedProcesses = new();
|
||||
|
||||
foreach (var process in processes)
|
||||
if (process != activeProcess) {
|
||||
try {
|
||||
process.ProcessorAffinity = defaultAffinity;
|
||||
}
|
||||
catch (Exception e) {
|
||||
fuckedProcesses.Add(process);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
activeProcess.ProcessorAffinity = fullAffinity;
|
||||
}
|
||||
catch (Exception e) {
|
||||
fuckedProcesses.Add(activeProcess);
|
||||
}
|
||||
|
||||
foreach (var fucked in fuckedProcesses)
|
||||
processes.Remove(fucked);
|
||||
}
|
||||
|
||||
private static void AdjustPriorities() {
|
||||
List<Process> fuckedProcesses = new();
|
||||
|
||||
foreach (var process in processes) {
|
||||
try {
|
||||
process.PriorityClass = ProcessPriorityClass.Idle;
|
||||
}
|
||||
catch (Exception e) {
|
||||
fuckedProcesses.Add(process);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
activeProcess.PriorityClass = ProcessPriorityClass.High;
|
||||
}
|
||||
catch (Exception e) {
|
||||
fuckedProcesses.Add(activeProcess);
|
||||
}
|
||||
|
||||
foreach (var fucked in fuckedProcesses)
|
||||
processes.Remove(fucked);
|
||||
}
|
||||
|
||||
private static void SwitchToProcess(int index) {
|
||||
Console.WriteLine("Switching to process at index " + index);
|
||||
if (index >= processes.Count) return;
|
||||
var targetWindowHandle = processes[processes.Count - 1 - index].MainWindowHandle;
|
||||
if (targetWindowHandle == IntPtr.Zero) {
|
||||
processes.RemoveAt(processes.Count - 1 - index);
|
||||
return;
|
||||
}
|
||||
SetForegroundWindow(targetWindowHandle);
|
||||
activeProcess = processes[processes.Count - 1 - index];
|
||||
AdjustAffinities();
|
||||
AdjustPriorities();
|
||||
}
|
||||
|
||||
private static void SwitchMainGame() {
|
||||
var foregroundWindow = GetForegroundWindow();
|
||||
Process foregroundGame = null;
|
||||
var foregroundGameIndex = -1;
|
||||
var exists = false;
|
||||
|
||||
foreach (var process in processes)
|
||||
if (foregroundWindow == process.MainWindowHandle) {
|
||||
exists = true;
|
||||
foregroundGame = process;
|
||||
foregroundGameIndex = processes.IndexOf(process);
|
||||
break;
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
var tempGame = processes[0];
|
||||
processes[0] = foregroundGame;
|
||||
processes[foregroundGameIndex] = tempGame;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ToggleGame() {
|
||||
Console.WriteLine("Toggling foreground window as tracked...");
|
||||
var foregroundWindow = GetForegroundWindow();
|
||||
var systemProcesses = Process.GetProcesses();
|
||||
Process foregroundProcess = null;
|
||||
|
||||
foreach (var process in systemProcesses)
|
||||
if (foregroundWindow == process.MainWindowHandle) {
|
||||
foregroundProcess = process;
|
||||
break;
|
||||
}
|
||||
|
||||
if (foregroundProcess == null) return;
|
||||
Console.WriteLine("Foreground process: " + foregroundProcess.ProcessName);
|
||||
var existingProcess = processes.Find(process => process.Id == foregroundProcess.Id);
|
||||
if (existingProcess != null) {
|
||||
Console.WriteLine("Removing foreground process from tracked...");
|
||||
processes.Remove(existingProcess);
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("Adding foreground process to tracked...");
|
||||
processes.Add(foregroundProcess);
|
||||
}
|
||||
}
|
||||
|
||||
[STAThread]
|
||||
private static void Main() {
|
||||
// AllocConsole();
|
||||
|
||||
var processes = Process.GetProcesses();
|
||||
var currentProcess = Process.GetCurrentProcess();
|
||||
|
||||
foreach (var process in processes)
|
||||
if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
|
||||
process.Kill();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
||||
|
||||
HotKeyManager.RegisterHotKey(Keys.D1, KeyModifiers.Alt);
|
||||
HotKeyManager.RegisterHotKey(Keys.D2, KeyModifiers.Alt);
|
||||
HotKeyManager.RegisterHotKey(Keys.D3, KeyModifiers.Alt);
|
||||
HotKeyManager.RegisterHotKey(Keys.D4, KeyModifiers.Alt);
|
||||
HotKeyManager.RegisterHotKey(Keys.D5, KeyModifiers.Alt);
|
||||
HotKeyManager.RegisterHotKey(Keys.D6, KeyModifiers.Alt);
|
||||
HotKeyManager.RegisterHotKey(Keys.D7, KeyModifiers.Alt);
|
||||
HotKeyManager.RegisterHotKey(Keys.D8, KeyModifiers.Alt);
|
||||
HotKeyManager.RegisterHotKey(Keys.D9, KeyModifiers.Alt);
|
||||
|
||||
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
||||
|
||||
// HotKeyManager.RegisterHotKey(Keys.Q, KeyModifiers.Alt);
|
||||
// HotKeyManager.RegisterHotKey(Keys.W, KeyModifiers.Alt);
|
||||
// HotKeyManager.RegisterHotKey(Keys.R, KeyModifiers.Alt);
|
||||
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
||||
|
||||
var pixelList = new System.Collections.Generic.List<Pixel>();
|
||||
// pixelList.Add(new Pixel(1401, 1234, 224, 224, 224));
|
||||
pixelList.Add(new Pixel(1359, 1235, 220, 220, 220));
|
||||
|
||||
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
|
||||
switch (e.Key) {
|
||||
case Keys.D1:
|
||||
SwitchToProcess(0);
|
||||
break;
|
||||
case Keys.D2:
|
||||
SwitchToProcess(1);
|
||||
break;
|
||||
case Keys.D3:
|
||||
SwitchToProcess(2);
|
||||
break;
|
||||
case Keys.D4:
|
||||
SwitchToProcess(3);
|
||||
break;
|
||||
case Keys.D5:
|
||||
SwitchToProcess(4);
|
||||
break;
|
||||
case Keys.D6:
|
||||
SwitchToProcess(5);
|
||||
break;
|
||||
case Keys.D7:
|
||||
SwitchToProcess(6);
|
||||
break;
|
||||
case Keys.D8:
|
||||
SwitchToProcess(7);
|
||||
break;
|
||||
case Keys.D9:
|
||||
SwitchToProcess(8);
|
||||
break;
|
||||
case Keys.Oemtilde:
|
||||
ToggleGame();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Console.CancelKeyPress += (sender, e) => {
|
||||
Process.GetCurrentProcess().Kill();
|
||||
};
|
||||
while (true)
|
||||
System.Threading.Thread.Sleep(100000);
|
||||
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using System.Threading;
|
||||
|
||||
namespace DD2Switcher {
|
||||
internal static class Program {
|
||||
private static int NumProc = 19;
|
||||
private static Process[] windows = new Process[NumProc];
|
||||
private static int ActiveIndex = -1;
|
||||
private static bool AltPressed = false;
|
||||
|
||||
// Simple list to track last 5 windows
|
||||
private static List<int> lastWindows = new List<int>();
|
||||
|
||||
private static readonly IntPtr defaultAffinity = new(0xFF000000);
|
||||
private static readonly IntPtr fullAffinity = new(0xFFFFFFFF);
|
||||
private static readonly KeyboardHook keyboardHook = new();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetForegroundWindow();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern short GetKeyState(int nVirtKey);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return:MarshalAs(UnmanagedType.Bool)]
|
||||
static extern bool AllocConsole();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
|
||||
|
||||
private static void CleanWindows() {
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
var window = windows[i];
|
||||
if (window == null)
|
||||
continue;
|
||||
if (window.MainWindowHandle == IntPtr.Zero) {
|
||||
Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
|
||||
windows[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AdjustAffinities() {
|
||||
CleanWindows();
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
var window = windows[i];
|
||||
if (window == null)
|
||||
continue;
|
||||
if (i != ActiveIndex) {
|
||||
try {
|
||||
window.ProcessorAffinity = defaultAffinity;
|
||||
} catch (Exception e) {
|
||||
windows[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var active = windows[ActiveIndex];
|
||||
if (active != null) {
|
||||
try {
|
||||
active.ProcessorAffinity = fullAffinity;
|
||||
} catch (Exception e) {
|
||||
windows[ActiveIndex] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AdjustPriorities() {
|
||||
CleanWindows();
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
var window = windows[i];
|
||||
if (window == null)
|
||||
continue;
|
||||
|
||||
if (i != ActiveIndex) {
|
||||
try {
|
||||
window.PriorityClass = ProcessPriorityClass.Idle;
|
||||
} catch (Exception e) {
|
||||
windows[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var active = windows[ActiveIndex];
|
||||
if (active != null) {
|
||||
try {
|
||||
active.PriorityClass = ProcessPriorityClass.High;
|
||||
} catch (Exception e) {
|
||||
windows[ActiveIndex] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Process GetForegroundProcess() {
|
||||
var foregroundWindow = GetForegroundWindow();
|
||||
var process = Process.GetProcesses();
|
||||
Process foregroundProcess = null;
|
||||
foreach (var p in process)
|
||||
if (foregroundWindow == p.MainWindowHandle) {
|
||||
foregroundProcess = p;
|
||||
break;
|
||||
}
|
||||
|
||||
if (foregroundProcess == null)
|
||||
return null;
|
||||
return foregroundProcess;
|
||||
}
|
||||
|
||||
private static Boolean ProcessTracked(int id) {
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
if (windows[i] != null && windows[i].Id == id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void Track(Process process) {
|
||||
// First find the first null slot
|
||||
int firstNullIndex = -1;
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
if (windows[i] == null) {
|
||||
firstNullIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstNullIndex == -1) {
|
||||
Console.WriteLine("No slots available for tracking");
|
||||
return;
|
||||
}
|
||||
|
||||
// Compact the array by shifting non-null elements to the left
|
||||
for (int i = firstNullIndex + 1; i < NumProc; i++) {
|
||||
if (windows[i] != null) {
|
||||
windows[firstNullIndex] = windows[i];
|
||||
windows[i] = null;
|
||||
firstNullIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the new process at the first null slot
|
||||
windows[firstNullIndex] = process;
|
||||
PushHistory(firstNullIndex);
|
||||
ActiveIndex = firstNullIndex;
|
||||
Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
|
||||
}
|
||||
|
||||
private static void TrackProcess() {
|
||||
CleanWindows();
|
||||
var foregroundWindow = GetForegroundWindow();
|
||||
var foregroundProcess = Process.GetProcesses().FirstOrDefault(p => p.MainWindowHandle == foregroundWindow);
|
||||
if (foregroundProcess == null) {
|
||||
Console.WriteLine("No foreground process found");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine($"Foreground process: {foregroundProcess.ProcessName} PID: {foregroundProcess.Id}");
|
||||
|
||||
var processes = Process.GetProcesses().OrderBy(p => p.Id).ToList();
|
||||
foreach (var process in processes) {
|
||||
// Console.WriteLine($"Checking {process.ProcessName} at pid {process.Id}");
|
||||
if (process.ProcessName == foregroundProcess.ProcessName) {
|
||||
Console.WriteLine($"Found {foregroundProcess.ProcessName} at pid {process.Id}");
|
||||
if (ProcessTracked(process.Id))
|
||||
continue;
|
||||
Track(process);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Swap(int index) {
|
||||
index = (index - 1) % NumProc;
|
||||
if (index < 0)
|
||||
index = NumProc - 1;
|
||||
if (index >= NumProc)
|
||||
return;
|
||||
CleanWindows();
|
||||
Console.WriteLine($"Swapping window at index {index}");
|
||||
var process = GetForegroundProcess();
|
||||
if (process == null)
|
||||
return;
|
||||
Console.WriteLine($"Foreground process: {process}");
|
||||
bool found = false;
|
||||
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
var window = windows[i];
|
||||
if (window != null && window.Id == process.Id) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
var window = windows[i];
|
||||
if (window == null) {
|
||||
Console.WriteLine($"Adding foreground window to tracked at index {i}...");
|
||||
windows[i] = process;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
var window = windows[i];
|
||||
if (window != null && window.Id == process.Id) {
|
||||
windows[i] = windows[index];
|
||||
windows[index] = window;
|
||||
Console.WriteLine($"Swapped window at index {i} to {index}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void TabTo(int index) {
|
||||
index = (index - 1) % NumProc;
|
||||
if (index < 0)
|
||||
index = NumProc - 1;
|
||||
if (index >= NumProc)
|
||||
return;
|
||||
CleanWindows();
|
||||
Console.WriteLine($"Tab to window at index {index}");
|
||||
|
||||
var window = windows[index];
|
||||
if (window == null || window.MainWindowHandle == IntPtr.Zero) {
|
||||
Console.WriteLine($"Window at index {index} does not exist, removing from tracked windows");
|
||||
windows[index] = null;
|
||||
} else {
|
||||
if (ActiveIndex != -1)
|
||||
PushHistory(ActiveIndex);
|
||||
|
||||
SetForegroundWindow(window.MainWindowHandle);
|
||||
ActiveIndex = index;
|
||||
AdjustAffinities();
|
||||
AdjustPriorities();
|
||||
}
|
||||
}
|
||||
|
||||
private static void TabToPrevious() {
|
||||
var foreground = GetForegroundProcess();
|
||||
if (!ProcessTracked(foreground.Id)) {
|
||||
Console.WriteLine("Foreground process not tracked, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
if (lastWindows.Count == 0) {
|
||||
Console.WriteLine("No previous window to switch to");
|
||||
return;
|
||||
}
|
||||
CleanWindows();
|
||||
|
||||
for (int i = lastWindows.Count - 1; i >= 0; i--) {
|
||||
int index = lastWindows[i];
|
||||
if (index != ActiveIndex) {
|
||||
TabTo(index+1); // Our windows are 1-indexed because... I don't remember why
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsCapsLockOn() {
|
||||
return (GetKeyState(0x14) & 1) == 1;
|
||||
}
|
||||
|
||||
private static void ToggleCapsLock() {
|
||||
keybd_event(0x14, 0, 0, 0); // KEYEVENTF_KEYDOWN
|
||||
keybd_event(0x14, 0, 0x0002, 0); // KEYEVENTF_KEYUP
|
||||
}
|
||||
|
||||
private static void PushHistory(int index) {
|
||||
lastWindows.Add(index);
|
||||
if (lastWindows.Count > 50)
|
||||
lastWindows.RemoveAt(0);
|
||||
}
|
||||
|
||||
[STAThread]
|
||||
private static void Main() {
|
||||
// AllocConsole();
|
||||
|
||||
var processes = Process.GetProcesses();
|
||||
var currentProcess = Process.GetCurrentProcess();
|
||||
|
||||
foreach (var process in processes)
|
||||
if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
|
||||
process.Kill();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
||||
bool onlyAlt = false;
|
||||
KeyboardHook.Start();
|
||||
KeyboardHook.KeyDown += (sender, e) => {
|
||||
Console.WriteLine($"Key down: {e}");
|
||||
if (e == 164 && !onlyAlt) {
|
||||
Console.WriteLine("Only alt");
|
||||
onlyAlt = true;
|
||||
} else {
|
||||
Console.WriteLine("Not only alt");
|
||||
onlyAlt = false;
|
||||
}
|
||||
};
|
||||
KeyboardHook.KeyUp += (sender, e) => {
|
||||
Console.WriteLine($"Key up: {e}");
|
||||
if (e == 164 && onlyAlt) { // Left alt
|
||||
Console.WriteLine("Tab to previous");
|
||||
onlyAlt = false;
|
||||
TabToPrevious();
|
||||
}
|
||||
};
|
||||
|
||||
HotKeyManager.RegisterHotKey(Keys.Capital, KeyModifiers.NoRepeat);
|
||||
// Register main number keys (0-9)
|
||||
for (int i = 0; i < 10; i++) HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt);
|
||||
|
||||
// Register numpad keys (1-9)
|
||||
for (int i = 0; i < 9; i++) HotKeyManager.RegisterHotKey(Keys.NumPad1 + i, KeyModifiers.Alt);
|
||||
|
||||
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
||||
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
||||
|
||||
void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) {
|
||||
if (e.Key == Keys.Oemtilde && e.Modifiers == KeyModifiers.Alt && IsCapsLockOn()) {
|
||||
TrackProcess();
|
||||
ToggleCapsLock();
|
||||
return;
|
||||
}
|
||||
|
||||
int index;
|
||||
if (e.Key >= Keys.D0 && e.Key <= Keys.D9) {
|
||||
index = e.Key - Keys.D0;
|
||||
} else if (e.Key >= Keys.NumPad1 && e.Key <= Keys.NumPad9) {
|
||||
index = 10 + (e.Key - Keys.NumPad1);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Modifiers == KeyModifiers.Alt) {
|
||||
if (IsCapsLockOn()) {
|
||||
Swap(index);
|
||||
ToggleCapsLock();
|
||||
} else {
|
||||
TabTo(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Console.CancelKeyPress += (sender, e) => { Process.GetCurrentProcess().Kill(); };
|
||||
Application.Run();
|
||||
KeyboardHook.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
DD2Switcher/Properties/AssemblyInfo.cs
Normal file
35
DD2Switcher/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly:AssemblyTitle("DD2Switcher")]
|
||||
[assembly:AssemblyDescription("")]
|
||||
[assembly:AssemblyConfiguration("")]
|
||||
[assembly:AssemblyCompany("")]
|
||||
[assembly:AssemblyProduct("DD2Switcher")]
|
||||
[assembly:AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly:AssemblyTrademark("")]
|
||||
[assembly:AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly:ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to
|
||||
// COM
|
||||
[assembly:Guid("2AC26899-8E27-4B96-85A9-C387186EAD27")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision
|
||||
// Numbers by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly:AssemblyVersion("1.0.0.0")]
|
||||
[assembly:AssemblyFileVersion("1.0.0.0")]
|
61
DD2Switcher/Properties/Resources.Designer.cs
generated
Normal file
61
DD2Switcher/Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,61 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace DD2Switcher.Properties {
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder",
|
||||
"17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance",
|
||||
"CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(
|
||||
global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(
|
||||
"DD2Switcher.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(
|
||||
global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get { return resourceCulture; }
|
||||
set { resourceCulture = value; }
|
||||
}
|
||||
}
|
||||
}
|
123
DD2Switcher/Properties/Resources.resx
Normal file
123
DD2Switcher/Properties/Resources.resx
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
|
||||
id="root"
|
||||
xmlns="">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="type" type="xsd:string"/>
|
||||
<xsd:attribute name="mimetype" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1"/>
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
</root>
|
24
DD2Switcher/Properties/Settings.Designer.cs
generated
Normal file
24
DD2Switcher/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,24 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace DD2Switcher.Properties {
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
|
||||
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
private static Settings defaultInstance =
|
||||
((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get { return defaultInstance; }
|
||||
}
|
||||
}
|
||||
}
|
7
DD2Switcher/Properties/Settings.settings
Normal file
7
DD2Switcher/Properties/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)"/>
|
||||
</Profiles>
|
||||
<Settings/>
|
||||
</SettingsFile>
|
Reference in New Issue
Block a user