Rev 180 | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WindowsInput.Native;
namespace nitdcscore {
public abstract class Command {
public UInt64 value { get; set; }
public jsdata data { get; set; }
public Command() {
value = 0;
}
public abstract int Send();
public abstract int Send(UInt64 value);
}
public class CommandDCS : Command {
public String cmd { get; set; }
public CommandDCS() : base() {
this.cmd = "";
}
public CommandDCS(String cmd) : base() {
this.cmd = cmd;
}
public override int Send() {
if (this.cmd.Equals(""))
return -1;
return Globals.bios.SendData(this.ToString());
}
public override int Send(UInt64 value) {
if (this.cmd.Equals(""))
return -1;
this.value = value;
Globals.bios.SendData(this.ToString());
return 0;
}
public override string ToString() {
return cmd + " " + base.value + "\n";
}
}
public class CommandDCSMap : Command {
public String cmd { get; set; }
public Dictionary<UInt64, String> map { get; set; }
//public CommandDCSMap(Dictionary<UInt64, String> map) : base() {
// this.cmd = "";
//}
public CommandDCSMap(String cmd, Dictionary<UInt64, String> map) : base() {
this.cmd = cmd;
this.map = map;
}
public override int Send() {
String send;
if (this.map.TryGetValue(this.value, out send))
Globals.bios.SendData(this.ToString());
return 0;
}
public override int Send(UInt64 value) {
this.value = value;
return this.Send();
}
public override string ToString() {
String send;
if (this.map.TryGetValue(this.value, out send))
return cmd + " " + send + "\n";
return cmd + ":" + this.value + " <null>";
}
}
public class CommandVJSAxis : Command {
HID_USAGES axis;
uint id = 0;
public CommandVJSAxis(uint id, HID_USAGES axis) {
this.axis = axis;
this.id = id;
}
public override int Send() {
int newval = (int)this.value;
bool result = Globals.vjoy.SetAxis(newval, this.id, this.axis);
if (result)
return 0;
return 1;
}
public override int Send(UInt64 value) {
this.value = value;
return this.Send();
}
public override string ToString() {
return "VJSAxis:" + id.ToString() + ":" + base.value + "\n";
}
}
public class CommandVKey : Command {
OSInput osi;
OSInput.VirtualKeyCodes key;
public CommandVKey(OSInput.VirtualKeyCodes vkey) : base() {
this.key = vkey;
osi = new OSInput(vkey);
}
public override int Send() {
if (this.value == 1) {
this.osi.Send();
return 0;
}
return 1;
}
public override int Send(UInt64 value) {
this.value = value;
return this.Send();
}
public override string ToString() {
return "VKey:" + key.ToString() + ":" + base.value + "\n";
}
}
public class CommandMouseButton : Command {
public static int MB_LEFT = 1;
public static int MB_RIGHT = 2;
// 1 = Left
// 2 = Right
// 3 = ?
int button = 0;
public CommandMouseButton(int button) : base() {
this.button = button;
}
public override int Send() {
if (button == 0)
return 1;
switch (button) {
case 1:
if (this.value == 1)
Globals.SendKey.Mouse.LeftButtonDown();
else
Globals.SendKey.Mouse.LeftButtonUp();
break;
case 2:
if (this.value == 1)
Globals.SendKey.Mouse.RightButtonDown();
else
Globals.SendKey.Mouse.RightButtonUp();
break;
case 3:
if (this.value == 1)
Globals.SendKey.Mouse.XButtonDown(0);
else
Globals.SendKey.Mouse.XButtonUp(0);
break;
}
return 0;
}
public override int Send(UInt64 value) {
this.value = value;
return this.Send();
}
public override string ToString() {
return "Mouse:" + this.button + "=" + base.value + "\n";
}
}
public class CommandTrackIRKey : Command {
VirtualKeyCode key;
public CommandTrackIRKey(VirtualKeyCode vkey) : base() {
this.key = vkey;
}
public override int Send() {
if (this.value == 1) {
Globals.SendKey.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
Utils.delayms(1);
Globals.SendKey.Keyboard.KeyPress(key);
Globals.SendKey.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
return 0;
}
return 1;
}
public override int Send(UInt64 value) {
this.value = value;
return this.Send();
}
public override string ToString() {
return "TrackIR:" + key.ToString() + ":" + base.value + "\n";
}
}
public class CommandIf : Command {
private Control ctl { get; set; }
private Dictionary<uint, Command> opts;
public CommandIf(Control control, Dictionary<uint, Command> opts) {
this.ctl = control;
this.opts = opts;
}
public override int Send() {
Command cmd;
ctl.data = this.data;
ctl.Tick();
if (opts.TryGetValue((uint)ctl.value, out cmd)) {
cmd.value = this.value;
cmd.data = this.data;
cmd.Send(this.value);
Console.Write(cmd.ToString());
return 0;
}
return 1;
}
public override int Send(UInt64 value) {
this.value = value;
return this.Send();
}
public override string ToString() {
return "";
//return "CommandIf:" + this.value + "\n";
}
}
}