mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Started work on keybinds
This commit is contained in:
parent
7373bad446
commit
e051918486
@ -354,6 +354,7 @@
|
||||
<Compile Include="DeviceProviders\Logitech\Utilities\OrionUtilities.cs" />
|
||||
<Compile Include="DeviceProviders\Razer\BlackWidow.cs" />
|
||||
<Compile Include="DeviceProviders\Razer\Utilities\RazerUtilities.cs" />
|
||||
<Compile Include="Managers\KeybindManager.cs" />
|
||||
<Compile Include="Models\DeviceVisualModel.cs" />
|
||||
<Compile Include="Models\FrameModel.cs" />
|
||||
<Compile Include="Managers\MigrationManager.cs" />
|
||||
|
||||
85
Artemis/Artemis/Managers/KeybindManager.cs
Normal file
85
Artemis/Artemis/Managers/KeybindManager.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Utilities.Keyboard;
|
||||
using MahApps.Metro.Controls;
|
||||
using KeyEventArgs = System.Windows.Forms.KeyEventArgs;
|
||||
|
||||
namespace Artemis.Managers
|
||||
{
|
||||
public static class KeybindManager
|
||||
{
|
||||
private static readonly Dictionary<HotKey, Action> HotKeys;
|
||||
|
||||
static KeybindManager()
|
||||
{
|
||||
KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback;
|
||||
HotKeys = new Dictionary<HotKey, Action>();
|
||||
}
|
||||
|
||||
private static void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
||||
{
|
||||
// Don't trigger if none of the modifiers are held down
|
||||
if (!e.Alt && !e.Control && !e.Shift)
|
||||
return;
|
||||
|
||||
// Don't trigger if the key itself is a modifier
|
||||
if (e.KeyCode == Keys.LShiftKey || e.KeyCode == Keys.RShiftKey ||
|
||||
e.KeyCode == Keys.LControlKey || e.KeyCode == Keys.RControlKey ||
|
||||
e.KeyCode == Keys.LMenu || e.KeyCode == Keys.RMenu)
|
||||
return;
|
||||
|
||||
// Create a WPF ModifierKeys enum
|
||||
var modifiers = ModifierKeys.None;
|
||||
if (e.Alt)
|
||||
modifiers = ModifierKeys.Alt;
|
||||
if (e.Control)
|
||||
if (modifiers == ModifierKeys.None)
|
||||
modifiers = ModifierKeys.Control;
|
||||
else
|
||||
modifiers |= ModifierKeys.Control;
|
||||
if (e.Shift)
|
||||
if (modifiers == ModifierKeys.None)
|
||||
modifiers = ModifierKeys.Shift;
|
||||
else
|
||||
modifiers |= ModifierKeys.Shift;
|
||||
|
||||
// Create a HotKey object for comparison
|
||||
var hotKey = new HotKey(KeyInterop.KeyFromVirtualKey(e.KeyValue), modifiers);
|
||||
|
||||
// If the hotkey is present, invoke the action related to it
|
||||
if (HotKeys.ContainsKey(hotKey))
|
||||
HotKeys[hotKey].Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers a hotkey and executes the provided action when the hotkey is pressed
|
||||
/// </summary>
|
||||
/// <param name="hotKey">The hotkey to register</param>
|
||||
/// <param name="action">The action to invoke on press</param>
|
||||
/// <returns>Returns true if key registed, false if already in use</returns>
|
||||
public static bool RegisterHotkey(HotKey hotKey, Action action)
|
||||
{
|
||||
if (HotKeys.ContainsKey(hotKey))
|
||||
return false;
|
||||
|
||||
HotKeys.Add(hotKey, action);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregister the given hotkey
|
||||
/// </summary>
|
||||
/// <param name="hotKey">The hotkey to unregister</param>
|
||||
/// <returns>Returns true if unregistered, false if not found</returns>
|
||||
public static bool UnregisterHotkey(HotKey hotKey)
|
||||
{
|
||||
if (!HotKeys.ContainsKey(hotKey))
|
||||
return false;
|
||||
|
||||
HotKeys.Remove(hotKey);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,6 @@ namespace Artemis.Managers
|
||||
_processTimer.Start();
|
||||
|
||||
ProgramEnabled = false;
|
||||
Running = false;
|
||||
|
||||
// Create and start the web server
|
||||
GameStateWebServer = gameStateWebServer;
|
||||
@ -71,7 +70,6 @@ namespace Artemis.Managers
|
||||
public PipeServer PipeServer { get; set; }
|
||||
public GameStateWebServer GameStateWebServer { get; set; }
|
||||
public bool ProgramEnabled { get; private set; }
|
||||
public bool Running { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@ -73,11 +73,12 @@ namespace Artemis.Settings
|
||||
public void Save()
|
||||
{
|
||||
SettingsProvider.Save(this);
|
||||
|
||||
Logging.SetupLogging(LogLevel);
|
||||
ApplyAutorun();
|
||||
ApplyTheme();
|
||||
ApplyGamestatePort();
|
||||
ApplyScreenCaptureFPS();
|
||||
Logging.SetupLogging(LogLevel);
|
||||
}
|
||||
|
||||
public void Reset(bool save = false)
|
||||
|
||||
@ -18,10 +18,10 @@ namespace Artemis.Utilities.Keyboard
|
||||
}
|
||||
|
||||
private static async void VirtualKeyboardOnKeyDown(object sender, KeyEventArgs keyEventArgs)
|
||||
{
|
||||
{
|
||||
await Task.Factory.StartNew(() => { KeyDownCallback?.Invoke(keyEventArgs); });
|
||||
}
|
||||
|
||||
|
||||
public static event KeyDownCallbackHandler KeyDownCallback;
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,19 @@ namespace Artemis.ViewModels.Profiles
|
||||
|
||||
private readonly LayerEditorViewModel _editorViewModel;
|
||||
|
||||
private readonly NamedOperator[] _hotkeyOperators =
|
||||
{
|
||||
new NamedOperator("Pressed", "enable"),
|
||||
new NamedOperator("Held down", "disable")
|
||||
};
|
||||
|
||||
private readonly GeneralHelpers.PropertyCollection[] _hotkeyProperties =
|
||||
{
|
||||
new GeneralHelpers.PropertyCollection {Display = "Enable when hotkey", Type = "hotkeyEnable"},
|
||||
new GeneralHelpers.PropertyCollection {Display = "Disable when hotkey", Type = "hotkeyDisable"},
|
||||
new GeneralHelpers.PropertyCollection {Display = "Toggle when hotkey", Type = "hotkeyToggle"}
|
||||
};
|
||||
|
||||
private readonly NamedOperator[] _int32Operators =
|
||||
{
|
||||
new NamedOperator("Lower than", "<"),
|
||||
@ -41,6 +54,7 @@ namespace Artemis.ViewModels.Profiles
|
||||
};
|
||||
|
||||
private bool _enumValueIsVisible;
|
||||
private bool _keybindIsVisible;
|
||||
private GeneralHelpers.PropertyCollection _selectedDataModelProp;
|
||||
private string _selectedEnum;
|
||||
private NamedOperator _selectedOperator;
|
||||
@ -52,9 +66,10 @@ namespace Artemis.ViewModels.Profiles
|
||||
_editorViewModel = editorViewModel;
|
||||
|
||||
ConditionModel = conditionModel;
|
||||
DataModelProps = editorViewModel.DataModelProps;
|
||||
Operators = new BindableCollection<NamedOperator>();
|
||||
Enums = new BindableCollection<string>();
|
||||
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>(_hotkeyProperties);
|
||||
DataModelProps.AddRange(editorViewModel.DataModelProps);
|
||||
|
||||
PropertyChanged += MapViewToModel;
|
||||
MapModelToView();
|
||||
@ -112,6 +127,17 @@ namespace Artemis.ViewModels.Profiles
|
||||
}
|
||||
}
|
||||
|
||||
public bool KeybindIsVisible
|
||||
{
|
||||
get { return _keybindIsVisible; }
|
||||
set
|
||||
{
|
||||
if (value == _keybindIsVisible) return;
|
||||
_keybindIsVisible = value;
|
||||
NotifyOfPropertyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public NamedOperator SelectedOperator
|
||||
{
|
||||
get { return _selectedOperator; }
|
||||
@ -190,6 +216,15 @@ namespace Artemis.ViewModels.Profiles
|
||||
Operators.AddRange(_stringOperators);
|
||||
UserValueIsVisible = true;
|
||||
break;
|
||||
case "hotkeyEnable":
|
||||
case "hotkeyDisable":
|
||||
Operators.AddRange(_hotkeyOperators);
|
||||
KeybindIsVisible = true;
|
||||
break;
|
||||
case "hotkeyToggle":
|
||||
Operators.Add(_hotkeyOperators[0]);
|
||||
KeybindIsVisible = true;
|
||||
break;
|
||||
default:
|
||||
Operators.AddRange(_operators);
|
||||
UserValueIsVisible = true;
|
||||
@ -207,7 +242,7 @@ namespace Artemis.ViewModels.Profiles
|
||||
Operators.Add(new NamedOperator("Increased", "increased"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SetupUserValueInput();
|
||||
}
|
||||
|
||||
@ -215,13 +250,21 @@ namespace Artemis.ViewModels.Profiles
|
||||
{
|
||||
UserValueIsVisible = false;
|
||||
EnumValueIsVisible = false;
|
||||
KeybindIsVisible = false;
|
||||
|
||||
// Event operators don't have any form of input
|
||||
if (SelectedOperator.Value == "changed" || SelectedOperator.Value == "decreased" ||
|
||||
SelectedOperator.Value == "increased")
|
||||
return;
|
||||
|
||||
if (SelectedDataModelProp.Type == "Boolean")
|
||||
if (SelectedDataModelProp.Type.Contains("hotkey"))
|
||||
{
|
||||
KeybindIsVisible = true;
|
||||
}
|
||||
else if (SelectedDataModelProp.Type == "Boolean")
|
||||
{
|
||||
EnumValueIsVisible = true;
|
||||
}
|
||||
else if (SelectedDataModelProp.EnumValues != null)
|
||||
{
|
||||
Enums.Clear();
|
||||
@ -229,7 +272,9 @@ namespace Artemis.ViewModels.Profiles
|
||||
EnumValueIsVisible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
UserValueIsVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:cal="http://www.caliburnproject.org"
|
||||
xmlns:utilities="clr-namespace:Artemis.Utilities"
|
||||
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
|
||||
mc:Ignorable="d" d:DesignWidth="613.296" Height="46">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
@ -50,8 +51,11 @@
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0" x:Name="KeybindIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<controls:HotKeyBox x:Name="Keybind" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110" Watermark="Enter keybind" AreModifierKeysRequired="True" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="0" x:Name="UserValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<TextBox x:Name="UserValue" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110" />
|
||||
<TextBox x:Name="UserValue" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110" controls:TextBoxHelper.Watermark="Enter value" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="0" x:Name="EnumValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<ComboBox x:Name="Enums" Width="110" MaxDropDownHeight="125" HorizontalAlignment="Center"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user