From ac2dc4a25566d26622c153b44145c225beb19324 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 23 Sep 2020 00:55:29 -0700 Subject: [PATCH] Added mouse button swap in settings. --- KVMControl.cs | 25 ++++++++++++++++--- KVMSettingsForm.Designer.cs | 9 +++++++ KVMSettingsForm.cs | 6 +++++ KVMSettingsForm.resx | 49 ++++++++++++++++++++++++++++--------- KVMViewer.cs | 2 ++ 5 files changed, 76 insertions(+), 15 deletions(-) diff --git a/KVMControl.cs b/KVMControl.cs index e4868bf..370cdf4 100644 --- a/KVMControl.cs +++ b/KVMControl.cs @@ -37,6 +37,7 @@ namespace MeshCentralRouter private int compressionlevel = 60; // 60% compression private int scalinglevel = 1024; // 100% scale private int frameRate = 100; // Medium frame rate + private bool swamMouseButtons = false; private double scalefactor = 1; public List displays = new List(); public ushort currentDisp = 0; @@ -103,6 +104,8 @@ namespace MeshCentralRouter public int CompressionLevel { get { return compressionlevel; } set { compressionlevel = value; SendCompressionLevel(); } } public int ScalingLevel { get { return scalinglevel; } set { scalinglevel = value; SendCompressionLevel(); } } public int FrameRate { get { return frameRate; } set { frameRate = value; SendCompressionLevel(); } } + public bool SwamMouseButtons { get { return swamMouseButtons; } set { swamMouseButtons = value; } } + public double ScaleFactor { get { return scalefactor; } set { scalefactor = value; } } public void SetCompressionParams(int level, int scaling, int framerate) { compressionlevel = level; scalinglevel = scaling; frameRate = framerate; SendCompressionLevel(); } @@ -394,10 +397,24 @@ namespace MeshCentralRouter switch (e.Button) { case MouseButtons.Left: - buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_LEFTDOWN; + if (swamMouseButtons) + { + buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_RIGHTDOWN; + } + else + { + buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_LEFTDOWN; + } break; case MouseButtons.Right: - buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_RIGHTDOWN; + if (swamMouseButtons) + { + buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_LEFTDOWN; + } + else + { + buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_RIGHTDOWN; + } break; case MouseButtons.Middle: buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_MIDDLEDOWN; @@ -409,10 +426,10 @@ namespace MeshCentralRouter switch (e.Button) { case MouseButtons.Left: - buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_LEFTUP; + if (swamMouseButtons) { buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_RIGHTUP; } else { buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_LEFTUP; } break; case MouseButtons.Right: - buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_RIGHTUP; + if (swamMouseButtons) { buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_LEFTUP; } else { buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_RIGHTUP; } break; case MouseButtons.Middle: buttons |= (byte)KvmMouseButtonCommands.MOUSEEVENTF_MIDDLEUP; diff --git a/KVMSettingsForm.Designer.cs b/KVMSettingsForm.Designer.cs index 95de29a..ff14b04 100644 --- a/KVMSettingsForm.Designer.cs +++ b/KVMSettingsForm.Designer.cs @@ -40,6 +40,7 @@ this.label3 = new System.Windows.Forms.Label(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.label4 = new System.Windows.Forms.Label(); + this.swapMouseButtonsCheckBox = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); @@ -62,6 +63,7 @@ // groupBox1 // resources.ApplyResources(this.groupBox1, "groupBox1"); + this.groupBox1.Controls.Add(this.swapMouseButtonsCheckBox); this.groupBox1.Controls.Add(this.frameRateComboBox); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.scalingComboBox); @@ -119,6 +121,12 @@ resources.ApplyResources(this.label4, "label4"); this.label4.Name = "label4"; // + // swapMouseButtonsCheckBox + // + resources.ApplyResources(this.swapMouseButtonsCheckBox, "swapMouseButtonsCheckBox"); + this.swapMouseButtonsCheckBox.Name = "swapMouseButtonsCheckBox"; + this.swapMouseButtonsCheckBox.UseVisualStyleBackColor = true; + // // KVMSettingsForm // this.AcceptButton = this.okButton; @@ -155,5 +163,6 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.ComboBox qualityComboBox; private System.Windows.Forms.Label label3; + private System.Windows.Forms.CheckBox swapMouseButtonsCheckBox; } } \ No newline at end of file diff --git a/KVMSettingsForm.cs b/KVMSettingsForm.cs index a90c61e..ae432a6 100644 --- a/KVMSettingsForm.cs +++ b/KVMSettingsForm.cs @@ -118,6 +118,12 @@ namespace MeshCentralRouter } } + public bool SwamMouseButtons + { + get { return swapMouseButtonsCheckBox.Checked; } + set { swapMouseButtonsCheckBox.Checked = value; } + } + private void okButton_Click(object sender, EventArgs e) { DialogResult = System.Windows.Forms.DialogResult.OK; diff --git a/KVMSettingsForm.resx b/KVMSettingsForm.resx index fff727c..cc49c12 100644 --- a/KVMSettingsForm.resx +++ b/KVMSettingsForm.resx @@ -123,7 +123,7 @@ - 312, 182 + 312, 207 75, 23 @@ -151,7 +151,7 @@ Bottom, Right - 231, 182 + 231, 207 75, 23 @@ -177,6 +177,33 @@ Top, Bottom, Left, Right + + True + + + 128, 105 + + + 127, 17 + + + 10 + + + Swap Mouse Buttons + + + swapMouseButtonsCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 0 + Top, Left, Right @@ -199,7 +226,7 @@ groupBox1 - 0 + 1 True @@ -226,7 +253,7 @@ groupBox1 - 1 + 2 Top, Left, Right @@ -250,7 +277,7 @@ groupBox1 - 2 + 3 True @@ -277,7 +304,7 @@ groupBox1 - 3 + 4 Top, Left, Right @@ -301,7 +328,7 @@ groupBox1 - 4 + 5 True @@ -328,19 +355,19 @@ groupBox1 - 5 + 6 12, 68 - 375, 108 + 375, 133 2 - Compression Settings + Settings groupBox1 @@ -412,7 +439,7 @@ 6, 13 - 399, 217 + 399, 242 diff --git a/KVMViewer.cs b/KVMViewer.cs index 280bcc7..239a88a 100644 --- a/KVMViewer.cs +++ b/KVMViewer.cs @@ -315,9 +315,11 @@ namespace MeshCentralRouter form.Compression = kvmControl.CompressionLevel; form.Scaling = kvmControl.ScalingLevel; form.FrameRate = kvmControl.FrameRate; + form.SwamMouseButtons = kvmControl.SwamMouseButtons; if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { kvmControl.SetCompressionParams(form.Compression, form.Scaling, form.FrameRate); + kvmControl.SwamMouseButtons = form.SwamMouseButtons; } } }