Use capslock instead of scrollock and code format (sadly in one...)
This commit is contained in:
@@ -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>
|
@@ -1,6 +1,6 @@
|
||||
<?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')"/>
|
||||
<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>
|
||||
@@ -8,11 +8,12 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>DD2Switcher</RootNamespace>
|
||||
<AssemblyName>DD2Switcher</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<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>
|
||||
@@ -36,17 +37,17 @@
|
||||
<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"/>
|
||||
<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">
|
||||
@@ -55,9 +56,9 @@
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="HotKeyManager.cs"/>
|
||||
<Compile Include="Program.cs"/>
|
||||
<Compile Include="Properties\AssemblyInfo.cs"/>
|
||||
<Compile Include="HotKeyManager.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
@@ -78,10 +79,10 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config"/>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="beep.wav"/>
|
||||
<Content Include="beep.wav" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
4
DD2Switcher/Form1.Designer.cs
generated
4
DD2Switcher/Form1.Designer.cs
generated
@@ -1,5 +1,5 @@
|
||||
namespace DD2Switcher {
|
||||
partial class Form1 {
|
||||
partial class Form1 {
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
@@ -32,5 +32,5 @@ partial class Form1 {
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DD2Switcher {
|
||||
public partial class Form1 : Form {
|
||||
public Form1() { InitializeComponent(); }
|
||||
}
|
||||
public partial class Form1 : Form {
|
||||
public Form1() {
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@ using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DD2Switcher {
|
||||
public static class HotKeyManager {
|
||||
public static class HotKeyManager {
|
||||
private static volatile MessageWindow _wnd;
|
||||
private static volatile IntPtr _hwnd;
|
||||
private static readonly ManualResetEvent _windowReadyEvent = new(false);
|
||||
@@ -12,8 +12,7 @@ public static class HotKeyManager {
|
||||
private static int _id;
|
||||
|
||||
static HotKeyManager() {
|
||||
var messageLoop =
|
||||
new Thread(delegate() { Application.Run(new MessageWindow()); });
|
||||
var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
|
||||
messageLoop.Name = "MessageLoopThread";
|
||||
messageLoop.IsBackground = true;
|
||||
messageLoop.Start();
|
||||
@@ -24,18 +23,15 @@ public static class HotKeyManager {
|
||||
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);
|
||||
_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);
|
||||
_wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
|
||||
}
|
||||
|
||||
private static void RegisterHotKeyInternal(IntPtr hwnd, int id,
|
||||
uint modifiers, uint key) {
|
||||
private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) {
|
||||
RegisterHotKey(hwnd, id, modifiers, key);
|
||||
}
|
||||
|
||||
@@ -49,14 +45,12 @@ public static class HotKeyManager {
|
||||
}
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern bool RegisterHotKey(IntPtr hWnd, int id,
|
||||
uint fsModifiers, uint vk);
|
||||
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 RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
|
||||
|
||||
private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
|
||||
|
||||
@@ -83,9 +77,9 @@ public static class HotKeyManager {
|
||||
base.SetVisibleCore(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class HotKeyEventArgs : EventArgs {
|
||||
public class HotKeyEventArgs : EventArgs {
|
||||
public readonly Keys Key;
|
||||
public readonly KeyModifiers Modifiers;
|
||||
|
||||
@@ -99,14 +93,8 @@ public class HotKeyEventArgs : EventArgs {
|
||||
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 }
|
||||
}
|
@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DD2Switcher {
|
||||
internal static class Program {
|
||||
internal static class Program {
|
||||
private static int NumProc = 19;
|
||||
private static Process[] windows = new Process[NumProc];
|
||||
private static int ActiveIndex = -1;
|
||||
@@ -28,8 +28,7 @@ internal static class Program {
|
||||
static extern bool AllocConsole();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
|
||||
int dwExtraInfo);
|
||||
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++) {
|
||||
@@ -37,8 +36,7 @@ internal static class Program {
|
||||
if (window == null)
|
||||
continue;
|
||||
if (window.MainWindowHandle == IntPtr.Zero) {
|
||||
Console.WriteLine(
|
||||
$"Window at index {i} has no main window, removing from tracked windows");
|
||||
Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
|
||||
windows[i] = null;
|
||||
}
|
||||
}
|
||||
@@ -146,8 +144,7 @@ internal static class Program {
|
||||
|
||||
// Add the new process at the first null slot
|
||||
windows[firstNullIndex] = process;
|
||||
Console.WriteLine(
|
||||
$"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
|
||||
Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
|
||||
}
|
||||
|
||||
// private static void TrackWows() {
|
||||
@@ -189,8 +186,7 @@ internal static class Program {
|
||||
for (int i = 0; i < NumProc; i++) {
|
||||
var window = windows[i];
|
||||
if (window == null) {
|
||||
Console.WriteLine(
|
||||
$"Adding foreground window to tracked at index {i}...");
|
||||
Console.WriteLine($"Adding foreground window to tracked at index {i}...");
|
||||
windows[i] = process;
|
||||
break;
|
||||
}
|
||||
@@ -203,9 +199,9 @@ internal static class Program {
|
||||
windows[i] = windows[index];
|
||||
windows[index] = window;
|
||||
Console.WriteLine($"Swapped window at index {i} to {index}");
|
||||
// Toggle scroll lock off
|
||||
keybd_event(0x91, 0, 0, 0); // KEYEVENTF_KEYDOWN
|
||||
keybd_event(0x91, 0, 0x0002, 0); // KEYEVENTF_KEYUP
|
||||
// Toggle caps lock off
|
||||
keybd_event(0x14, 0, 0, 0); // KEYEVENTF_KEYDOWN
|
||||
keybd_event(0x14, 0, 0x0002, 0); // KEYEVENTF_KEYUP
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -222,8 +218,7 @@ internal static class Program {
|
||||
|
||||
var window = windows[index];
|
||||
if (window == null || window.MainWindowHandle == IntPtr.Zero) {
|
||||
Console.WriteLine(
|
||||
$"Window at index {index} does not exist, removing from tracked windows");
|
||||
Console.WriteLine($"Window at index {index} does not exist, removing from tracked windows");
|
||||
windows[index] = null;
|
||||
} else {
|
||||
SetForegroundWindow(window.MainWindowHandle);
|
||||
@@ -233,7 +228,9 @@ internal static class Program {
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsScrollLockOn() { return (GetKeyState(0x91) & 1) == 1; }
|
||||
private static bool IsCapsLockOn() {
|
||||
return (GetKeyState(0x14) & 1) == 1;
|
||||
}
|
||||
|
||||
[STAThread]
|
||||
private static void Main() {
|
||||
@@ -243,20 +240,17 @@ internal static class Program {
|
||||
var currentProcess = Process.GetCurrentProcess();
|
||||
|
||||
foreach (var process in processes)
|
||||
if (process.Id != currentProcess.Id &&
|
||||
process.ProcessName == currentProcess.ProcessName) {
|
||||
if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
|
||||
process.Kill();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
||||
HotKeyManager.RegisterHotKey(Keys.Scroll, KeyModifiers.NoRepeat);
|
||||
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);
|
||||
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);
|
||||
for (int i = 0; i < 9; i++) HotKeyManager.RegisterHotKey(Keys.NumPad1 + i, KeyModifiers.Alt);
|
||||
|
||||
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
||||
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
||||
@@ -277,7 +271,7 @@ internal static class Program {
|
||||
}
|
||||
|
||||
if (e.Modifiers == KeyModifiers.Alt) {
|
||||
if (IsScrollLockOn()) {
|
||||
if (IsCapsLockOn()) {
|
||||
Swap(index);
|
||||
} else {
|
||||
TabTo(index);
|
||||
@@ -285,10 +279,8 @@ internal static class Program {
|
||||
}
|
||||
}
|
||||
|
||||
Console.CancelKeyPress +=
|
||||
(sender, e) => { Process.GetCurrentProcess().Kill(); };
|
||||
while (true)
|
||||
System.Threading.Thread.Sleep(100000);
|
||||
Console.CancelKeyPress += (sender, e) => { Process.GetCurrentProcess().Kill(); };
|
||||
while (true) System.Threading.Thread.Sleep(100000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
DD2Switcher/Properties/Resources.Designer.cs
generated
36
DD2Switcher/Properties/Resources.Designer.cs
generated
@@ -9,27 +9,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
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")]
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance",
|
||||
"CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {}
|
||||
|
||||
/// <summary>
|
||||
@@ -40,8 +39,7 @@ internal class Resources {
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp =
|
||||
new global::System.Resources.ResourceManager(
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(
|
||||
"DD2Switcher.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
@@ -59,5 +57,5 @@ internal class Resources {
|
||||
get { return resourceCulture; }
|
||||
set { resourceCulture = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
DD2Switcher/Properties/Settings.Designer.cs
generated
16
DD2Switcher/Properties/Settings.Designer.cs
generated
@@ -9,18 +9,16 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace DD2Switcher.Properties {
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
|
||||
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator",
|
||||
"11.0.0.0")]
|
||||
internal sealed partial class Settings
|
||||
: global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
[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())));
|
||||
((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get { return defaultInstance; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user