-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminalCommands.cs
More file actions
98 lines (86 loc) · 3.48 KB
/
Copy pathTerminalCommands.cs
File metadata and controls
98 lines (86 loc) · 3.48 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//-------------------------------------------------------------------
// Copyright © 2012 Kindel Systems, LLC
// http://www.kindel.com
// charlie@kindel.com
//
// Published under the MIT License.
// Source control on SourceForge
// http://sourceforge.net/projects/mcecontroller/
//-------------------------------------------------------------------
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using MCEControl.Properties;
using WindowsInput.Native;
namespace MCEControl
{
/// <summary>
/// Commands that control MCE Controller, or get information about it
/// </summary>
class McecCommand : Command
{
public static readonly string CmdPrefix = "mcec:";
public McecCommand(string cmd)
{
Key = cmd.Substring(CmdPrefix.Length, cmd.Length - CmdPrefix.Length);
}
public override void Execute(Reply reply)
{
if (reply == null)
return;
var replyBuilder = new StringBuilder();
switch (Key)
{
// MCE Controller version
case "ver":
replyBuilder.Append(Application.ProductVersion);
break;
// Cause MCE Controller to exit
case "exit":
reply.WriteLine("exiting");
MainWindow.MainWnd.BeginInvoke((Action)(() => MainWindow.MainWnd.ShutDown()));
return;
// Return a list of supported commands (really just for testing)
case "cmds":
foreach (Command cmd in MainWindow.MainWnd.CmdTable.List)
{
Match match = Regex.Match(cmd.GetType().ToString(), @"MCEControl\.([A-za-z]+)Command");
replyBuilder.AppendFormat("{0}={1}{2}", cmd.Key, match.Groups[1].Value, Environment.NewLine);
}
// Now add VK_ commands
foreach (VirtualKeyCode vk in Enum.GetValues(typeof(VirtualKeyCode)))
{
string s;
if (vk > VirtualKeyCode.HELP && vk < VirtualKeyCode.LWIN)
s = vk.ToString(); // already have VK_
else
s = "VK_" + vk.ToString();
replyBuilder.AppendFormat("{0}={1}{2}", s, "SendInput", Environment.NewLine);
}
break;
// Return the current date/time of the PC
case "time":
DateTime dt = DateTime.Now;
replyBuilder.AppendFormat("{0}", DateTime.Now);
break;
// These two are for testing. They cause a loop between two
// instances of MCE Controller
case "foo":
reply.WriteLine("mcec:bar");
return;
case "bar":
reply.WriteLine("mcec:foo");
return;
}
// Reply.
replyBuilder.Insert(0, string.Format("{0}=", Key));
Reply(reply, replyBuilder.ToString());
}
private void Reply(Reply reply, string msg)
{
MainWindow.AddLogEntry("Cmd: Sending reply: " + msg);
reply.WriteLine(msg);
}
}
}