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>
|
<configuration>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||||
</startup>
|
</startup>
|
||||||
</configuration>
|
</configuration>
|
@@ -8,11 +8,12 @@
|
|||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>DD2Switcher</RootNamespace>
|
<RootNamespace>DD2Switcher</RootNamespace>
|
||||||
<AssemblyName>DD2Switcher</AssemblyName>
|
<AssemblyName>DD2Switcher</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<LangVersion>9.0</LangVersion>
|
<LangVersion>9.0</LangVersion>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace DD2Switcher {
|
namespace DD2Switcher {
|
||||||
public partial class Form1 : Form {
|
public partial class Form1 : Form {
|
||||||
public Form1() { InitializeComponent(); }
|
public Form1() {
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -12,8 +12,7 @@ public static class HotKeyManager {
|
|||||||
private static int _id;
|
private static int _id;
|
||||||
|
|
||||||
static HotKeyManager() {
|
static HotKeyManager() {
|
||||||
var messageLoop =
|
var messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); });
|
||||||
new Thread(delegate() { Application.Run(new MessageWindow()); });
|
|
||||||
messageLoop.Name = "MessageLoopThread";
|
messageLoop.Name = "MessageLoopThread";
|
||||||
messageLoop.IsBackground = true;
|
messageLoop.IsBackground = true;
|
||||||
messageLoop.Start();
|
messageLoop.Start();
|
||||||
@@ -24,18 +23,15 @@ public static class HotKeyManager {
|
|||||||
public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
|
public static int RegisterHotKey(Keys key, KeyModifiers modifiers) {
|
||||||
_windowReadyEvent.WaitOne();
|
_windowReadyEvent.WaitOne();
|
||||||
var id = Interlocked.Increment(ref _id);
|
var id = Interlocked.Increment(ref _id);
|
||||||
_wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id,
|
_wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key);
|
||||||
(uint)modifiers, (uint)key);
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UnregisterHotKey(int id) {
|
public static void UnregisterHotKey(int id) {
|
||||||
_wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd,
|
_wnd.Invoke(new UnRegisterHotKeyDelegate(UnRegisterHotKeyInternal), _hwnd, id);
|
||||||
id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RegisterHotKeyInternal(IntPtr hwnd, int id,
|
private static void RegisterHotKeyInternal(IntPtr hwnd, int id, uint modifiers, uint key) {
|
||||||
uint modifiers, uint key) {
|
|
||||||
RegisterHotKey(hwnd, id, modifiers, key);
|
RegisterHotKey(hwnd, id, modifiers, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,14 +45,12 @@ public static class HotKeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32", SetLastError = true)]
|
[DllImport("user32", SetLastError = true)]
|
||||||
private static extern bool RegisterHotKey(IntPtr hWnd, int id,
|
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
|
||||||
uint fsModifiers, uint vk);
|
|
||||||
|
|
||||||
[DllImport("user32", SetLastError = true)]
|
[DllImport("user32", SetLastError = true)]
|
||||||
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
|
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
|
||||||
|
|
||||||
private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id,
|
private delegate void RegisterHotKeyDelegate(IntPtr hwnd, int id, uint modifiers, uint key);
|
||||||
uint modifiers, uint key);
|
|
||||||
|
|
||||||
private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
|
private delegate void UnRegisterHotKeyDelegate(IntPtr hwnd, int id);
|
||||||
|
|
||||||
@@ -102,11 +96,5 @@ public class HotKeyEventArgs : EventArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum KeyModifiers {
|
public enum KeyModifiers { Alt = 1, Control = 2, Shift = 4, Windows = 8, NoRepeat = 0x4000 }
|
||||||
Alt = 1,
|
|
||||||
Control = 2,
|
|
||||||
Shift = 4,
|
|
||||||
Windows = 8,
|
|
||||||
NoRepeat = 0x4000
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -28,8 +28,7 @@ internal static class Program {
|
|||||||
static extern bool AllocConsole();
|
static extern bool AllocConsole();
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
|
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
|
||||||
int dwExtraInfo);
|
|
||||||
|
|
||||||
private static void CleanWindows() {
|
private static void CleanWindows() {
|
||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
@@ -37,8 +36,7 @@ internal static class Program {
|
|||||||
if (window == null)
|
if (window == null)
|
||||||
continue;
|
continue;
|
||||||
if (window.MainWindowHandle == IntPtr.Zero) {
|
if (window.MainWindowHandle == IntPtr.Zero) {
|
||||||
Console.WriteLine(
|
Console.WriteLine($"Window at index {i} has no main window, removing from tracked windows");
|
||||||
$"Window at index {i} has no main window, removing from tracked windows");
|
|
||||||
windows[i] = null;
|
windows[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,8 +144,7 @@ internal static class Program {
|
|||||||
|
|
||||||
// Add the new process at the first null slot
|
// Add the new process at the first null slot
|
||||||
windows[firstNullIndex] = process;
|
windows[firstNullIndex] = process;
|
||||||
Console.WriteLine(
|
Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
|
||||||
$"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static void TrackWows() {
|
// private static void TrackWows() {
|
||||||
@@ -189,8 +186,7 @@ internal static class Program {
|
|||||||
for (int i = 0; i < NumProc; i++) {
|
for (int i = 0; i < NumProc; i++) {
|
||||||
var window = windows[i];
|
var window = windows[i];
|
||||||
if (window == null) {
|
if (window == null) {
|
||||||
Console.WriteLine(
|
Console.WriteLine($"Adding foreground window to tracked at index {i}...");
|
||||||
$"Adding foreground window to tracked at index {i}...");
|
|
||||||
windows[i] = process;
|
windows[i] = process;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -203,9 +199,9 @@ internal static class Program {
|
|||||||
windows[i] = windows[index];
|
windows[i] = windows[index];
|
||||||
windows[index] = window;
|
windows[index] = window;
|
||||||
Console.WriteLine($"Swapped window at index {i} to {index}");
|
Console.WriteLine($"Swapped window at index {i} to {index}");
|
||||||
// Toggle scroll lock off
|
// Toggle caps lock off
|
||||||
keybd_event(0x91, 0, 0, 0); // KEYEVENTF_KEYDOWN
|
keybd_event(0x14, 0, 0, 0); // KEYEVENTF_KEYDOWN
|
||||||
keybd_event(0x91, 0, 0x0002, 0); // KEYEVENTF_KEYUP
|
keybd_event(0x14, 0, 0x0002, 0); // KEYEVENTF_KEYUP
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,8 +218,7 @@ internal static class Program {
|
|||||||
|
|
||||||
var window = windows[index];
|
var window = windows[index];
|
||||||
if (window == null || window.MainWindowHandle == IntPtr.Zero) {
|
if (window == null || window.MainWindowHandle == IntPtr.Zero) {
|
||||||
Console.WriteLine(
|
Console.WriteLine($"Window at index {index} does not exist, removing from tracked windows");
|
||||||
$"Window at index {index} does not exist, removing from tracked windows");
|
|
||||||
windows[index] = null;
|
windows[index] = null;
|
||||||
} else {
|
} else {
|
||||||
SetForegroundWindow(window.MainWindowHandle);
|
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]
|
[STAThread]
|
||||||
private static void Main() {
|
private static void Main() {
|
||||||
@@ -243,20 +240,17 @@ internal static class Program {
|
|||||||
var currentProcess = Process.GetCurrentProcess();
|
var currentProcess = Process.GetCurrentProcess();
|
||||||
|
|
||||||
foreach (var process in processes)
|
foreach (var process in processes)
|
||||||
if (process.Id != currentProcess.Id &&
|
if (process.Id != currentProcess.Id && process.ProcessName == currentProcess.ProcessName) {
|
||||||
process.ProcessName == currentProcess.ProcessName) {
|
|
||||||
process.Kill();
|
process.Kill();
|
||||||
Process.GetCurrentProcess().Kill();
|
Process.GetCurrentProcess().Kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
HotKeyManager.RegisterHotKey(Keys.Scroll, KeyModifiers.NoRepeat);
|
HotKeyManager.RegisterHotKey(Keys.Capital, KeyModifiers.NoRepeat);
|
||||||
// Register main number keys (0-9)
|
// Register main number keys (0-9)
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++) HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt);
|
||||||
HotKeyManager.RegisterHotKey(Keys.D0 + i, KeyModifiers.Alt);
|
|
||||||
|
|
||||||
// Register numpad keys (1-9)
|
// Register numpad keys (1-9)
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++) HotKeyManager.RegisterHotKey(Keys.NumPad1 + i, KeyModifiers.Alt);
|
||||||
HotKeyManager.RegisterHotKey(Keys.NumPad1 + i, KeyModifiers.Alt);
|
|
||||||
|
|
||||||
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Alt);
|
||||||
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed;
|
||||||
@@ -277,7 +271,7 @@ internal static class Program {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e.Modifiers == KeyModifiers.Alt) {
|
if (e.Modifiers == KeyModifiers.Alt) {
|
||||||
if (IsScrollLockOn()) {
|
if (IsCapsLockOn()) {
|
||||||
Swap(index);
|
Swap(index);
|
||||||
} else {
|
} else {
|
||||||
TabTo(index);
|
TabTo(index);
|
||||||
@@ -285,10 +279,8 @@ internal static class Program {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.CancelKeyPress +=
|
Console.CancelKeyPress += (sender, e) => { Process.GetCurrentProcess().Kill(); };
|
||||||
(sender, e) => { Process.GetCurrentProcess().Kill(); };
|
while (true) System.Threading.Thread.Sleep(100000);
|
||||||
while (true)
|
|
||||||
System.Threading.Thread.Sleep(100000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
DD2Switcher/Properties/Resources.Designer.cs
generated
12
DD2Switcher/Properties/Resources.Designer.cs
generated
@@ -18,18 +18,17 @@ using System;
|
|||||||
// class via a tool like ResGen or Visual Studio.
|
// class via a tool like ResGen or Visual Studio.
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
// with the /str option, or rebuild your VS project.
|
// with the /str option, or rebuild your VS project.
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder",
|
||||||
"System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
"17.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
internal class Resources {
|
internal class Resources {
|
||||||
|
|
||||||
private static global::System.Resources.ResourceManager resourceMan;
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance",
|
||||||
"Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
"CA1811:AvoidUncalledPrivateCode")]
|
||||||
internal Resources() {}
|
internal Resources() {}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -40,8 +39,7 @@ internal class Resources {
|
|||||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
get {
|
get {
|
||||||
if (object.ReferenceEquals(resourceMan, null)) {
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
global::System.Resources.ResourceManager temp =
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(
|
||||||
new global::System.Resources.ResourceManager(
|
|
||||||
"DD2Switcher.Properties.Resources", typeof(Resources).Assembly);
|
"DD2Switcher.Properties.Resources", typeof(Resources).Assembly);
|
||||||
resourceMan = temp;
|
resourceMan = temp;
|
||||||
}
|
}
|
||||||
|
10
DD2Switcher/Properties/Settings.Designer.cs
generated
10
DD2Switcher/Properties/Settings.Designer.cs
generated
@@ -9,15 +9,13 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace DD2Switcher.Properties {
|
namespace DD2Switcher.Properties {
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
|
||||||
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator",
|
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.0.0")]
|
||||||
"11.0.0.0")]
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||||
internal sealed partial class Settings
|
|
||||||
: global::System.Configuration.ApplicationSettingsBase {
|
|
||||||
private static Settings defaultInstance =
|
private static Settings defaultInstance =
|
||||||
((Settings)(global::System.Configuration.ApplicationSettingsBase
|
((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
.Synchronized(new Settings())));
|
|
||||||
|
|
||||||
public static Settings Default {
|
public static Settings Default {
|
||||||
get { return defaultInstance; }
|
get { return defaultInstance; }
|
||||||
|
Reference in New Issue
Block a user