Use capslock instead of scrollock and code format (sadly in one...)

This commit is contained in:
2025-08-15 14:13:33 +02:00
parent cf804a6c8b
commit 603bc488e8
8 changed files with 495 additions and 516 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -2,6 +2,8 @@
namespace DD2Switcher {
public partial class Form1 : Form {
public Form1() { InitializeComponent(); }
public Form1() {
InitializeComponent();
}
}
}

View File

@@ -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);
@@ -102,11 +96,5 @@ public class HotKeyEventArgs : EventArgs {
}
[Flags]
public enum KeyModifiers {
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8,
NoRepeat = 0x4000
}
public enum KeyModifiers { Alt = 1, Control = 2, Shift = 4, Windows = 8, NoRepeat = 0x4000 }
}

View File

@@ -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);
}
}
}

View File

@@ -18,18 +18,17 @@ using System;
// 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.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;
}

View File

@@ -9,15 +9,13 @@
//------------------------------------------------------------------------------
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 {
"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; }