mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 10:13:30 +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\Logitech\Utilities\OrionUtilities.cs" />
|
||||||
<Compile Include="DeviceProviders\Razer\BlackWidow.cs" />
|
<Compile Include="DeviceProviders\Razer\BlackWidow.cs" />
|
||||||
<Compile Include="DeviceProviders\Razer\Utilities\RazerUtilities.cs" />
|
<Compile Include="DeviceProviders\Razer\Utilities\RazerUtilities.cs" />
|
||||||
|
<Compile Include="Managers\KeybindManager.cs" />
|
||||||
<Compile Include="Models\DeviceVisualModel.cs" />
|
<Compile Include="Models\DeviceVisualModel.cs" />
|
||||||
<Compile Include="Models\FrameModel.cs" />
|
<Compile Include="Models\FrameModel.cs" />
|
||||||
<Compile Include="Managers\MigrationManager.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();
|
_processTimer.Start();
|
||||||
|
|
||||||
ProgramEnabled = false;
|
ProgramEnabled = false;
|
||||||
Running = false;
|
|
||||||
|
|
||||||
// Create and start the web server
|
// Create and start the web server
|
||||||
GameStateWebServer = gameStateWebServer;
|
GameStateWebServer = gameStateWebServer;
|
||||||
@ -71,7 +70,6 @@ namespace Artemis.Managers
|
|||||||
public PipeServer PipeServer { get; set; }
|
public PipeServer PipeServer { get; set; }
|
||||||
public GameStateWebServer GameStateWebServer { get; set; }
|
public GameStateWebServer GameStateWebServer { get; set; }
|
||||||
public bool ProgramEnabled { get; private set; }
|
public bool ProgramEnabled { get; private set; }
|
||||||
public bool Running { get; private set; }
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -73,11 +73,12 @@ namespace Artemis.Settings
|
|||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
SettingsProvider.Save(this);
|
SettingsProvider.Save(this);
|
||||||
|
|
||||||
|
Logging.SetupLogging(LogLevel);
|
||||||
ApplyAutorun();
|
ApplyAutorun();
|
||||||
ApplyTheme();
|
ApplyTheme();
|
||||||
ApplyGamestatePort();
|
ApplyGamestatePort();
|
||||||
ApplyScreenCaptureFPS();
|
ApplyScreenCaptureFPS();
|
||||||
Logging.SetupLogging(LogLevel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset(bool save = false)
|
public void Reset(bool save = false)
|
||||||
|
|||||||
@ -15,6 +15,19 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
|
|
||||||
private readonly LayerEditorViewModel _editorViewModel;
|
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 =
|
private readonly NamedOperator[] _int32Operators =
|
||||||
{
|
{
|
||||||
new NamedOperator("Lower than", "<"),
|
new NamedOperator("Lower than", "<"),
|
||||||
@ -41,6 +54,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
};
|
};
|
||||||
|
|
||||||
private bool _enumValueIsVisible;
|
private bool _enumValueIsVisible;
|
||||||
|
private bool _keybindIsVisible;
|
||||||
private GeneralHelpers.PropertyCollection _selectedDataModelProp;
|
private GeneralHelpers.PropertyCollection _selectedDataModelProp;
|
||||||
private string _selectedEnum;
|
private string _selectedEnum;
|
||||||
private NamedOperator _selectedOperator;
|
private NamedOperator _selectedOperator;
|
||||||
@ -52,9 +66,10 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
_editorViewModel = editorViewModel;
|
_editorViewModel = editorViewModel;
|
||||||
|
|
||||||
ConditionModel = conditionModel;
|
ConditionModel = conditionModel;
|
||||||
DataModelProps = editorViewModel.DataModelProps;
|
|
||||||
Operators = new BindableCollection<NamedOperator>();
|
Operators = new BindableCollection<NamedOperator>();
|
||||||
Enums = new BindableCollection<string>();
|
Enums = new BindableCollection<string>();
|
||||||
|
DataModelProps = new BindableCollection<GeneralHelpers.PropertyCollection>(_hotkeyProperties);
|
||||||
|
DataModelProps.AddRange(editorViewModel.DataModelProps);
|
||||||
|
|
||||||
PropertyChanged += MapViewToModel;
|
PropertyChanged += MapViewToModel;
|
||||||
MapModelToView();
|
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
|
public NamedOperator SelectedOperator
|
||||||
{
|
{
|
||||||
get { return _selectedOperator; }
|
get { return _selectedOperator; }
|
||||||
@ -190,6 +216,15 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
Operators.AddRange(_stringOperators);
|
Operators.AddRange(_stringOperators);
|
||||||
UserValueIsVisible = true;
|
UserValueIsVisible = true;
|
||||||
break;
|
break;
|
||||||
|
case "hotkeyEnable":
|
||||||
|
case "hotkeyDisable":
|
||||||
|
Operators.AddRange(_hotkeyOperators);
|
||||||
|
KeybindIsVisible = true;
|
||||||
|
break;
|
||||||
|
case "hotkeyToggle":
|
||||||
|
Operators.Add(_hotkeyOperators[0]);
|
||||||
|
KeybindIsVisible = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Operators.AddRange(_operators);
|
Operators.AddRange(_operators);
|
||||||
UserValueIsVisible = true;
|
UserValueIsVisible = true;
|
||||||
@ -215,13 +250,21 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
{
|
{
|
||||||
UserValueIsVisible = false;
|
UserValueIsVisible = false;
|
||||||
EnumValueIsVisible = false;
|
EnumValueIsVisible = false;
|
||||||
|
KeybindIsVisible = false;
|
||||||
|
|
||||||
|
// Event operators don't have any form of input
|
||||||
if (SelectedOperator.Value == "changed" || SelectedOperator.Value == "decreased" ||
|
if (SelectedOperator.Value == "changed" || SelectedOperator.Value == "decreased" ||
|
||||||
SelectedOperator.Value == "increased")
|
SelectedOperator.Value == "increased")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (SelectedDataModelProp.Type == "Boolean")
|
if (SelectedDataModelProp.Type.Contains("hotkey"))
|
||||||
|
{
|
||||||
|
KeybindIsVisible = true;
|
||||||
|
}
|
||||||
|
else if (SelectedDataModelProp.Type == "Boolean")
|
||||||
|
{
|
||||||
EnumValueIsVisible = true;
|
EnumValueIsVisible = true;
|
||||||
|
}
|
||||||
else if (SelectedDataModelProp.EnumValues != null)
|
else if (SelectedDataModelProp.EnumValues != null)
|
||||||
{
|
{
|
||||||
Enums.Clear();
|
Enums.Clear();
|
||||||
@ -229,7 +272,9 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
EnumValueIsVisible = true;
|
EnumValueIsVisible = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
UserValueIsVisible = true;
|
UserValueIsVisible = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:cal="http://www.caliburnproject.org"
|
xmlns:cal="http://www.caliburnproject.org"
|
||||||
xmlns:utilities="clr-namespace:Artemis.Utilities"
|
xmlns:utilities="clr-namespace:Artemis.Utilities"
|
||||||
|
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
|
||||||
mc:Ignorable="d" d:DesignWidth="613.296" Height="46">
|
mc:Ignorable="d" d:DesignWidth="613.296" Height="46">
|
||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
@ -50,8 +51,11 @@
|
|||||||
<ColumnDefinition Width="120" />
|
<ColumnDefinition Width="120" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</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">
|
<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>
|
||||||
<StackPanel Grid.Column="0" x:Name="EnumValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
<StackPanel Grid.Column="0" x:Name="EnumValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||||
<ComboBox x:Name="Enums" Width="110" MaxDropDownHeight="125" HorizontalAlignment="Center"
|
<ComboBox x:Name="Enums" Width="110" MaxDropDownHeight="125" HorizontalAlignment="Center"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user