From f4635ee7dcc6673a9895a1b93ef58e726d4fc34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20=C5=A0ipo=C5=A1?= Date: Thu, 14 Nov 2024 15:57:23 +0100 Subject: [PATCH] Add option to disable unchatter for individual keys --- KeyboardUnchatter/App.config | 19 +++++++++------ KeyboardUnchatter/DataGridController.cs | 23 +++++++++---------- KeyboardUnchatter/KeyboardMonitor.cs | 16 ++++++++----- KeyboardUnchatter/KeyboardUnchatter.csproj | 4 +++- KeyboardUnchatter/MainWindow.Designer.cs | 15 +++++++++--- KeyboardUnchatter/MainWindow.cs | 22 ++++++++++++------ KeyboardUnchatter/MainWindow.resx | 12 ---------- .../Properties/Resources.Designer.cs | 2 +- .../Properties/Settings.Designer.cs | 15 +++++++++++- .../Properties/Settings.settings | 6 ++++- 10 files changed, 83 insertions(+), 51 deletions(-) diff --git a/KeyboardUnchatter/App.config b/KeyboardUnchatter/App.config index edf65bd..14f1bd8 100644 --- a/KeyboardUnchatter/App.config +++ b/KeyboardUnchatter/App.config @@ -1,15 +1,15 @@ - + - -
+ +
- + - + 20 @@ -19,6 +19,11 @@ True - + + + + + + - \ No newline at end of file + diff --git a/KeyboardUnchatter/DataGridController.cs b/KeyboardUnchatter/DataGridController.cs index d64e330..08e9e3d 100644 --- a/KeyboardUnchatter/DataGridController.cs +++ b/KeyboardUnchatter/DataGridController.cs @@ -1,9 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace KeyboardUnchatter @@ -84,25 +80,28 @@ public void AddKeyBlock(Keys key) private void UpdateGridCell(KeyData keyData) { bool cellUpdated = false; + var keyPressed = keyData.Key.ToString(); + var keyDisabled = Properties.Settings.Default.disabledKeys.Contains(keyPressed); + int press = keyData.KeyPressedCount; + int block = keyData.KeyBlockedCount; + var percentage = Math.Floor((float)block / (float)press * 100).ToString() + "%"; + for (int a = 0; a < _dataGrid.Rows.Count; ++a) { var row = _dataGrid.Rows[a]; + var keyColumnCell = row.Cells[1]; - if (row.Cells[0].Value != null && row.Cells[0].Value.ToString() == keyData.Key.ToString()) + if (keyColumnCell.Value != null && keyColumnCell.Value.ToString() == keyPressed) { - int press = keyData.KeyPressedCount; - int block = keyData.KeyBlockedCount; - - _dataGrid.Rows[a].SetValues(new string[] { keyData.Key.ToString(), press.ToString(), block.ToString(), (Math.Floor((float)block/(float)press*100)).ToString() +"%" }); + _dataGrid.Rows[a].SetValues(new object[] { keyDisabled, keyPressed, press.ToString(), block.ToString(), percentage}); cellUpdated = true; + break; } } if (!cellUpdated) { - int press = keyData.KeyPressedCount; - int block = keyData.KeyBlockedCount; - _dataGrid.Rows.Add(new string[] { keyData.Key.ToString(), press.ToString(), block.ToString(), (Math.Floor((float)block / (float)press)*100).ToString() + "%" }); + _dataGrid.Rows.Add(new object[] { keyDisabled, keyPressed, press.ToString(), block.ToString(), percentage }); } } } diff --git a/KeyboardUnchatter/KeyboardMonitor.cs b/KeyboardUnchatter/KeyboardMonitor.cs index 096ecd9..6bf0ec4 100644 --- a/KeyboardUnchatter/KeyboardMonitor.cs +++ b/KeyboardUnchatter/KeyboardMonitor.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Windows.Forms; -using System.Diagnostics; namespace KeyboardUnchatter @@ -60,6 +58,7 @@ private bool HandleKey(InputHook.KeyPress keyPress) } var key = _keyStatusList.GetKey(keyPress.KeyCode); + var unchatterDisabled = Properties.Settings.Default.disabledKeys.Contains(keyPress.Key.ToString()); if (keyPress.Status == InputHook.KeyStatus.Down) { @@ -69,7 +68,8 @@ private bool HandleKey(InputHook.KeyPress keyPress) if (lastPressStatus == KeyStatusList.PressStatus.Up && key.IsBlocked) { Debug.Log("Key"+ key.KeyCode+" is blocked. Discarding"); - return false; + if (!unchatterDisabled) + return false; } double timeSpan = key.GetLastPressTimeSpan(); @@ -77,9 +77,12 @@ private bool HandleKey(InputHook.KeyPress keyPress) if(timeSpan < _chatterTimeMs) { Debug.Log("Key" + key.KeyCode + " timeSpawn is below limit. Blocking"); - key.Block(); RegisterChatterPress(keyPress.Key); - return false; + if (!unchatterDisabled) + { + key.Block(); + return false; + } } } @@ -94,7 +97,8 @@ private bool HandleKey(InputHook.KeyPress keyPress) if (keyWasBlocked && key.GetBlockTimeSpan() < _chatterTimeMs) { Debug.Log("Key" + key.KeyCode + " was blocked"); - return false; + if (!unchatterDisabled) + return false; } else { diff --git a/KeyboardUnchatter/KeyboardUnchatter.csproj b/KeyboardUnchatter/KeyboardUnchatter.csproj index 997dbf4..4cb410b 100644 --- a/KeyboardUnchatter/KeyboardUnchatter.csproj +++ b/KeyboardUnchatter/KeyboardUnchatter.csproj @@ -8,7 +8,7 @@ WinExe KeyboardUnchatter KeyboardUnchatter - v4.5.2 + v4.8 512 true publish\ @@ -26,6 +26,7 @@ false false true + AnyCPU @@ -84,6 +85,7 @@ MainWindow.cs + Designer ResXFileCodeGenerator diff --git a/KeyboardUnchatter/MainWindow.Designer.cs b/KeyboardUnchatter/MainWindow.Designer.cs index b76f48a..0001210 100644 --- a/KeyboardUnchatter/MainWindow.Designer.cs +++ b/KeyboardUnchatter/MainWindow.Designer.cs @@ -34,6 +34,7 @@ private void InitializeComponent() this._statusPanelLabel = new System.Windows.Forms.Label(); this._buttonActivate = new System.Windows.Forms.Button(); this._mainDataGrid = new System.Windows.Forms.DataGridView(); + this.Disabled = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.Key = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.PressCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ChatterCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -106,9 +107,10 @@ private void InitializeComponent() this._mainDataGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this._mainDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this._mainDataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Key, - this.PressCount, - this.ChatterCount, + this.Disabled, + this.Key, + this.PressCount, + this.ChatterCount, this.FailureRate}); this._mainDataGrid.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this._mainDataGrid.Location = new System.Drawing.Point(6, 19); @@ -118,6 +120,12 @@ private void InitializeComponent() this._mainDataGrid.Size = new System.Drawing.Size(583, 204); this._mainDataGrid.TabIndex = 3; this._mainDataGrid.SortCompare += new System.Windows.Forms.DataGridViewSortCompareEventHandler(this.DataSortCompare); + this._mainDataGrid.CellContentClick += this.OnDisabledCheckBox; + // + // Disabled + // + this.Disabled.HeaderText = "Disable Unchattering"; + this.Disabled.Name = "Disabled"; // // Key // @@ -322,6 +330,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem _exitMenuItem; private System.Windows.Forms.Label label1; + private System.Windows.Forms.DataGridViewCheckBoxColumn Disabled; private System.Windows.Forms.DataGridViewTextBoxColumn Key; private System.Windows.Forms.DataGridViewTextBoxColumn PressCount; private System.Windows.Forms.DataGridViewTextBoxColumn ChatterCount; diff --git a/KeyboardUnchatter/MainWindow.cs b/KeyboardUnchatter/MainWindow.cs index 6b97ae5..eeaa9c4 100644 --- a/KeyboardUnchatter/MainWindow.cs +++ b/KeyboardUnchatter/MainWindow.cs @@ -1,13 +1,6 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using System.Diagnostics; namespace KeyboardUnchatter { @@ -149,6 +142,21 @@ private void OnActivateOnLaunchCheckBox(object sender, EventArgs e) Properties.Settings.Default.Save(); } + private void OnDisabledCheckBox(object sender, DataGridViewCellEventArgs e) + { + if (e.ColumnIndex == this.Disabled.Index) + { + var cell = this._mainDataGrid[e.ColumnIndex, e.RowIndex]; + var isChecked = !(bool)cell.Value; + cell.Value = isChecked; // Toggle checkbox manually, datagrid is in programmatic edit mode + string pressedKey = this._mainDataGrid.Rows[e.RowIndex].Cells[1].Value.ToString(); + if (isChecked) + Properties.Settings.Default.disabledKeys.Add(pressedKey); + else + Properties.Settings.Default.disabledKeys.Remove(pressedKey); + Properties.Settings.Default.Save(); + } + } private void DataSortCompare(object sender, DataGridViewSortCompareEventArgs e) { diff --git a/KeyboardUnchatter/MainWindow.resx b/KeyboardUnchatter/MainWindow.resx index 5c77807..ef428c1 100644 --- a/KeyboardUnchatter/MainWindow.resx +++ b/KeyboardUnchatter/MainWindow.resx @@ -129,18 +129,6 @@ True - - True - - - True - - - True - - - True - 17, 17 diff --git a/KeyboardUnchatter/Properties/Resources.Designer.cs b/KeyboardUnchatter/Properties/Resources.Designer.cs index debe850..31679bd 100644 --- a/KeyboardUnchatter/Properties/Resources.Designer.cs +++ b/KeyboardUnchatter/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace KeyboardUnchatter.Properties { // 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 { diff --git a/KeyboardUnchatter/Properties/Settings.Designer.cs b/KeyboardUnchatter/Properties/Settings.Designer.cs index c8e0bcd..37fdb50 100644 --- a/KeyboardUnchatter/Properties/Settings.Designer.cs +++ b/KeyboardUnchatter/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace KeyboardUnchatter.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -58,5 +58,18 @@ public bool activateOnLaunch { this["activateOnLaunch"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("\r\n")] + public global::System.Collections.Specialized.StringCollection disabledKeys { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["disabledKeys"])); + } + set { + this["disabledKeys"] = value; + } + } } } diff --git a/KeyboardUnchatter/Properties/Settings.settings b/KeyboardUnchatter/Properties/Settings.settings index 597fca4..677b37b 100644 --- a/KeyboardUnchatter/Properties/Settings.settings +++ b/KeyboardUnchatter/Properties/Settings.settings @@ -1,5 +1,5 @@  - + @@ -11,5 +11,9 @@ True + + <?xml version="1.0" encoding="utf-16"?> +<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> + \ No newline at end of file