mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Updated keyboard hook and TypeWave, fixes #19
This commit is contained in:
parent
327bd928da
commit
ef270a1aa4
@ -101,6 +101,10 @@
|
|||||||
<HintPath>..\packages\CUE.NET.1.0.0\lib\net45\CUE.NET.dll</HintPath>
|
<HintPath>..\packages\CUE.NET.1.0.0\lib\net45\CUE.NET.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Gma.System.MouseKeyHook, Version=5.4.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\MouseKeyHook.5.4.0\lib\net40\Gma.System.MouseKeyHook.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.5\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
|
<HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.5\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
@ -127,10 +131,6 @@
|
|||||||
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Open.WinKeyboardHook, Version=1.0.10.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\packages\Open.WinKeyboardHook.1.0.10.0\lib\net45\Open.WinKeyboardHook.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
@ -270,6 +270,7 @@
|
|||||||
<Compile Include="Utilities\GameState\GameDataReceivedEventArgs.cs" />
|
<Compile Include="Utilities\GameState\GameDataReceivedEventArgs.cs" />
|
||||||
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />
|
<Compile Include="Utilities\GameState\GameStateWebServer.cs" />
|
||||||
<Compile Include="Utilities\ImageUtilities.cs" />
|
<Compile Include="Utilities\ImageUtilities.cs" />
|
||||||
|
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
|
||||||
<Compile Include="Utilities\Memory\Memory.cs" />
|
<Compile Include="Utilities\Memory\Memory.cs" />
|
||||||
<Compile Include="Utilities\Memory\MemoryHelpers.cs" />
|
<Compile Include="Utilities\Memory\MemoryHelpers.cs" />
|
||||||
<Compile Include="Utilities\Memory\Win32.cs" />
|
<Compile Include="Utilities\Memory\Win32.cs" />
|
||||||
|
|||||||
@ -8,6 +8,7 @@ using Artemis.Events;
|
|||||||
using Artemis.KeyboardProviders;
|
using Artemis.KeyboardProviders;
|
||||||
using Artemis.Settings;
|
using Artemis.Settings;
|
||||||
using Artemis.Utilities.GameState;
|
using Artemis.Utilities.GameState;
|
||||||
|
using Artemis.Utilities.Keyboard;
|
||||||
using Artemis.Utilities.Memory;
|
using Artemis.Utilities.Memory;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ namespace Artemis.Models
|
|||||||
EffectModels = new List<EffectModel>();
|
EffectModels = new List<EffectModel>();
|
||||||
KeyboardProviders = ProviderHelper.GetKeyboardProviders();
|
KeyboardProviders = ProviderHelper.GetKeyboardProviders();
|
||||||
GameStateWebServer = new GameStateWebServer();
|
GameStateWebServer = new GameStateWebServer();
|
||||||
|
KeyboardHook = new KeyboardHook();
|
||||||
|
|
||||||
Events = events;
|
Events = events;
|
||||||
Fps = 25;
|
Fps = 25;
|
||||||
@ -33,6 +35,8 @@ namespace Artemis.Models
|
|||||||
_processWorker.DoWork += ProcessWorker_DoWork;
|
_processWorker.DoWork += ProcessWorker_DoWork;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KeyboardHook KeyboardHook { get; set; }
|
||||||
|
|
||||||
public EffectModel ActiveEffect { get; set; }
|
public EffectModel ActiveEffect { get; set; }
|
||||||
public KeyboardProvider ActiveKeyboard { get; set; }
|
public KeyboardProvider ActiveKeyboard { get; set; }
|
||||||
public List<EffectModel> EffectModels { get; set; }
|
public List<EffectModel> EffectModels { get; set; }
|
||||||
|
|||||||
@ -7,65 +7,66 @@ using System.Windows.Forms;
|
|||||||
using Artemis.KeyboardProviders.Logitech.Utilities;
|
using Artemis.KeyboardProviders.Logitech.Utilities;
|
||||||
using Artemis.Models;
|
using Artemis.Models;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
using Open.WinKeyboardHook;
|
using Gma.System.MouseKeyHook;
|
||||||
|
|
||||||
namespace Artemis.Modules.Effects.TypeWave
|
namespace Artemis.Modules.Effects.TypeWave
|
||||||
{
|
{
|
||||||
public class TypeWaveModel : EffectModel
|
public class TypeWaveModel : EffectModel
|
||||||
{
|
{
|
||||||
|
private readonly List<Wave> _waves;
|
||||||
|
private Color _randomColor;
|
||||||
|
|
||||||
public TypeWaveModel(MainModel mainModel, TypeWaveSettings settings) : base(mainModel)
|
public TypeWaveModel(MainModel mainModel, TypeWaveSettings settings) : base(mainModel)
|
||||||
{
|
{
|
||||||
Name = "TypeWave";
|
Name = "TypeWave";
|
||||||
Waves = new List<Wave>();
|
_waves = new List<Wave>();
|
||||||
|
_randomColor = Color.Red;
|
||||||
Settings = settings;
|
Settings = settings;
|
||||||
|
|
||||||
// KeyboardIntercepter won't start untill the effect is active
|
|
||||||
KeyboardInterceptor = new KeyboardInterceptor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeWaveSettings Settings { get; set; }
|
public TypeWaveSettings Settings { get; set; }
|
||||||
public List<Wave> Waves { get; set; }
|
|
||||||
public KeyboardInterceptor KeyboardInterceptor { get; set; }
|
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
KeyboardInterceptor.KeyUp -= HandleKeypress;
|
MainModel.KeyboardHook.Unsubscribe(HandleKeypress);
|
||||||
KeyboardInterceptor.StopCapturing();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Enable()
|
public override void Enable()
|
||||||
{
|
{
|
||||||
KeyboardInterceptor.StartCapturing();
|
// Listener won't start unless the effect is active
|
||||||
KeyboardInterceptor.KeyUp += HandleKeypress;
|
MainModel.KeyboardHook.Subscribe(HandleKeypress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < Waves.Count; i++)
|
if (Settings.IsRandomColors)
|
||||||
|
_randomColor = ColorHelpers.ShiftColor(_randomColor, 25);
|
||||||
|
|
||||||
|
for (var i = 0; i < _waves.Count; i++)
|
||||||
{
|
{
|
||||||
// TODO: Get from settings
|
// TODO: Get from settings
|
||||||
var fps = 25;
|
var fps = 25;
|
||||||
|
|
||||||
Waves[i].Size += Settings.SpreadSpeed;
|
_waves[i].Size += Settings.SpreadSpeed;
|
||||||
|
|
||||||
if (Settings.IsShiftColors)
|
if (Settings.IsShiftColors)
|
||||||
Waves[i].Color = ColorHelpers.ShiftColor(Waves[i].Color, Settings.ShiftColorSpeed);
|
_waves[i].Color = ColorHelpers.ShiftColor(_waves[i].Color, Settings.ShiftColorSpeed);
|
||||||
|
|
||||||
var decreaseAmount = 255/(Settings.TimeToLive/fps);
|
var decreaseAmount = 255/(Settings.TimeToLive/fps);
|
||||||
Waves[i].Color = Color.FromArgb(Waves[i].Color.A - decreaseAmount, Waves[i].Color.R, Waves[i].Color.G,
|
_waves[i].Color = Color.FromArgb(_waves[i].Color.A - decreaseAmount, _waves[i].Color.R, _waves[i].Color.G,
|
||||||
Waves[i].Color.B);
|
_waves[i].Color.B);
|
||||||
|
|
||||||
if (Waves[i].Color.A >= decreaseAmount)
|
if (_waves[i].Color.A >= decreaseAmount)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Waves.RemoveAt(i);
|
_waves.RemoveAt(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Bitmap GenerateBitmap()
|
public override Bitmap GenerateBitmap()
|
||||||
{
|
{
|
||||||
if (Waves.Count == 0)
|
if (_waves.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var bitmap = new Bitmap(21, 6);
|
var bitmap = new Bitmap(21, 6);
|
||||||
@ -78,17 +79,17 @@ namespace Artemis.Modules.Effects.TypeWave
|
|||||||
|
|
||||||
// Don't want a foreach, collection is changed in different thread
|
// Don't want a foreach, collection is changed in different thread
|
||||||
// ReSharper disable once ForCanBeConvertedToForeach
|
// ReSharper disable once ForCanBeConvertedToForeach
|
||||||
for (var i = 0; i < Waves.Count; i++)
|
for (var i = 0; i < _waves.Count; i++)
|
||||||
{
|
{
|
||||||
if (Waves[i].Size == 0)
|
if (_waves[i].Size == 0)
|
||||||
continue;
|
continue;
|
||||||
var path = new GraphicsPath();
|
var path = new GraphicsPath();
|
||||||
path.AddEllipse(Waves[i].Point.X - Waves[i].Size/2, Waves[i].Point.Y - Waves[i].Size/2,
|
path.AddEllipse(_waves[i].Point.X - _waves[i].Size/2, _waves[i].Point.Y - _waves[i].Size/2,
|
||||||
Waves[i].Size, Waves[i].Size);
|
_waves[i].Size, _waves[i].Size);
|
||||||
|
|
||||||
var pthGrBrush = new PathGradientBrush(path)
|
var pthGrBrush = new PathGradientBrush(path)
|
||||||
{
|
{
|
||||||
SurroundColors = new[] {Waves[i].Color},
|
SurroundColors = new[] {_waves[i].Color},
|
||||||
CenterColor = Color.Transparent
|
CenterColor = Color.Transparent
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,8 +97,8 @@ namespace Artemis.Modules.Effects.TypeWave
|
|||||||
pthGrBrush.FocusScales = new PointF(0.3f, 0.8f);
|
pthGrBrush.FocusScales = new PointF(0.3f, 0.8f);
|
||||||
|
|
||||||
g.FillPath(pthGrBrush, path);
|
g.FillPath(pthGrBrush, path);
|
||||||
g.DrawEllipse(new Pen(pthGrBrush, 1), Waves[i].Point.X - Waves[i].Size/2,
|
g.DrawEllipse(new Pen(pthGrBrush, 1), _waves[i].Point.X - _waves[i].Size/2,
|
||||||
Waves[i].Point.Y - Waves[i].Size/2, Waves[i].Size, Waves[i].Size);
|
_waves[i].Point.Y - _waves[i].Size/2, _waves[i].Size, _waves[i].Size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bitmap;
|
return bitmap;
|
||||||
@ -114,8 +115,8 @@ namespace Artemis.Modules.Effects.TypeWave
|
|||||||
if (keyMatch == null)
|
if (keyMatch == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Waves.Add(Settings.IsRandomColors
|
_waves.Add(Settings.IsRandomColors
|
||||||
? new Wave(new Point(keyMatch.PosX, keyMatch.PosY), 0, ColorHelpers.GetRandomRainbowColor())
|
? new Wave(new Point(keyMatch.PosX, keyMatch.PosY), 0, _randomColor)
|
||||||
: new Wave(new Point(keyMatch.PosX, keyMatch.PosY), 0,
|
: new Wave(new Point(keyMatch.PosX, keyMatch.PosY), 0,
|
||||||
ColorHelpers.ToDrawingColor(Settings.WaveColor)));
|
ColorHelpers.ToDrawingColor(Settings.WaveColor)));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,21 +3,19 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Artemis.Models;
|
using Artemis.Models;
|
||||||
|
using Gma.System.MouseKeyHook;
|
||||||
using NAudio.CoreAudioApi;
|
using NAudio.CoreAudioApi;
|
||||||
using Open.WinKeyboardHook;
|
|
||||||
|
|
||||||
namespace Artemis.Modules.Overlays.VolumeDisplay
|
namespace Artemis.Modules.Overlays.VolumeDisplay
|
||||||
{
|
{
|
||||||
public class VolumeDisplayModel : OverlayModel
|
public class VolumeDisplayModel : OverlayModel
|
||||||
{
|
{
|
||||||
|
private IKeyboardMouseEvents _mGlobalHook;
|
||||||
|
|
||||||
public VolumeDisplayModel(MainModel mainModel, VolumeDisplaySettings settings) : base(mainModel)
|
public VolumeDisplayModel(MainModel mainModel, VolumeDisplaySettings settings) : base(mainModel)
|
||||||
{
|
{
|
||||||
Settings = settings;
|
Settings = settings;
|
||||||
Name = "VolumeDisplay";
|
Name = "VolumeDisplay";
|
||||||
|
|
||||||
KeyboardInterceptor = new KeyboardInterceptor();
|
|
||||||
KeyboardInterceptor.StartCapturing();
|
|
||||||
|
|
||||||
Enabled = Settings.Enabled;
|
Enabled = Settings.Enabled;
|
||||||
|
|
||||||
VolumeDisplay = new VolumeDisplay(mainModel, settings);
|
VolumeDisplay = new VolumeDisplay(mainModel, settings);
|
||||||
@ -26,18 +24,16 @@ namespace Artemis.Modules.Overlays.VolumeDisplay
|
|||||||
public VolumeDisplay VolumeDisplay { get; set; }
|
public VolumeDisplay VolumeDisplay { get; set; }
|
||||||
|
|
||||||
public VolumeDisplaySettings Settings { get; set; }
|
public VolumeDisplaySettings Settings { get; set; }
|
||||||
public KeyboardInterceptor KeyboardInterceptor { get; set; }
|
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
KeyboardInterceptor.KeyUp -= HandleKeypress;
|
MainModel.KeyboardHook.Unsubscribe(HandleKeypress);
|
||||||
KeyboardInterceptor.StopCapturing();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Enable()
|
public override void Enable()
|
||||||
{
|
{
|
||||||
KeyboardInterceptor.StartCapturing();
|
// Listener won't start unless the effect is active
|
||||||
KeyboardInterceptor.KeyUp += HandleKeypress;
|
MainModel.KeyboardHook.Subscribe(HandleKeypress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
|
|||||||
31
Artemis/Artemis/Utilities/Keyboard/KeyboardHook.cs
Normal file
31
Artemis/Artemis/Utilities/Keyboard/KeyboardHook.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
using Gma.System.MouseKeyHook;
|
||||||
|
|
||||||
|
namespace Artemis.Utilities.Keyboard
|
||||||
|
{
|
||||||
|
public class KeyboardHook
|
||||||
|
{
|
||||||
|
private IKeyboardMouseEvents _mGlobalHook;
|
||||||
|
public int Subscriptions { get; set; }
|
||||||
|
|
||||||
|
public void Subscribe(KeyEventHandler handleKeypress)
|
||||||
|
{
|
||||||
|
if (Subscriptions < 1)
|
||||||
|
_mGlobalHook = Hook.GlobalEvents();
|
||||||
|
|
||||||
|
_mGlobalHook.KeyDown += handleKeypress;
|
||||||
|
Subscriptions++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unsubscribe(KeyEventHandler handleKeypress)
|
||||||
|
{
|
||||||
|
_mGlobalHook.KeyDown -= handleKeypress;
|
||||||
|
Subscriptions--;
|
||||||
|
|
||||||
|
if (Subscriptions >= 1)
|
||||||
|
return;
|
||||||
|
_mGlobalHook.Dispose();
|
||||||
|
_mGlobalHook = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,8 +11,8 @@
|
|||||||
<package id="log4net" version="2.0.5" targetFramework="net452" />
|
<package id="log4net" version="2.0.5" targetFramework="net452" />
|
||||||
<package id="MahApps.Metro" version="1.3.0-ALPHA017" targetFramework="net452" />
|
<package id="MahApps.Metro" version="1.3.0-ALPHA017" targetFramework="net452" />
|
||||||
<package id="MahApps.Metro.Resources" version="0.4.0.0" targetFramework="net452" />
|
<package id="MahApps.Metro.Resources" version="0.4.0.0" targetFramework="net452" />
|
||||||
|
<package id="MouseKeyHook" version="5.4.0" targetFramework="net452" />
|
||||||
<package id="NAudio" version="1.7.3" targetFramework="net452" />
|
<package id="NAudio" version="1.7.3" targetFramework="net452" />
|
||||||
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
|
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
|
||||||
<package id="Open.WinKeyboardHook" version="1.0.10.0" targetFramework="net452" />
|
|
||||||
<package id="WpfExceptionViewer" version="1.0.0.0" targetFramework="net452" />
|
<package id="WpfExceptionViewer" version="1.0.0.0" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
||||||
Loading…
x
Reference in New Issue
Block a user