static void Main(string[] args) { Char last_c = '\0'; uint id = 0; string line; DevType type = DevType.vJoy; int hDev = 0; joystick = new vGen(); // Print device' status dev_stat(); // Get type of device Console.WriteLine("\n\nvJoy or vXbox [J/X]?"); ConsoleKeyInfo key = Console.ReadKey(); last_c = Char.ToUpper(key.KeyChar); if (last_c == 'X') { type = DevType.vXbox; } //get device ID Console.WriteLine("\n\nDevice ID [1-16]?"); line = Console.ReadLine(); if (line.Length == 0) { Console.WriteLine("\n\nDevice ID <empty>, exiting?"); return; } id = Convert.ToUInt32(line); // Verify ID if (id < 1) { Console.WriteLine("\n\nDevice ID negative, exiting?"); return; } if ((type == DevType.vXbox) && (id > 4)) { Console.WriteLine("\n\nDevice ID is greater than 4, exiting?"); return; } if ((type == DevType.vJoy) && (id > 16)) { Console.WriteLine("\n\nDevice ID is greater than 16, exiting?"); return; } // Acquire Device and verify joystick.AcquireDev(id, type, ref hDev); dev_stat(); Console.WriteLine("\nHit any key to reliquish device"); Console.ReadKey(); joystick.RelinquishDev(hDev); dev_stat(); Console.WriteLine("\nHit any key to re-acquire device"); Console.ReadKey(); joystick.AcquireDev(id, type, ref hDev); dev_stat(); joystick.GetDevType(hDev, ref type); Console.WriteLine("\nDevice type: " + type.ToString()); dev_axes(hDev); uint nBtn = 0; joystick.GetDevButtonN(hDev, ref nBtn); Console.WriteLine("\nNumber of buttons: " + nBtn.ToString()); uint nHat = 0; joystick.GetDevHatN(hDev, ref nHat); Console.WriteLine("\nNumber of Hats: " + nHat.ToString()); bool go_on = true; do { go_on = SetVal(hDev); } while (go_on); Console.WriteLine("\nHit any key to exit"); Console.ReadKey(); }
private void button1_Click(object sender, EventArgs e) { joystick = new vGen(); insim = new InSim(); insim.Initialized += (o, ec) => { insim.Send(new IS_BTN() { ReqI = 5, L = 40, T = 20, H = 5, W = 40, BStyle = ButtonStyles.ISB_CLICK, ClickID = 66, Text = "Control mode: 0", UCID = 0 }); foreach (var p in paths.paths) { MSL("^3Path: ^7" + p.Name); } DrawClickables(); }; insim.Bind(PacketType.ISP_BTC, (ins, bb) => { var bt = (IS_BTC)bb; if (bt.ClickID == 66) { control = (control + 1) % 2; } else if (bt.ClickID == 67) { initPhase = true; } else if (bt.ClickID >= PATH_CLICKID) { var p = paths.paths[bt.ClickID - PATH_CLICKID]; currentPath = p.Waypoints; MSL("^7Selected path: ^3" + p.Name); initPhase = true; } DrawClickables(); }); insim.Bind(PacketType.ISP_BTT, (ins, bb) => { var bt = (IS_BTT)bb; if (bt.ClickID == 67) { speedmod = int.Parse(bt.Text); MSL("^3Speedmod set to ^7" + speedmod + "%"); } DrawClickables(); }); insim.Initialize(new InSimSettings() { IName = "^7Afto^1Piliet", Host = "127.0.0.1", Port = 29997, Interval = 100, Prefix = '!', Flags = InSimFlags.ISF_LOCAL }); outsim = new OutSim(10000); outsim.TimedOut += (a, b) => { insim.Send(new InSimDotNet.Packets.IS_MSL() { Msg = "TimeOut..", ReqI = 10, Sound = MessageSound.SND_MESSAGE }); }; outsim.PacketReceived += Outsim_PacketReceived; outsim.Connect("127.0.0.1", 30000); joystick.AcquireDev(1, DevType.vJoy, ref hDev); //joystick.SetDevAxis(hDev, 1, (float)100.0); //timer = new System.Timers.Timer(100); //timer.Elapsed += (o, ee) => { // //joystick.SetDevAxis(hDev, 1, (float)DateTime.Now.Millisecond*0.1f); // var cpos = Cursor.Position; // joystick.SetDevAxis(hDev, 1, cpos.X / 19.2f); // joystick.SetDevAxis(hDev, 2, cpos.Y / 10.8f); //}; //timer.Start(); }