Initial commit
This commit is contained in:
commit
ccd496c168
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
13
.idea/.idea.CSMediaControl/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.CSMediaControl/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Rider ignored files
|
||||||
|
/contentModel.xml
|
||||||
|
/.idea.CSMediaControl.iml
|
||||||
|
/projectSettingsUpdater.xml
|
||||||
|
/modules.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
4
.idea/.idea.CSMediaControl/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.CSMediaControl/.idea/encodings.xml
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
8
.idea/.idea.CSMediaControl/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.CSMediaControl/.idea/indexLayout.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/.idea.CSMediaControl/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.CSMediaControl/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
16
CSMediaControl.sln
Normal file
16
CSMediaControl.sln
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSMediaControl", "CSMediaControl\CSMediaControl.csproj", "{96EB5D7F-F477-4AFA-BCF6-F5F4A85A88C2}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{96EB5D7F-F477-4AFA-BCF6-F5F4A85A88C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{96EB5D7F-F477-4AFA-BCF6-F5F4A85A88C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{96EB5D7F-F477-4AFA-BCF6-F5F4A85A88C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{96EB5D7F-F477-4AFA-BCF6-F5F4A85A88C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
15
CSMediaControl/CSMediaControl.csproj
Normal file
15
CSMediaControl/CSMediaControl.csproj
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CS2GSI" Version="1.0.7" />
|
||||||
|
<PackageReference Include="GlaxLogger" Version="1.0.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
33
CSMediaControl/MediaController.cs
Normal file
33
CSMediaControl/MediaController.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace CSMediaControl;
|
||||||
|
|
||||||
|
internal static class MediaController
|
||||||
|
{
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
// ReSharper disable once IdentifierTypo
|
||||||
|
private static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
|
||||||
|
private const int KeyEventFExtendedKey = 1;
|
||||||
|
//private const int KeyEventFKeyup = 0;
|
||||||
|
//https://learn.microsoft.com/de-de/windows/win32/inputdev/virtual-key-codes
|
||||||
|
|
||||||
|
public static void PlayPause()
|
||||||
|
{
|
||||||
|
keybd_event(0xB3, 0, KeyEventFExtendedKey, IntPtr.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Next()
|
||||||
|
{
|
||||||
|
keybd_event(0xB0, 0, KeyEventFExtendedKey, IntPtr.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Previous()
|
||||||
|
{
|
||||||
|
keybd_event(0xB1, 0, KeyEventFExtendedKey, IntPtr.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Stop()
|
||||||
|
{
|
||||||
|
keybd_event(0xB2, 0, KeyEventFExtendedKey, IntPtr.Zero);
|
||||||
|
}
|
||||||
|
}
|
11
CSMediaControl/Program.cs
Normal file
11
CSMediaControl/Program.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
using CSMediaControl;
|
||||||
|
|
||||||
|
ConsoleKey key;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.WriteLine("Is media currently playing? (y/n)");
|
||||||
|
key = Console.ReadKey(true).Key;
|
||||||
|
} while (key != ConsoleKey.Y && key != ConsoleKey.N);
|
||||||
|
Watchdog _ = new (key == ConsoleKey.Y);
|
72
CSMediaControl/Watchdog.cs
Normal file
72
CSMediaControl/Watchdog.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using CS2GSI;
|
||||||
|
using GlaxLogger;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace CSMediaControl;
|
||||||
|
using GSI = CS2GSI.CS2GSI;
|
||||||
|
|
||||||
|
public class Watchdog : IDisposable, IAsyncDisposable
|
||||||
|
{
|
||||||
|
private bool _keepRunning = true;
|
||||||
|
private readonly GSI _gsi;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
private bool _mediaRunning;
|
||||||
|
|
||||||
|
public Watchdog(bool mediaRunning)
|
||||||
|
{
|
||||||
|
this._mediaRunning = mediaRunning;
|
||||||
|
this._logger = new Logger(LogLevel.Information, consoleOut: Console.Out);
|
||||||
|
this._gsi = new GSI(this._logger);
|
||||||
|
|
||||||
|
this._gsi.OnRoundStart += MusicStart;
|
||||||
|
this._gsi.OnRoundOver += MusicStop;
|
||||||
|
this._gsi.OnDeath += MusicStop;
|
||||||
|
|
||||||
|
Console.WriteLine("Press p to pause/play media.");
|
||||||
|
while (_keepRunning)
|
||||||
|
{
|
||||||
|
if (Console.KeyAvailable && Console.ReadKey(true).Key is ConsoleKey.P)
|
||||||
|
{
|
||||||
|
if(this._mediaRunning)
|
||||||
|
MusicStop(null);
|
||||||
|
else
|
||||||
|
MusicStart(null);
|
||||||
|
}else
|
||||||
|
Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
this._logger.Log(LogLevel.Information, "Bye!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MusicStop(CS2EventArgs? _)
|
||||||
|
{
|
||||||
|
if (_mediaRunning)
|
||||||
|
{
|
||||||
|
this._logger.Log(LogLevel.Information, "Music Pause");
|
||||||
|
MediaController.PlayPause();
|
||||||
|
this._mediaRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MusicStart(CS2EventArgs? _)
|
||||||
|
{
|
||||||
|
if (!_mediaRunning)
|
||||||
|
{
|
||||||
|
this._logger.Log(LogLevel.Information, "Music Start");
|
||||||
|
MediaController.PlayPause();
|
||||||
|
this._mediaRunning = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
this._keepRunning = false;
|
||||||
|
_logger.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask DisposeAsync()
|
||||||
|
{
|
||||||
|
this._keepRunning = false;
|
||||||
|
await _logger.DisposeAsync();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user