forked from BlueCyro/Mediator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (56 loc) · 1.59 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (56 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Fleck;
using System.Runtime.InteropServices;
public class Program
{
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
public const byte PlayPause = 0xB3;
public const byte Next = 0xB0;
public const byte Prev = 0xB1;
private static Dictionary<string, byte> _commands = new Dictionary<string, byte>() {
{"playpause", 0xB3},
{"next", 0xB0},
{"prev", 0xB1}
};
public static void ConsoleBehavior()
{
var key = Console.ReadKey();
if (key.KeyChar == 'm')
{
keybd_event(PlayPause, 0, 0, UIntPtr.Zero);
ConsoleBehavior();
}
else if (key.KeyChar == 'p')
{
return;
}
else
{
ConsoleBehavior();
}
}
public static void Main(string[] args)
{
int portArg = -1;
Int32.TryParse(args.Length > 0 ? args[0] : "", out portArg);
portArg = portArg > 0 ? portArg : 9070;
var server = new WebSocketServer($"ws://127.0.0.1:{portArg}");
server.Start(socket =>
{
socket.OnOpen = () => {
socket.Send("Connected to media control!");
};
socket.OnMessage = msg => {
if (msg == "close")
{
socket.Close();
}
if (_commands.TryGetValue(msg, out byte key))
{
keybd_event(key, 0, 0, UIntPtr.Zero);
}
};
});
ConsoleBehavior();
}
}