2016-04-24 14:12:33 +02:00
|
|
|
|
using System;
|
|
|
|
|
using KeeWebHelper.InputCommands;
|
|
|
|
|
|
|
|
|
|
namespace KeeWebHelper
|
|
|
|
|
{
|
|
|
|
|
class InputParser
|
|
|
|
|
{
|
|
|
|
|
public static InputCommandBase Next()
|
|
|
|
|
{
|
|
|
|
|
var line = Console.ReadLine();
|
|
|
|
|
if (line == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (line.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return new NoOpCommand();
|
|
|
|
|
}
|
|
|
|
|
var parts = line.Split(new[] { ' ' }, 2);
|
|
|
|
|
switch (parts[0])
|
|
|
|
|
{
|
|
|
|
|
case "exit":
|
|
|
|
|
return null;
|
|
|
|
|
case "key":
|
2016-08-08 19:55:30 +02:00
|
|
|
|
return ParseSendCommand(parts[1], false);
|
2016-04-24 14:12:33 +02:00
|
|
|
|
case "text":
|
2016-08-08 19:55:30 +02:00
|
|
|
|
return ParseSendCommand(parts[1], true);
|
2016-04-24 14:12:33 +02:00
|
|
|
|
case "copypaste":
|
|
|
|
|
return new CopyPasteCommand(parts[1]);
|
|
|
|
|
case "wait":
|
|
|
|
|
return new WaitCommand(int.Parse(parts[1]));
|
|
|
|
|
default:
|
|
|
|
|
return new UnknownCommand(parts[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-08 19:55:30 +02:00
|
|
|
|
static InputCommandBase ParseSendCommand(string arg, bool text)
|
2016-04-24 14:12:33 +02:00
|
|
|
|
{
|
|
|
|
|
ModifierKeys modifiers = ModifierKeys.None;
|
2016-08-08 19:55:30 +02:00
|
|
|
|
var index = 0;
|
|
|
|
|
while (index < arg.Length && !Char.IsDigit(arg[index]) && !Char.IsWhiteSpace(arg[index]))
|
2016-04-24 14:12:33 +02:00
|
|
|
|
{
|
2016-08-08 19:55:30 +02:00
|
|
|
|
switch (arg[index])
|
2016-04-24 14:12:33 +02:00
|
|
|
|
{
|
|
|
|
|
case '^':
|
|
|
|
|
modifiers |= ModifierKeys.Ctrl;
|
|
|
|
|
break;
|
|
|
|
|
case '+':
|
|
|
|
|
modifiers |= ModifierKeys.Shift;
|
|
|
|
|
break;
|
|
|
|
|
case '%':
|
|
|
|
|
modifiers |= ModifierKeys.Alt;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-08 19:55:30 +02:00
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
if (text)
|
|
|
|
|
{
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
if (index >= arg.Length)
|
|
|
|
|
{
|
|
|
|
|
return new NoOpCommand();
|
|
|
|
|
}
|
|
|
|
|
if (text)
|
|
|
|
|
{
|
|
|
|
|
return new SendTextCommand(arg.Substring(index), modifiers);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var key = byte.Parse(arg.Substring(index));
|
|
|
|
|
return new SendKeyCommand(key, modifiers);
|
2016-04-24 14:12:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|