From 1e0169a71db7525382f7d6ec6f6399521654c71d Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 21 May 2023 19:01:43 +0200 Subject: [PATCH] Added M1/M2 keys and keyboard init --- app/AsusUSB.cs | 46 +++++- app/Extra.Designer.cs | 241 ++++++++++++++++++++--------- app/Extra.cs | 28 ++-- app/Program.cs | 1 + app/Properties/Strings.Designer.cs | 18 +++ app/Properties/Strings.resx | 6 + app/Settings.cs | 2 + 7 files changed, 253 insertions(+), 89 deletions(-) diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index 591214ce..0e8c3298 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -1,6 +1,7 @@ using HidLibrary; using Microsoft.Win32; using System.Diagnostics; +using System.Text; namespace GHelper { @@ -55,6 +56,12 @@ namespace GHelper public const byte HID_ID = 0x5a; + public static readonly byte[] LED_INIT1 = new byte[] { 0x5d, 0xb9 }; + public static readonly byte[] LED_INIT2 = Encoding.ASCII.GetBytes("]ASUS Tech.Inc."); + public static readonly byte[] LED_INIT3 = new byte[] { 0x5d, 0x05, 0x20, 0x31, 0, 0x08 }; + public static readonly byte[] LED_INIT4 = Encoding.ASCII.GetBytes("^ASUS Tech.Inc."); + public static readonly byte[] LED_INIT5 = new byte[] { 0x5e, 0x05, 0x20, 0x31, 0, 0x08 }; + static byte[] MESSAGE_SET = { 0x5d, 0xb5, 0, 0, 0 }; static byte[] MESSAGE_APPLY = { 0x5d, 0xb4 }; @@ -240,19 +247,42 @@ namespace GHelper return msg; } + public static void Init() + { + + var devices = GetHidDevices(deviceIds); + foreach (HidDevice device in devices) + { + device.OpenDevice(); + device.WriteFeatureData(LED_INIT1); + device.WriteFeatureData(LED_INIT2); + device.WriteFeatureData(LED_INIT3); + device.WriteFeatureData(LED_INIT4); + device.WriteFeatureData(LED_INIT5); + device.CloseDevice(); + } + } + public static void ApplyBrightness(int brightness) { byte[] msg = { 0x5d, 0xba, 0xc5, 0xc4, (byte)brightness }; var devices = GetHidDevices(deviceIds); - //Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); - foreach (HidDevice device in devices) { + + device.OpenDevice(); - device.Write(msg); - Logger.WriteLine("USB-KB " + device.Attributes.ProductHexId + ":" + BitConverter.ToString(msg)); + + device.WriteFeatureData(LED_INIT1); + device.WriteFeatureData(LED_INIT2); + device.WriteFeatureData(LED_INIT3); + device.WriteFeatureData(LED_INIT4); + device.WriteFeatureData(LED_INIT5); + + device.WriteFeatureData(msg); + Logger.WriteLine("USB-KB " + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg)); device.CloseDevice(); } @@ -273,7 +303,7 @@ namespace GHelper foreach (HidDevice device in devices) { device.OpenDevice(); - device.Write(msg); + device.WriteFeatureData(msg); Logger.WriteLine("USB-KB " + device.Attributes.ProductHexId + ":" + BitConverter.ToString(msg)); device.CloseDevice(); } @@ -362,9 +392,9 @@ namespace GHelper foreach (HidDevice device in devices) { device.OpenDevice(); - device.Write(msg); - device.Write(MESSAGE_SET); - device.Write(MESSAGE_APPLY); + device.WriteFeatureData(msg); + device.WriteFeatureData(MESSAGE_SET); + device.WriteFeatureData(MESSAGE_APPLY); device.CloseDevice(); Logger.WriteLine("USB-KB " + device.Capabilities.FeatureReportByteLength + "|" + device.Capabilities.InputReportByteLength + device.Description + device.DevicePath + ":" + BitConverter.ToString(msg)); } diff --git a/app/Extra.Designer.cs b/app/Extra.Designer.cs index 612397f5..ae2754da 100644 --- a/app/Extra.Designer.cs +++ b/app/Extra.Designer.cs @@ -32,16 +32,23 @@ namespace GHelper private void InitializeComponent() { groupBindings = new GroupBox(); - pictureHelp = new PictureBox(); - textFNF4 = new TextBox(); - comboFNF4 = new RComboBox(); + tableKeys = new TableLayoutPanel(); + textM2 = new TextBox(); + textM1 = new TextBox(); + comboM1 = new RComboBox(); + labelM1 = new Label(); labelFNF4 = new Label(); + comboFNF4 = new RComboBox(); + comboM4 = new RComboBox(); + comboM3 = new RComboBox(); + textFNF4 = new TextBox(); textM4 = new TextBox(); textM3 = new TextBox(); - comboM4 = new RComboBox(); labelM4 = new Label(); - comboM3 = new RComboBox(); labelM3 = new Label(); + labelM2 = new Label(); + comboM2 = new RComboBox(); + pictureHelp = new PictureBox(); groupLight = new GroupBox(); panelBacklightExtra = new Panel(); numericBacklightTime = new NumericUpDown(); @@ -80,6 +87,7 @@ namespace GHelper checkNoOverdrive = new CheckBox(); checkTopmost = new CheckBox(); groupBindings.SuspendLayout(); + tableKeys.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit(); groupLight.SuspendLayout(); panelBacklightExtra.SuspendLayout(); @@ -92,118 +100,199 @@ namespace GHelper // // groupBindings // + groupBindings.Controls.Add(tableKeys); groupBindings.Controls.Add(pictureHelp); - groupBindings.Controls.Add(textFNF4); - groupBindings.Controls.Add(comboFNF4); - groupBindings.Controls.Add(labelFNF4); - groupBindings.Controls.Add(textM4); - groupBindings.Controls.Add(textM3); - groupBindings.Controls.Add(comboM4); - groupBindings.Controls.Add(labelM4); - groupBindings.Controls.Add(comboM3); - groupBindings.Controls.Add(labelM3); groupBindings.Dock = DockStyle.Top; groupBindings.Location = new Point(10, 10); groupBindings.Name = "groupBindings"; - groupBindings.Size = new Size(954, 242); + groupBindings.Size = new Size(954, 324); groupBindings.TabIndex = 0; groupBindings.TabStop = false; groupBindings.Text = "Key Bindings"; // - // pictureHelp + // tableKeys // - pictureHelp.BackgroundImage = Resources.icons8_help_64; - pictureHelp.BackgroundImageLayout = ImageLayout.Zoom; - pictureHelp.Cursor = Cursors.Hand; - pictureHelp.Location = new Point(884, 58); - pictureHelp.Name = "pictureHelp"; - pictureHelp.Size = new Size(32, 32); - pictureHelp.TabIndex = 9; - pictureHelp.TabStop = false; + tableKeys.ColumnCount = 3; + tableKeys.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20F)); + tableKeys.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F)); + tableKeys.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F)); + tableKeys.Controls.Add(textM2, 2, 1); + tableKeys.Controls.Add(textM1, 2, 0); + tableKeys.Controls.Add(comboM1, 1, 0); + tableKeys.Controls.Add(labelM1, 0, 0); + tableKeys.Controls.Add(labelFNF4, 0, 4); + tableKeys.Controls.Add(comboFNF4, 1, 4); + tableKeys.Controls.Add(comboM4, 1, 3); + tableKeys.Controls.Add(comboM3, 1, 2); + tableKeys.Controls.Add(textFNF4, 2, 4); + tableKeys.Controls.Add(textM4, 2, 3); + tableKeys.Controls.Add(textM3, 2, 2); + tableKeys.Controls.Add(labelM4, 0, 3); + tableKeys.Controls.Add(labelM3, 0, 2); + tableKeys.Controls.Add(labelM2, 0, 1); + tableKeys.Controls.Add(comboM2, 1, 1); + tableKeys.Location = new Point(13, 38); + tableKeys.Name = "tableKeys"; + tableKeys.Padding = new Padding(10); + tableKeys.RowCount = 5; + tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); + tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); + tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); + tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); + tableKeys.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); + tableKeys.Size = new Size(897, 266); + tableKeys.TabIndex = 10; // - // textFNF4 + // textM2 // - textFNF4.Location = new Point(415, 176); - textFNF4.Name = "textFNF4"; - textFNF4.PlaceholderText = "action"; - textFNF4.Size = new Size(448, 39); - textFNF4.TabIndex = 8; + textM2.Location = new Point(538, 63); + textM2.Name = "textM2"; + textM2.PlaceholderText = "action"; + textM2.Size = new Size(346, 39); + textM2.TabIndex = 14; + // + // textM1 + // + textM1.Location = new Point(538, 13); + textM1.Name = "textM1"; + textM1.PlaceholderText = "action"; + textM1.Size = new Size(346, 39); + textM1.TabIndex = 13; + // + // comboM1 + // + comboM1.BorderColor = Color.White; + comboM1.ButtonColor = Color.FromArgb(255, 255, 255); + comboM1.FormattingEnabled = true; + comboM1.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom }); + comboM1.Location = new Point(188, 13); + comboM1.Name = "comboM1"; + comboM1.Size = new Size(312, 40); + comboM1.TabIndex = 11; + // + // labelM1 + // + labelM1.AutoSize = true; + labelM1.Location = new Point(13, 10); + labelM1.Name = "labelM1"; + labelM1.Size = new Size(54, 32); + labelM1.TabIndex = 9; + labelM1.Text = "M1:"; + // + // labelFNF4 + // + labelFNF4.AutoSize = true; + labelFNF4.Location = new Point(13, 210); + labelFNF4.Name = "labelFNF4"; + labelFNF4.Size = new Size(90, 32); + labelFNF4.TabIndex = 6; + labelFNF4.Text = "FN+F4:"; // // comboFNF4 // comboFNF4.BorderColor = Color.White; comboFNF4.ButtonColor = Color.FromArgb(255, 255, 255); comboFNF4.FormattingEnabled = true; - comboFNF4.Location = new Point(93, 175); + comboFNF4.Location = new Point(188, 213); comboFNF4.Name = "comboFNF4"; comboFNF4.Size = new Size(312, 40); comboFNF4.TabIndex = 7; // - // labelFNF4 - // - labelFNF4.AutoSize = true; - labelFNF4.Location = new Point(2, 178); - labelFNF4.Name = "labelFNF4"; - labelFNF4.Size = new Size(90, 32); - labelFNF4.TabIndex = 6; - labelFNF4.Text = "FN+F4:"; - // - // textM4 - // - textM4.Location = new Point(415, 113); - textM4.Name = "textM4"; - textM4.PlaceholderText = "action"; - textM4.Size = new Size(448, 39); - textM4.TabIndex = 5; - // - // textM3 - // - textM3.Location = new Point(415, 54); - textM3.Name = "textM3"; - textM3.PlaceholderText = "notepad /p \"file.txt\""; - textM3.Size = new Size(448, 39); - textM3.TabIndex = 4; - // // comboM4 // comboM4.BorderColor = Color.White; comboM4.ButtonColor = Color.FromArgb(255, 255, 255); comboM4.FormattingEnabled = true; comboM4.Items.AddRange(new object[] { Strings.PerformanceMode, Strings.OpenGHelper, Strings.Custom }); - comboM4.Location = new Point(93, 112); + comboM4.Location = new Point(188, 163); comboM4.Name = "comboM4"; comboM4.Size = new Size(312, 40); comboM4.TabIndex = 3; // - // labelM4 - // - labelM4.AutoSize = true; - labelM4.Location = new Point(25, 116); - labelM4.Name = "labelM4"; - labelM4.Size = new Size(54, 32); - labelM4.TabIndex = 2; - labelM4.Text = "M4:"; - // // comboM3 // comboM3.BorderColor = Color.White; comboM3.ButtonColor = Color.FromArgb(255, 255, 255); comboM3.FormattingEnabled = true; comboM3.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom }); - comboM3.Location = new Point(93, 54); + comboM3.Location = new Point(188, 113); comboM3.Name = "comboM3"; comboM3.Size = new Size(312, 40); comboM3.TabIndex = 1; // + // textFNF4 + // + textFNF4.Location = new Point(538, 213); + textFNF4.Name = "textFNF4"; + textFNF4.PlaceholderText = "action"; + textFNF4.Size = new Size(346, 39); + textFNF4.TabIndex = 8; + // + // textM4 + // + textM4.Location = new Point(538, 163); + textM4.Name = "textM4"; + textM4.PlaceholderText = "action"; + textM4.Size = new Size(346, 39); + textM4.TabIndex = 5; + // + // textM3 + // + textM3.Location = new Point(538, 113); + textM3.Name = "textM3"; + textM3.PlaceholderText = "action"; + textM3.Size = new Size(346, 39); + textM3.TabIndex = 4; + // + // labelM4 + // + labelM4.AutoSize = true; + labelM4.Location = new Point(13, 160); + labelM4.Name = "labelM4"; + labelM4.Size = new Size(54, 32); + labelM4.TabIndex = 2; + labelM4.Text = "M4:"; + // // labelM3 // labelM3.AutoSize = true; - labelM3.Location = new Point(25, 58); + labelM3.Location = new Point(13, 110); labelM3.Name = "labelM3"; labelM3.Size = new Size(54, 32); labelM3.TabIndex = 0; labelM3.Text = "M3:"; // + // labelM2 + // + labelM2.AutoSize = true; + labelM2.Location = new Point(13, 60); + labelM2.Name = "labelM2"; + labelM2.Size = new Size(54, 32); + labelM2.TabIndex = 10; + labelM2.Text = "M2:"; + // + // comboM2 + // + comboM2.BorderColor = Color.White; + comboM2.ButtonColor = Color.FromArgb(255, 255, 255); + comboM2.FormattingEnabled = true; + comboM2.Items.AddRange(new object[] { Strings.Default, Strings.VolumeMute, Strings.PlayPause, Strings.PrintScreen, Strings.ToggleAura, Strings.Custom }); + comboM2.Location = new Point(188, 63); + comboM2.Name = "comboM2"; + comboM2.Size = new Size(312, 40); + comboM2.TabIndex = 12; + // + // pictureHelp + // + pictureHelp.BackgroundImage = Resources.icons8_help_64; + pictureHelp.BackgroundImageLayout = ImageLayout.Zoom; + pictureHelp.Cursor = Cursors.Hand; + pictureHelp.Location = new Point(906, 51); + pictureHelp.Name = "pictureHelp"; + pictureHelp.Size = new Size(32, 32); + pictureHelp.TabIndex = 9; + pictureHelp.TabStop = false; + // // groupLight // groupLight.AutoSize = true; @@ -211,7 +300,7 @@ namespace GHelper groupLight.Controls.Add(panelXMG); groupLight.Controls.Add(tableBacklight); groupLight.Dock = DockStyle.Top; - groupLight.Location = new Point(10, 252); + groupLight.Location = new Point(10, 334); groupLight.Name = "groupLight"; groupLight.Size = new Size(954, 516); groupLight.TabIndex = 1; @@ -579,7 +668,7 @@ namespace GHelper groupOther.Controls.Add(checkNoOverdrive); groupOther.Controls.Add(checkTopmost); groupOther.Dock = DockStyle.Top; - groupOther.Location = new Point(10, 768); + groupOther.Location = new Point(10, 850); groupOther.Name = "groupOther"; groupOther.Size = new Size(954, 276); groupOther.TabIndex = 2; @@ -643,7 +732,7 @@ namespace GHelper AutoScaleMode = AutoScaleMode.Font; AutoSize = true; AutoSizeMode = AutoSizeMode.GrowAndShrink; - ClientSize = new Size(974, 1059); + ClientSize = new Size(974, 1131); Controls.Add(groupOther); Controls.Add(groupLight); Controls.Add(groupBindings); @@ -658,7 +747,8 @@ namespace GHelper ShowInTaskbar = false; Text = "Extra Settings"; groupBindings.ResumeLayout(false); - groupBindings.PerformLayout(); + tableKeys.ResumeLayout(false); + tableKeys.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureHelp).EndInit(); groupLight.ResumeLayout(false); groupLight.PerformLayout(); @@ -725,5 +815,12 @@ namespace GHelper private NumericUpDown numericBacklightTime; private CheckBox checkKeyboardAuto; private CheckBox checkAutoApplyWindowsPowerMode; + private TableLayoutPanel tableKeys; + private Label labelM1; + private Label labelM2; + private RComboBox comboM1; + private RComboBox comboM2; + private TextBox textM2; + private TextBox textM1; } } \ No newline at end of file diff --git a/app/Extra.cs b/app/Extra.cs index b3e728ec..6855c4b7 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -22,16 +22,24 @@ namespace GHelper private void SetKeyCombo(ComboBox combo, TextBox txbox, string name) { - if (name == "m3") - customActions[""] = Properties.Strings.MuteMic; - - if (name == "m4") - customActions[""] = Properties.Strings.OpenGHelper; - - if (name == "fnf4") + switch (name) { - customActions[""] = Properties.Strings.ToggleAura; - customActions.Remove("aura"); + case "m1": + customActions[""] = Properties.Strings.VolumeDown; + break; + case "m2": + customActions[""] = Properties.Strings.VolumeUp; + break; + case "m3": + customActions[""] = Properties.Strings.MuteMic; + break; + case "m4": + customActions[""] = Properties.Strings.OpenGHelper; + break; + case "fnf4": + customActions[""] = Properties.Strings.ToggleAura; + customActions.Remove("aura"); + break; } combo.DropDownStyle = ComboBoxStyle.DropDownList; @@ -89,6 +97,8 @@ namespace GHelper InitTheme(); + SetKeyCombo(comboM1, textM1, "m1"); + SetKeyCombo(comboM2, textM2, "m2"); SetKeyCombo(comboM3, textM3, "m3"); SetKeyCombo(comboM4, textM4, "m4"); SetKeyCombo(comboFNF4, textFNF4, "fnf4"); diff --git a/app/Program.cs b/app/Program.cs index 38ee9653..570b9ea4 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -81,6 +81,7 @@ namespace GHelper settingsForm.InitMatrix(); settingsForm.SetStartupCheck(Startup.IsScheduled()); + SetAutoModes(); // Subscribing for system power change events diff --git a/app/Properties/Strings.Designer.cs b/app/Properties/Strings.Designer.cs index ea0c7bf9..dfa06e71 100644 --- a/app/Properties/Strings.Designer.cs +++ b/app/Properties/Strings.Designer.cs @@ -1068,6 +1068,15 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized string similar to Volume Down. + /// + internal static string VolumeDown { + get { + return ResourceManager.GetString("VolumeDown", resourceCulture); + } + } + /// /// Looks up a localized string similar to Volume Mute. /// @@ -1077,6 +1086,15 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized string similar to Volume Up. + /// + internal static string VolumeUp { + get { + return ResourceManager.GetString("VolumeUp", resourceCulture); + } + } + /// /// Looks up a localized string similar to Keep app window always on top. /// diff --git a/app/Properties/Strings.resx b/app/Properties/Strings.resx index ec196a9e..b541851a 100644 --- a/app/Properties/Strings.resx +++ b/app/Properties/Strings.resx @@ -453,9 +453,15 @@ Version + + Volume Down + Volume Mute + + Volume Up + Keep app window always on top diff --git a/app/Settings.cs b/app/Settings.cs index a89f5461..05d6f161 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1243,6 +1243,8 @@ namespace GHelper public void AutoKeyboard() { + AsusUSB.Init(); + if (AppConfig.getConfig("keyboard_auto") != 1) return; if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)