From 267fa1dfa6fd5422007e78281066a2bf82039be4 Mon Sep 17 00:00:00 2001 From: Jimmy Quach Date: Mon, 7 Aug 2023 14:40:11 -0700 Subject: [PATCH 1/3] Start keybind rewrite --- Classes/Services/HotkeyService.cs | 59 +++--- Classes/Services/Hotkeys/BookmarkHotkey.cs | 3 +- Classes/Services/Hotkeys/Hotkey.cs | 2 +- Classes/Services/Hotkeys/RecordingHotkey.cs | 2 +- Classes/Services/SettingsService.cs | 6 +- Classes/Utils/JSONObjects.cs | 3 + Classes/Utils/Messages.cs | 2 +- Classes/frmMain.Designer.cs | 188 ++++++++----------- Classes/frmMain.cs | 41 ---- ClientApp/src/components/HotkeySelector.tsx | 24 --- ClientApp/src/components/KeybindSelector.tsx | 50 +++++ ClientApp/src/index.tsx | 18 +- ClientApp/src/pages/Settings.tsx | 19 +- ClientApp/src/pages/Settings/Keybind.tsx | 22 +++ ClientApp/src/pages/Settings/Keybindings.tsx | 27 --- 15 files changed, 207 insertions(+), 259 deletions(-) delete mode 100644 ClientApp/src/components/HotkeySelector.tsx create mode 100644 ClientApp/src/components/KeybindSelector.tsx create mode 100644 ClientApp/src/pages/Settings/Keybind.tsx delete mode 100644 ClientApp/src/pages/Settings/Keybindings.tsx diff --git a/Classes/Services/HotkeyService.cs b/Classes/Services/HotkeyService.cs index 0a85228d..6f3a5844 100644 --- a/Classes/Services/HotkeyService.cs +++ b/Classes/Services/HotkeyService.cs @@ -8,19 +8,10 @@ namespace RePlays.Services { public static class HotkeyService { - public delegate IntPtr CallbackDelegate(int Code, IntPtr W, IntPtr L); - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public struct KBDLLHookStruct { - public Int32 vkCode; - public Int32 scanCode; - public Int32 flags; - public Int32 time; - public Int32 dwExtraInfo; - } + public delegate IntPtr WinHookProc(int Code, IntPtr W, IntPtr L); [DllImport("user32", CallingConvention = CallingConvention.StdCall)] - private static extern IntPtr SetWindowsHookEx(int idHook, CallbackDelegate lpfn, int hInstance, int threadId); + private static extern IntPtr SetWindowsHookEx(int idHook, WinHookProc lpfn, int hInstance, int threadId); [DllImport("user32", CallingConvention = CallingConvention.StdCall)] private static extern bool UnhookWindowsHookEx(IntPtr idHook); @@ -28,51 +19,57 @@ public struct KBDLLHookStruct { [DllImport("user32", CallingConvention = CallingConvention.StdCall)] private static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam); - [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall)] - private static extern int GetCurrentThreadId(); - public static string EditId = null; - private static List _hotkeys = new(); - private static IntPtr HookID; - static CallbackDelegate TheHookCB = null; + private static readonly List hotkeys = new(); + private static readonly HashSet pressedKeys = new(); + static nint keyboardHook; + static WinHookProc keyboardDele; public static void Start() { //Create hotkeys - _hotkeys.Add(new BookmarkHotkey()); - _hotkeys.Add(new RecordingHotkey()); + hotkeys.Add(new BookmarkHotkey()); + hotkeys.Add(new RecordingHotkey()); + //Create hook - TheHookCB = KeybHookProc; - HookID = SetWindowsHookEx(13, TheHookCB, 0, 0); + keyboardDele = OnKeyEvent; + keyboardHook = SetWindowsHookEx(13, keyboardDele, 0, 0); Logger.WriteLine("Loaded KeyboardHook..."); } public static void Stop() { - _hotkeys.Clear(); - UnhookWindowsHookEx(HookID); + hotkeys.Clear(); + UnhookWindowsHookEx(keyboardHook); Logger.WriteLine("Unloaded KeyboardHook..."); } - private static IntPtr KeybHookProc(int Code, IntPtr W, IntPtr L) { + private static IntPtr OnKeyEvent(int Code, IntPtr W, IntPtr L) { if (Code < 0) - return CallNextHookEx(HookID, Code, W, L); + return CallNextHookEx(keyboardHook, Code, W, L); try { KeyEvents kEvent = (KeyEvents)W; + Keys vkCode = (Keys)Marshal.ReadInt32(L); if (kEvent == KeyEvents.KeyDown) { - Keys vkCode = (Keys)Marshal.ReadInt32(L); - vkCode |= Control.ModifierKeys; - foreach (Hotkey h in _hotkeys) { - if (vkCode == h.Keybind) h.Action(); + pressedKeys.Add(vkCode); + Logger.WriteLine($"Keys: [{string.Join(",", pressedKeys)}]"); + foreach (Hotkey h in hotkeys) { + if (vkCode == h.Keybind) { + h.Action(); + Logger.WriteLine($"Key: [{h.Keybind}], Action: [{h.GetType()}]"); + } } } + else if (kEvent == KeyEvents.KeyUp) { + pressedKeys.Remove(vkCode); + Logger.WriteLine($"Keys: [{string.Join(",", pressedKeys)}]"); + } } catch (Exception e) { Logger.WriteLine("Error getting current keypress: " + e.ToString()); } - return CallNextHookEx(HookID, Code, W, L); + return CallNextHookEx(keyboardHook, Code, W, L); } - public enum KeyEvents { KeyDown = 0x0100, KeyUp = 0x0101 diff --git a/Classes/Services/Hotkeys/BookmarkHotkey.cs b/Classes/Services/Hotkeys/BookmarkHotkey.cs index 71d2d78e..0c773d97 100644 --- a/Classes/Services/Hotkeys/BookmarkHotkey.cs +++ b/Classes/Services/Hotkeys/BookmarkHotkey.cs @@ -9,8 +9,7 @@ public override void Action() { } protected override void SetKeybind() { - string[] keybind; - SettingsService.Settings.keybindings.TryGetValue(key, out keybind); + SettingsService.Settings.keybindsSettings.TryGetValue(key, out string[] keybind); _keybind = ParseKeys(key, keybind); } } diff --git a/Classes/Services/Hotkeys/Hotkey.cs b/Classes/Services/Hotkeys/Hotkey.cs index 96b5754f..3689b5ea 100644 --- a/Classes/Services/Hotkeys/Hotkey.cs +++ b/Classes/Services/Hotkeys/Hotkey.cs @@ -35,7 +35,7 @@ public static Keys ParseKeys(string keyReference, string[] keys) { private static string[] AddMissingHotkey(string keyReference) { defaultKeybindings.TryGetValue(keyReference, out string[] keys); - SettingsService.Settings.keybindings.Add(keyReference, keys); + SettingsService.Settings.keybindsSettings.Add(keyReference, keys); SettingsService.SaveSettings(); return keys; } diff --git a/Classes/Services/Hotkeys/RecordingHotkey.cs b/Classes/Services/Hotkeys/RecordingHotkey.cs index cb93ff05..9a416ff8 100644 --- a/Classes/Services/Hotkeys/RecordingHotkey.cs +++ b/Classes/Services/Hotkeys/RecordingHotkey.cs @@ -11,7 +11,7 @@ public override void Action() { protected override void SetKeybind() { string[] keybind; - SettingsService.Settings.keybindings.TryGetValue(key, out keybind); + SettingsService.Settings.keybindsSettings.TryGetValue(key, out keybind); _keybind = ParseKeys(key, keybind); } } diff --git a/Classes/Services/SettingsService.cs b/Classes/Services/SettingsService.cs index 89f36bae..2c1402e3 100644 --- a/Classes/Services/SettingsService.cs +++ b/Classes/Services/SettingsService.cs @@ -27,8 +27,8 @@ public class SettingsJson { private DetectionSettings _detectionSettings = new(); public DetectionSettings detectionSettings { get { return _detectionSettings; } set { _detectionSettings = value; } } - private Dictionary _keybindings = new Dictionary() { }; - public Dictionary keybindings { get { return _keybindings; } set { _keybindings = value; } } + private KeybindSettings _keybindsSettings = new(); + public KeybindSettings keybindsSettings { get { return _keybindsSettings; } set { _keybindsSettings = value; } } } public static void LoadSettings() { @@ -44,7 +44,7 @@ public static void LoadSettings() { } } else { - Logger.WriteLine(string.Format("{0} did not exist, using default values", settingsFile)); + Logger.WriteLine($"{settingsFile} did not exist, using default values"); } } diff --git a/Classes/Utils/JSONObjects.cs b/Classes/Utils/JSONObjects.cs index 974667d7..c85173cc 100644 --- a/Classes/Utils/JSONObjects.cs +++ b/Classes/Utils/JSONObjects.cs @@ -248,6 +248,9 @@ public class DetectionSettings { public List blacklist { get { return _blacklist; } set { _blacklist = value; } } } + // Key = Action, Value = Key combination + public class KeybindSettings : Dictionary { } + public struct CustomGame { public CustomGame(string gameExe, string gameName) { this._gameExe = gameExe; diff --git a/Classes/Utils/Messages.cs b/Classes/Utils/Messages.cs index bd70be46..722cf3f6 100644 --- a/Classes/Utils/Messages.cs +++ b/Classes/Utils/Messages.cs @@ -204,7 +204,7 @@ public static async Task RecieveMessage(string message) { #if WINDOWS case "EditKeybind": { var id = webMessage.data.Replace("\"", ""); - frmMain.Instance.EditKeybind(id); + Logger.WriteLine($"EditKeybind :: {id}"); } break; case "SelectFolder": { diff --git a/Classes/frmMain.Designer.cs b/Classes/frmMain.Designer.cs index 8177d8b5..0ab5419e 100644 --- a/Classes/frmMain.Designer.cs +++ b/Classes/frmMain.Designer.cs @@ -1,10 +1,8 @@ #if WINDOWS using RePlays.Utils; -namespace RePlays -{ - partial class frmMain - { +namespace RePlays { + partial class frmMain { /// /// Required designer variable. /// @@ -14,10 +12,8 @@ partial class frmMain /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); @@ -29,134 +25,113 @@ protected override void Dispose(bool disposing) /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.checkForUpdatesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.recentLinksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.button1 = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.contextMenuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.SuspendLayout(); + private void InitializeComponent() { + components = new System.ComponentModel.Container(); + notifyIcon1 = new System.Windows.Forms.NotifyIcon(components); + contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(components); + checkForUpdatesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + recentLinksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + pictureBox1 = new System.Windows.Forms.PictureBox(); + label1 = new System.Windows.Forms.Label(); + contextMenuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); + SuspendLayout(); // // notifyIcon1 // - this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1; - this.notifyIcon1.Text = "RePlays"; - this.notifyIcon1.Visible = true; - this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick); + notifyIcon1.ContextMenuStrip = contextMenuStrip1; + notifyIcon1.Text = "RePlays"; + notifyIcon1.Visible = true; + notifyIcon1.DoubleClick += notifyIcon1_DoubleClick; // // contextMenuStrip1 // - this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.checkForUpdatesToolStripMenuItem, - this.recentLinksToolStripMenuItem, - this.toolStripSeparator1, - this.exitToolStripMenuItem}); - this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(171, 76); + contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { checkForUpdatesToolStripMenuItem, recentLinksToolStripMenuItem, toolStripSeparator1, exitToolStripMenuItem }); + contextMenuStrip1.Name = "contextMenuStrip1"; + contextMenuStrip1.Size = new System.Drawing.Size(171, 76); // // checkForUpdatesToolStripMenuItem // - this.checkForUpdatesToolStripMenuItem.Name = "checkForUpdatesToolStripMenuItem"; - this.checkForUpdatesToolStripMenuItem.Size = new System.Drawing.Size(170, 22); - this.checkForUpdatesToolStripMenuItem.Text = "Check for updates"; - this.checkForUpdatesToolStripMenuItem.Click += new System.EventHandler(this.checkForUpdatesToolStripMenuItem_Click); + checkForUpdatesToolStripMenuItem.Name = "checkForUpdatesToolStripMenuItem"; + checkForUpdatesToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + checkForUpdatesToolStripMenuItem.Text = "Check for updates"; + checkForUpdatesToolStripMenuItem.Click += checkForUpdatesToolStripMenuItem_Click; // // recentLinksToolStripMenuItem // - this.recentLinksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem}); - this.recentLinksToolStripMenuItem.Name = "recentLinksToolStripMenuItem"; - this.recentLinksToolStripMenuItem.Size = new System.Drawing.Size(170, 22); - this.recentLinksToolStripMenuItem.Text = "Recent Links"; - this.recentLinksToolStripMenuItem.DropDownOpening += new System.EventHandler(this.recentLinks_ToolStripMenuItem_DropDownOpening); + recentLinksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem }); + recentLinksToolStripMenuItem.Name = "recentLinksToolStripMenuItem"; + recentLinksToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + recentLinksToolStripMenuItem.Text = "Recent Links"; + recentLinksToolStripMenuItem.DropDownOpening += recentLinks_ToolStripMenuItem_DropDownOpening; // // leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem // - this.leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem.Enabled = false; - this.leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem.Name = "leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem"; - this.leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem.Size = new System.Drawing.Size(363, 22); - this.leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem.Text = "Left click to copy to clipboard. Right click to open URL."; + leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem.Enabled = false; + leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem.Name = "leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem"; + leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem.Size = new System.Drawing.Size(363, 22); + leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem.Text = "Left click to copy to clipboard. Right click to open URL."; // // toolStripSeparator1 // - this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(167, 6); + toolStripSeparator1.Name = "toolStripSeparator1"; + toolStripSeparator1.Size = new System.Drawing.Size(167, 6); // // exitToolStripMenuItem // - this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(170, 22); - this.exitToolStripMenuItem.Text = "Exit"; - this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); + exitToolStripMenuItem.Name = "exitToolStripMenuItem"; + exitToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + exitToolStripMenuItem.Text = "Exit"; + exitToolStripMenuItem.Click += exitToolStripMenuItem_Click; // // pictureBox1 // - this.pictureBox1.Image = System.Drawing.Image.FromFile(Functions.GetResourcesFolder() + "/loading.gif"); - this.pictureBox1.Location = new System.Drawing.Point(0, 0); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(0, 0); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.pictureBox1.TabIndex = 1; - this.pictureBox1.TabStop = false; - // - // button1 - // - this.button1.Location = new System.Drawing.Point(0, 0); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(0, 0); - this.button1.TabIndex = 2; - this.button1.Text = "this button is used for logging keypresses for EditKeybind functions, pretty hack" + - "y"; - this.button1.UseVisualStyleBackColor = true; - this.button1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.button1_KeyDown); - this.button1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.button1_KeyUp); + pictureBox1.Image = System.Drawing.Image.FromFile(Functions.GetResourcesFolder() + "/loading.gif"); + pictureBox1.Location = new System.Drawing.Point(0, 0); + pictureBox1.Name = "pictureBox1"; + pictureBox1.Size = new System.Drawing.Size(0, 0); + pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + pictureBox1.TabIndex = 1; + pictureBox1.TabStop = false; // // label1 // - this.label1.Font = new System.Drawing.Font("Segoe UI Semibold", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.label1.ForeColor = System.Drawing.Color.White; - this.label1.Location = new System.Drawing.Point(12, 274); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(276, 54); - this.label1.TabIndex = 4; - this.label1.Text = "Loading RePlays"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + label1.Font = new System.Drawing.Font("Segoe UI Semibold", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + label1.ForeColor = System.Drawing.Color.White; + label1.Location = new System.Drawing.Point(12, 274); + label1.Name = "label1"; + label1.Size = new System.Drawing.Size(276, 54); + label1.TabIndex = 4; + label1.Text = "Loading RePlays"; + label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // frmMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(17)))), ((int)(((byte)(24)))), ((int)(((byte)(39))))); - this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; - this.ClientSize = new System.Drawing.Size(300, 360); - this.Controls.Add(this.label1); - this.Controls.Add(this.button1); - this.Controls.Add(this.pictureBox1); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Functions.GetResourcesFolder() + "tray_idle.ico"); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.Name = "frmMain"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "RePlays"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmMain_FormClosing); - this.Load += new System.EventHandler(this.frmMain_Load); - this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown); - this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); - this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseUp); - this.Resize += new System.EventHandler(this.frmMain_Resize); - this.contextMenuStrip1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.ResumeLayout(false); - + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + BackColor = System.Drawing.Color.FromArgb(17, 24, 39); + BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; + ClientSize = new System.Drawing.Size(300, 360); + Controls.Add(label1); + Controls.Add(pictureBox1); + FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + Icon = System.Drawing.Icon.ExtractAssociatedIcon(Functions.GetResourcesFolder() + "tray_idle.ico"); + Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + Name = "frmMain"; + StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + Text = "RePlays"; + FormClosing += frmMain_FormClosing; + Load += frmMain_Load; + MouseDown += frmMain_MouseDown; + MouseMove += frmMain_MouseMove; + MouseUp += frmMain_MouseUp; + Resize += frmMain_Resize; + contextMenuStrip1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); + ResumeLayout(false); } #endregion @@ -168,7 +143,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem recentLinksToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem leftClickToCopyToClipboardRightClickToOpenURLToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; - private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label1; } } diff --git a/Classes/frmMain.cs b/Classes/frmMain.cs index cb96f4f4..d3dc016e 100644 --- a/Classes/frmMain.cs +++ b/Classes/frmMain.cs @@ -4,7 +4,6 @@ using RePlays.Services; using RePlays.Utils; using System; -using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Globalization; @@ -304,46 +303,6 @@ public void DisplayNotification(string title, string context) { public void HideRecentLinks() { recentLinksMenu.Hide(); } - - private List PressedKeys = new(); - private void button1_KeyDown(object sender, KeyEventArgs e) { - Keys k = e.KeyCode; - if (k.ToString().Contains(e.Modifiers.ToString())) k = e.Modifiers; - - if (!PressedKeys.Contains(k)) { - PressedKeys.Add(k); - } - PressedKeys.Sort(); - PressedKeys.Reverse(); - Logger.WriteLine(string.Join(" | ", PressedKeys.ToArray())); - } - - bool _hasHotkeyTimeout = false; - private void button1_KeyUp(object sender, KeyEventArgs e) { - if (HotkeyService.EditId != null && SettingsService.Settings.keybindings.ContainsKey(HotkeyService.EditId) && !_hasHotkeyTimeout) { - SettingsService.Settings.keybindings[HotkeyService.EditId] = string.Join(" | ", PressedKeys.ToArray()).Split(" | "); - SettingsService.SaveSettings(); - WebMessage.SendMessage(GetUserSettings()); - HotkeyService.Start(); - var cleanupTask = new Task(() => ClearKeys()); cleanupTask.Start(); - } - if (webView2 != null) webView2.Focus(); - else pictureBox1.Focus(); - _hasHotkeyTimeout = PressedKeys.Count >= 2; - } - - public async void ClearKeys() { - await Task.Delay(1000); - _hasHotkeyTimeout = false; - PressedKeys.Clear(); - } - - public void EditKeybind(string id) { - HotkeyService.EditId = id; - HotkeyService.Stop(); - //button1 is a hacky way of logging keypresses - this.button1.Focus(); - } } } #endif \ No newline at end of file diff --git a/ClientApp/src/components/HotkeySelector.tsx b/ClientApp/src/components/HotkeySelector.tsx deleted file mode 100644 index fcdcc2b7..00000000 --- a/ClientApp/src/components/HotkeySelector.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { ReactElement } from 'react'; -import { postMessage } from '../helpers/messenger'; - -interface Props { - id: string; - keybind?: string[]; - width?: string; - icon?: ReactElement; -} - -export const HotkeySelector: React.FC = ({id, keybind, icon, width="full"}) => { - return ( -
- -
- ) -} - -export default HotkeySelector; \ No newline at end of file diff --git a/ClientApp/src/components/KeybindSelector.tsx b/ClientApp/src/components/KeybindSelector.tsx new file mode 100644 index 00000000..3de252b5 --- /dev/null +++ b/ClientApp/src/components/KeybindSelector.tsx @@ -0,0 +1,50 @@ +import { postMessage } from '../helpers/messenger'; +import DropDownMenu from './DropDownMenu'; + +interface Props { + id: string; + keybind?: string[]; +} + +interface Keybind { + action: string; + description?: string; +} + +const keybinds: { [key: string]: Keybind } = { + "StartStopRecording": { action: "Toggle Recording" }, + "CreateBookmark": { action: "Create Bookmark" } +}; + +export const KeybindSelector: React.FC = ({id, keybind}) => { + return ( +
+
+ Action + {}}, + {name: "720p", onClick: () => {}}, + ]}/> +
+
+ Keybind +
{ e.currentTarget.style.borderColor = "#efaf2b" }} + onFocus={(e) => { e.currentTarget.style.borderColor = "rgba(156, 163, 175, var(--tw-border-opacity))" }} + > + {keybind ? keybind.join("+") : "None"} +
+
+
+ Enable +
+ {}}/> +
+
+
+ ) +} + +export default KeybindSelector; \ No newline at end of file diff --git a/ClientApp/src/index.tsx b/ClientApp/src/index.tsx index b840d118..07ef211f 100644 --- a/ClientApp/src/index.tsx +++ b/ClientApp/src/index.tsx @@ -92,11 +92,10 @@ declare global { interface UserSettings { generalSettings: GeneralSettings captureSettings: CaptureSettings - keybindingsSettings: KeybindingsSettings + detectionSettings: DetectionSettings uploadSettings: UploadSettings storageSettings: StorageSettings - keybindings: Keybindings - detectionSettings: DetectionSettings + keybindSettings: KeybindSettings } interface GeneralSettings { launchStartup: boolean, @@ -136,9 +135,6 @@ declare global { fileFormatsCache: FileFormat[] fileFormat: FileFormat, } - interface KeybindingsSettings { - keybindings: Keybindings - } interface UploadSettings { recentLinks: string[], streamableSettings: { @@ -173,18 +169,18 @@ declare global { manageSpaceLimit: number, manageTimeLimit: number, } - interface DetectionSettings{ + interface DetectionSettings { whitelist: CustomGame[], blacklist: string[], } + interface KeybindSettings { + StartStopRecording: string[], + CreateBookmark: string[], + } interface CustomGame { gameExe: string, gameName: string, } - interface Keybindings { - StartStopRecording: string[], - CreateBookmark: string[], - } } ReactDOM.render( diff --git a/ClientApp/src/pages/Settings.tsx b/ClientApp/src/pages/Settings.tsx index 0c34c79b..51f1f8dd 100644 --- a/ClientApp/src/pages/Settings.tsx +++ b/ClientApp/src/pages/Settings.tsx @@ -1,4 +1,3 @@ -import { useState } from "react"; import { Link, Route, HashRouter as Router, Switch, useParams } from "react-router-dom"; import About from "./Settings/About"; import Storage from "./Settings/Storage"; @@ -7,8 +6,8 @@ import General from "./Settings/General"; import Help from "./Settings/Help"; import Upload from "./Settings/Upload"; import Detection from "./Settings/Detection" +import KeyBind from "./Settings/Keybind"; import { postMessage } from '../helpers/messenger'; -import Keybindings from "./Settings/Keybindings"; type SettingsParams = { page: string; @@ -41,8 +40,8 @@ export const Settings: React.FC = ({userSettings, setUserSettings}) => { Detection - - Keybindings + + Keybinds Upload @@ -61,12 +60,12 @@ export const Settings: React.FC = ({userSettings, setUserSettings}) => { - - - - - - + + + + + + diff --git a/ClientApp/src/pages/Settings/Keybind.tsx b/ClientApp/src/pages/Settings/Keybind.tsx new file mode 100644 index 00000000..53ae22c4 --- /dev/null +++ b/ClientApp/src/pages/Settings/Keybind.tsx @@ -0,0 +1,22 @@ +import KeybindSelector from "../../components/KeybindSelector"; + +interface Props { + updateSettings: () => void; + settings: KeybindSettings | undefined; +} + +export const Keybind: React.FC = ({ settings, updateSettings }) => { + return ( +
+

Keybinds

+
+ +
+
+ +
+
+ ) +} + +export default Keybind; \ No newline at end of file diff --git a/ClientApp/src/pages/Settings/Keybindings.tsx b/ClientApp/src/pages/Settings/Keybindings.tsx deleted file mode 100644 index 41e7efd7..00000000 --- a/ClientApp/src/pages/Settings/Keybindings.tsx +++ /dev/null @@ -1,27 +0,0 @@ - -import HotkeySelector from "../../components/HotkeySelector"; - -interface Props { - updateSettings: () => void; - settings: KeybindingsSettings | undefined; - keybindings: Keybindings | undefined; -} - -export const Keybindings: React.FC = ({ settings, keybindings, updateSettings }) => { - - return ( -
-

Keybindings

-
- Toggle Recording Keybind - -
-
- Bookmark Keybind - -
-
- ) -} - -export default Keybindings; \ No newline at end of file From 86582805e964b4060f35d9bb3c9ab05c63898a5c Mon Sep 17 00:00:00 2001 From: Jimmy Quach Date: Mon, 7 Aug 2023 16:26:22 -0700 Subject: [PATCH 2/3] Fix keybind editing button styles --- ClientApp/src/components/KeybindSelector.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ClientApp/src/components/KeybindSelector.tsx b/ClientApp/src/components/KeybindSelector.tsx index 3de252b5..ad4e9bf3 100644 --- a/ClientApp/src/components/KeybindSelector.tsx +++ b/ClientApp/src/components/KeybindSelector.tsx @@ -28,14 +28,17 @@ export const KeybindSelector: React.FC = ({id, keybind}) => { ]}/>
- Keybind -
{ e.currentTarget.style.borderColor = "#efaf2b" }} - onFocus={(e) => { e.currentTarget.style.borderColor = "rgba(156, 163, 175, var(--tw-border-opacity))" }} +
Keybind
+
+ + {keybind ? keybind.join("+") : "None"} + +
Enable From 37dc097f1d136115a25caade50e223bfb715aa72 Mon Sep 17 00:00:00 2001 From: Jimmy Quach Date: Mon, 7 Aug 2023 21:00:26 -0700 Subject: [PATCH 3/3] Complete keybind rewrite --- Classes/Services/HotkeyService.cs | 55 ++++++++++++++----- Classes/Services/Hotkeys/BookmarkHotkey.cs | 17 ------ Classes/Services/Hotkeys/Hotkey.cs | 49 ----------------- Classes/Services/Hotkeys/RecordingHotkey.cs | 19 ------- Classes/Services/Keybinds/BookmarkKeybind.cs | 16 ++++++ Classes/Services/Keybinds/Keybind.cs | 41 ++++++++++++++ Classes/Services/Keybinds/RecordingKeybind.cs | 17 ++++++ Classes/Services/SettingsService.cs | 4 +- Classes/Utils/JSONObjects.cs | 15 ++++- Classes/Utils/Messages.cs | 9 ++- ClientApp/src/App.tsx | 2 + ClientApp/src/components/KeybindSelector.tsx | 31 ++++++----- ClientApp/src/index.tsx | 22 +++++--- ClientApp/src/pages/Settings/Keybind.tsx | 6 +- 14 files changed, 172 insertions(+), 131 deletions(-) delete mode 100644 Classes/Services/Hotkeys/BookmarkHotkey.cs delete mode 100644 Classes/Services/Hotkeys/Hotkey.cs delete mode 100644 Classes/Services/Hotkeys/RecordingHotkey.cs create mode 100644 Classes/Services/Keybinds/BookmarkKeybind.cs create mode 100644 Classes/Services/Keybinds/Keybind.cs create mode 100644 Classes/Services/Keybinds/RecordingKeybind.cs diff --git a/Classes/Services/HotkeyService.cs b/Classes/Services/HotkeyService.cs index 6f3a5844..79a7e986 100644 --- a/Classes/Services/HotkeyService.cs +++ b/Classes/Services/HotkeyService.cs @@ -1,8 +1,9 @@ #if WINDOWS -using RePlays.Classes.Services.Hotkeys; +using RePlays.Classes.Services.Keybinds; using RePlays.Utils; using System; using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -19,15 +20,18 @@ public static class HotkeyService { [DllImport("user32", CallingConvention = CallingConvention.StdCall)] private static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam); - private static readonly List hotkeys = new(); + private static readonly List keybinds = new(); private static readonly HashSet pressedKeys = new(); + private static readonly HashSet cachePressedKeys = new(); static nint keyboardHook; static WinHookProc keyboardDele; + public static string EditId { get; internal set; } + public static void Start() { - //Create hotkeys - hotkeys.Add(new BookmarkHotkey()); - hotkeys.Add(new RecordingHotkey()); + //Create keybinds + keybinds.Add(new BookmarkKeybind()); + keybinds.Add(new RecordingKeybind()); //Create hook keyboardDele = OnKeyEvent; @@ -36,7 +40,7 @@ public static void Start() { } public static void Stop() { - hotkeys.Clear(); + keybinds.Clear(); UnhookWindowsHookEx(keyboardHook); Logger.WriteLine("Unloaded KeyboardHook..."); } @@ -48,19 +52,38 @@ private static IntPtr OnKeyEvent(int Code, IntPtr W, IntPtr L) { try { KeyEvents kEvent = (KeyEvents)W; Keys vkCode = (Keys)Marshal.ReadInt32(L); - if (kEvent == KeyEvents.KeyDown) { + if (kEvent == KeyEvents.KeyDown || kEvent == KeyEvents.SysKeyDown) { pressedKeys.Add(vkCode); - Logger.WriteLine($"Keys: [{string.Join(",", pressedKeys)}]"); - foreach (Hotkey h in hotkeys) { - if (vkCode == h.Keybind) { - h.Action(); - Logger.WriteLine($"Key: [{h.Keybind}], Action: [{h.GetType()}]"); + if (EditId == null) { + foreach (Keybind h in keybinds) { + if (string.Join(",", pressedKeys.OrderBy(s => s.ToString())) == string.Join(",", h.Keys.OrderBy(s => s.ToString())) && + !pressedKeys.SetEquals(cachePressedKeys) && !SettingsService.Settings.keybindSettings[h.Id].disabled) { + h.Action(); + Logger.WriteLine($"Key: [{string.Join(",", h.Keys)}], Action: [{h.Id}]"); + } + } + } + else { + if (!pressedKeys.SetEquals(cachePressedKeys)) { + Logger.WriteLine($"KeysDown: [{string.Join(",", pressedKeys)}]"); } } + cachePressedKeys.Add(vkCode); } - else if (kEvent == KeyEvents.KeyUp) { + else if (kEvent == KeyEvents.KeyUp || kEvent == KeyEvents.SysKeyUp) { + if (EditId != null) { + int hkIndex = keybinds.FindIndex(h => h.Id == EditId); + if (hkIndex == -1) { + Logger.WriteLine($"Error, could not find keybind action: {EditId}"); + } + else { + keybinds[hkIndex].SetKeybind(pressedKeys.Select(p => p.ToString()).ToArray()); + } + Logger.WriteLine($"Exiting keybind edit mode."); + EditId = null; + } pressedKeys.Remove(vkCode); - Logger.WriteLine($"Keys: [{string.Join(",", pressedKeys)}]"); + cachePressedKeys.Remove(vkCode); } } catch (Exception e) { @@ -72,7 +95,9 @@ private static IntPtr OnKeyEvent(int Code, IntPtr W, IntPtr L) { public enum KeyEvents { KeyDown = 0x0100, - KeyUp = 0x0101 + KeyUp = 0x0101, + SysKeyDown = 0x0104, + SysKeyUp = 0x0105, } } } diff --git a/Classes/Services/Hotkeys/BookmarkHotkey.cs b/Classes/Services/Hotkeys/BookmarkHotkey.cs deleted file mode 100644 index 0c773d97..00000000 --- a/Classes/Services/Hotkeys/BookmarkHotkey.cs +++ /dev/null @@ -1,17 +0,0 @@ -#if WINDOWS -using RePlays.Services; - -namespace RePlays.Classes.Services.Hotkeys { - public class BookmarkHotkey : Hotkey { - private readonly string key = "CreateBookmark"; - public override void Action() { - if (RecordingService.IsRecording) BookmarkService.AddBookmark(new Bookmark { type = Bookmark.BookmarkType.Manual }); - } - - protected override void SetKeybind() { - SettingsService.Settings.keybindsSettings.TryGetValue(key, out string[] keybind); - _keybind = ParseKeys(key, keybind); - } - } -} -#endif \ No newline at end of file diff --git a/Classes/Services/Hotkeys/Hotkey.cs b/Classes/Services/Hotkeys/Hotkey.cs deleted file mode 100644 index 3689b5ea..00000000 --- a/Classes/Services/Hotkeys/Hotkey.cs +++ /dev/null @@ -1,49 +0,0 @@ -#if WINDOWS -using RePlays.Services; -using System; -using System.Collections.Generic; -using System.Windows.Forms; - -namespace RePlays.Classes.Services.Hotkeys { - public abstract class Hotkey { - protected Keys _keybind; - public Keys Keybind => _keybind; - - private static Dictionary defaultKeybindings = new Dictionary() { - { "StartStopRecording", new string[] { "Control", "F9" } }, - { "CreateBookmark", new string[] { "F8" } } - }; - - protected Hotkey() { - SetKeybind(); - } - - public static Keys ParseKeys(string keyReference, string[] keys) { - Keys keybind = Keys.None; - - if (keys == null) keys = AddMissingHotkey(keyReference); - - - for (int i = 0; i < keys.Length; i++) { - Keys key; - Enum.TryParse(keys[i], out key); - keybind |= key; - } - - return keybind; - } - - private static string[] AddMissingHotkey(string keyReference) { - defaultKeybindings.TryGetValue(keyReference, out string[] keys); - SettingsService.Settings.keybindsSettings.Add(keyReference, keys); - SettingsService.SaveSettings(); - return keys; - } - - public abstract void Action(); - - //TODO: Refactor - protected abstract void SetKeybind(); - } -} -#endif \ No newline at end of file diff --git a/Classes/Services/Hotkeys/RecordingHotkey.cs b/Classes/Services/Hotkeys/RecordingHotkey.cs deleted file mode 100644 index 9a416ff8..00000000 --- a/Classes/Services/Hotkeys/RecordingHotkey.cs +++ /dev/null @@ -1,19 +0,0 @@ -#if WINDOWS -using RePlays.Services; - -namespace RePlays.Classes.Services.Hotkeys { - public class RecordingHotkey : Hotkey { - private readonly string key = "StartStopRecording"; - public override void Action() { - if (RecordingService.IsRecording) RecordingService.StopRecording(); - else RecordingService.StartRecording(); - } - - protected override void SetKeybind() { - string[] keybind; - SettingsService.Settings.keybindsSettings.TryGetValue(key, out keybind); - _keybind = ParseKeys(key, keybind); - } - } -} -#endif \ No newline at end of file diff --git a/Classes/Services/Keybinds/BookmarkKeybind.cs b/Classes/Services/Keybinds/BookmarkKeybind.cs new file mode 100644 index 00000000..5ba17e94 --- /dev/null +++ b/Classes/Services/Keybinds/BookmarkKeybind.cs @@ -0,0 +1,16 @@ +#if WINDOWS +using RePlays.Services; + +namespace RePlays.Classes.Services.Keybinds { + public class BookmarkKeybind : Keybind { + public BookmarkKeybind() { + Id = "CreateBookmark"; + DefaultKeys = new string[] { "F8" }; + SetKeybind(); + } + public override void Action() { + if (RecordingService.IsRecording) BookmarkService.AddBookmark(new Bookmark { type = Bookmark.BookmarkType.Manual }); + } + } +} +#endif \ No newline at end of file diff --git a/Classes/Services/Keybinds/Keybind.cs b/Classes/Services/Keybinds/Keybind.cs new file mode 100644 index 00000000..93131ca0 --- /dev/null +++ b/Classes/Services/Keybinds/Keybind.cs @@ -0,0 +1,41 @@ +#if WINDOWS +using RePlays.Services; +using RePlays.Utils; + +namespace RePlays.Classes.Services.Keybinds { + public abstract class Keybind { + public string Id { get; internal set; } + internal string[] DefaultKeys { get; set; } + public string[] Keys { get; internal set; } + + public abstract void Action(); + + public virtual void SetKeybind(string[] Keys = null) { + if (Keys == null) { + bool exists = SettingsService.Settings.keybindSettings.TryGetValue(Id, out CustomKeybind existingBind); + if (!exists) { + SettingsService.Settings.keybindSettings[Id] = new CustomKeybind { + keys = DefaultKeys, + }; + SettingsService.SaveSettings(); + Keys = DefaultKeys; + Logger.WriteLine($"Set new keybind: Action={Id}, Keys={Keys}"); + } + else { + Keys = existingBind.keys; + Logger.WriteLine($"Set existing keybind: Action={Id}, Keys={string.Join(",", Keys)}"); + } + } + else { + SettingsService.Settings.keybindSettings[Id] = new CustomKeybind { + keys = Keys, + }; + SettingsService.SaveSettings(); + Logger.WriteLine($"Set new keybind: Action={Id}, Keys={string.Join(",", Keys)}"); + WebMessage.SendMessage(Functions.GetUserSettings()); + } + this.Keys = Keys; + } + } +} +#endif \ No newline at end of file diff --git a/Classes/Services/Keybinds/RecordingKeybind.cs b/Classes/Services/Keybinds/RecordingKeybind.cs new file mode 100644 index 00000000..f5e56aae --- /dev/null +++ b/Classes/Services/Keybinds/RecordingKeybind.cs @@ -0,0 +1,17 @@ +#if WINDOWS +using RePlays.Services; + +namespace RePlays.Classes.Services.Keybinds { + public class RecordingKeybind : Keybind { + public RecordingKeybind() { + Id = "StartStopRecording"; + DefaultKeys = new string[] { "LControlKey", "F9" }; + SetKeybind(); + } + public override void Action() { + if (RecordingService.IsRecording) RecordingService.StopRecording(); + else RecordingService.StartRecording(); + } + } +} +#endif \ No newline at end of file diff --git a/Classes/Services/SettingsService.cs b/Classes/Services/SettingsService.cs index 2c1402e3..79a97f62 100644 --- a/Classes/Services/SettingsService.cs +++ b/Classes/Services/SettingsService.cs @@ -27,8 +27,8 @@ public class SettingsJson { private DetectionSettings _detectionSettings = new(); public DetectionSettings detectionSettings { get { return _detectionSettings; } set { _detectionSettings = value; } } - private KeybindSettings _keybindsSettings = new(); - public KeybindSettings keybindsSettings { get { return _keybindsSettings; } set { _keybindsSettings = value; } } + private KeybindSettings _keybindSettings = new(); + public KeybindSettings keybindSettings { get { return _keybindSettings; } set { _keybindSettings = value; } } } public static void LoadSettings() { diff --git a/Classes/Utils/JSONObjects.cs b/Classes/Utils/JSONObjects.cs index c85173cc..02ee4881 100644 --- a/Classes/Utils/JSONObjects.cs +++ b/Classes/Utils/JSONObjects.cs @@ -1,3 +1,4 @@ +using RePlays.Classes.Services.Keybinds; using Squirrel; using System; using System.Collections.Generic; @@ -248,8 +249,18 @@ public class DetectionSettings { public List blacklist { get { return _blacklist; } set { _blacklist = value; } } } - // Key = Action, Value = Key combination - public class KeybindSettings : Dictionary { } + public class KeybindSettings : Dictionary { } + + public struct CustomKeybind { + public CustomKeybind(bool disabled, string[] keys) { + this._disabled = disabled; + this._keys = keys; + } + private bool _disabled; + public bool disabled { get { return _disabled; } set { _disabled = value; } } + private string[] _keys; + public string[] keys { get { return _keys; } set { _keys = value; } } + } public struct CustomGame { public CustomGame(string gameExe, string gameName) { diff --git a/Classes/Utils/Messages.cs b/Classes/Utils/Messages.cs index 722cf3f6..cb4026dd 100644 --- a/Classes/Utils/Messages.cs +++ b/Classes/Utils/Messages.cs @@ -202,9 +202,14 @@ public static async Task RecieveMessage(string message) { } break; #if WINDOWS - case "EditKeybind": { + case "EnterEditKeybind": { var id = webMessage.data.Replace("\"", ""); - Logger.WriteLine($"EditKeybind :: {id}"); + HotkeyService.EditId = id; + } + break; + case "ExitEditKeybind": { + var id = webMessage.data.Replace("\"", ""); + HotkeyService.EditId = null; } break; case "SelectFolder": { diff --git a/ClientApp/src/App.tsx b/ClientApp/src/App.tsx index 969de1b8..d0cba7cf 100644 --- a/ClientApp/src/App.tsx +++ b/ClientApp/src/App.tsx @@ -106,6 +106,8 @@ function App() { localStorage.setItem("videoMetadataBookmarks", JSON.stringify(videoMetadata)); break; case 'UserSettings': + //@ts-ignore + document.activeElement.blur(); setUserSettings(data); localStorage.setItem("availableRateControls", data.captureSettings.rateControlCache); localStorage.setItem("availableFileFormats", JSON.stringify(data.captureSettings.fileFormatsCache)); diff --git a/ClientApp/src/components/KeybindSelector.tsx b/ClientApp/src/components/KeybindSelector.tsx index ad4e9bf3..bee94176 100644 --- a/ClientApp/src/components/KeybindSelector.tsx +++ b/ClientApp/src/components/KeybindSelector.tsx @@ -1,9 +1,10 @@ import { postMessage } from '../helpers/messenger'; -import DropDownMenu from './DropDownMenu'; interface Props { + updateSettings: () => void; + settings: KeybindSettings | undefined; id: string; - keybind?: string[]; + keybind?: CustomKeybind; } interface Keybind { @@ -16,34 +17,36 @@ const keybinds: { [key: string]: Keybind } = { "CreateBookmark": { action: "Create Bookmark" } }; -export const KeybindSelector: React.FC = ({id, keybind}) => { +export const KeybindSelector: React.FC = ({settings, updateSettings, id, keybind}) => { return (
Action - {}}, - {name: "720p", onClick: () => {}}, - ]}/> +
+ {keybinds[id].action} +
Keybind
Enable
- {}}/> + {settings[id].disabled = !e.target.checked; updateSettings(); + }}/>
diff --git a/ClientApp/src/index.tsx b/ClientApp/src/index.tsx index 07ef211f..8ee87d9b 100644 --- a/ClientApp/src/index.tsx +++ b/ClientApp/src/index.tsx @@ -90,12 +90,12 @@ declare global { } // userSettings interface UserSettings { - generalSettings: GeneralSettings - captureSettings: CaptureSettings - detectionSettings: DetectionSettings - uploadSettings: UploadSettings - storageSettings: StorageSettings - keybindSettings: KeybindSettings + generalSettings: GeneralSettings, + captureSettings: CaptureSettings, + detectionSettings: DetectionSettings, + uploadSettings: UploadSettings, + storageSettings: StorageSettings, + keybindSettings: KeybindSettings, } interface GeneralSettings { launchStartup: boolean, @@ -154,7 +154,7 @@ declare global { customUploaderSettings: { url: string, method: string, - headers: {Key: string, Value: string}[], + headers: {Key: string, Value: string}[], urlparams: {Key: string, Value: string}[], responseType: string, responsePath: string, @@ -174,8 +174,12 @@ declare global { blacklist: string[], } interface KeybindSettings { - StartStopRecording: string[], - CreateBookmark: string[], + StartStopRecording: CustomKeybind, + CreateBookmark: CustomKeybind, + } + interface CustomKeybind { + disabled: boolean, + keys: string[], } interface CustomGame { gameExe: string, diff --git a/ClientApp/src/pages/Settings/Keybind.tsx b/ClientApp/src/pages/Settings/Keybind.tsx index 53ae22c4..eb261dd7 100644 --- a/ClientApp/src/pages/Settings/Keybind.tsx +++ b/ClientApp/src/pages/Settings/Keybind.tsx @@ -6,14 +6,16 @@ interface Props { } export const Keybind: React.FC = ({ settings, updateSettings }) => { + console.log(settings) + return (

Keybinds

- +
- +
)