コード例 #1
0
        public KeyboardHandler(BongoManager manager, BongoInputMapping mapping) : base(manager, mapping)
        {
            TranslateMapping(mapping);

            sim = new InputSimulator();

            manager.TopRightPressed += () => sim.Keyboard.KeyDown(topRight);
            manager.BotRightPressed += () => sim.Keyboard.KeyDown(botRight);
            manager.TopLeftPressed  += () => sim.Keyboard.KeyDown(topLeft);
            manager.BotLeftPressed  += () => sim.Keyboard.KeyDown(botLeft);
            manager.MicStarted      += () => sim.Keyboard.KeyDown(mic);
            manager.StartPressed    += () => sim.Keyboard.KeyDown(start);

            manager.TopRightHeld += () => sim.Keyboard.KeyDown(topRight);
            manager.BotRightHeld += () => sim.Keyboard.KeyDown(botRight);
            manager.TopLeftHeld  += () => sim.Keyboard.KeyDown(topLeft);
            manager.BotLeftHeld  += () => sim.Keyboard.KeyDown(botLeft);
            manager.MicHeld      += () => sim.Keyboard.KeyDown(mic);
            manager.StartHeld    += () => sim.Keyboard.KeyDown(start);

            manager.TopRightReleased += () => sim.Keyboard.KeyUp(topRight);
            manager.BotRightReleased += () => sim.Keyboard.KeyUp(botLeft);
            manager.TopLeftReleased  += () => sim.Keyboard.KeyUp(topLeft);
            manager.BotLeftReleased  += () => sim.Keyboard.KeyUp(botLeft);
            manager.MicReleased      += () => sim.Keyboard.KeyUp(mic);
            manager.StartReleased    += () => sim.Keyboard.KeyUp(start);
        }
コード例 #2
0
        public VJoyHandler(BongoManager manager, BongoInputMapping mapping, int id, int mic) : base(manager, mapping)
        {
            joystick = new vJoy();
            uint _id = (uint)id;

            micSensitivity = mic;

            if (id <= 0 | id > 16)
            {
                Program.WriteErrorToConsoleAndExit("Invalid vJoy id");
            }

            if (!joystick.vJoyEnabled())
            {
                Program.WriteErrorToConsoleAndExit("vJoy not enabled");
            }

            if (!joystick.AcquireVJD(_id))
            {
                Program.WriteErrorToConsoleAndExit("Failed to acquire vJoy device");
            }

            TranslateMapping(mapping);

            joystick.ResetVJD(_id);

            manager.TopRightPressed += () => joystick.SetBtn(true, _id, topRight);
            manager.BotRightPressed += () => joystick.SetBtn(true, _id, botRight);
            manager.TopLeftPressed  += () => joystick.SetBtn(true, _id, topLeft);
            manager.BotLeftPressed  += () => joystick.SetBtn(true, _id, botLeft);
            manager.StartPressed    += () => joystick.SetBtn(true, _id, start);

            manager.TopRightReleased += () => joystick.SetBtn(false, _id, topRight);
            manager.BotRightReleased += () => joystick.SetBtn(false, _id, botRight);
            manager.TopLeftReleased  += () => joystick.SetBtn(false, _id, topLeft);
            manager.BotLeftReleased  += () => joystick.SetBtn(false, _id, botLeft);
            manager.StartReleased    += () => joystick.SetBtn(false, _id, start);

            if (micButton == 255)
            {
                manager.MicUpdate += (int update) => joystick.SetAxis(update * micSensitivity, _id, micAxis);
            }
            else
            {
                manager.MicStarted  += () => joystick.SetBtn(true, _id, micButton);
                manager.MicReleased += () => joystick.SetBtn(false, _id, micButton);
            }
        }
コード例 #3
0
 public OutputHandler(BongoManager manager, BongoInputMapping mapping)
 {
 }
コード例 #4
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                WriteErrorToConsoleAndExit("Please specify a config file");
            }

            BongoConfig config = null;

            try
            {
                String json = "";
                using (StreamReader sr = new StreamReader(args[0]))
                {
                    json += sr.ReadToEnd();
                }
                config = JsonConvert.DeserializeObject <BongoConfig>(json);
            }
            catch (IOException)
            {
                WriteErrorToConsoleAndExit("File not found");
            }

            if (config == null)
            {
                WriteErrorToConsoleAndExit("Failed to read config file");
            }

            manager = new BongoManager(config.micThreshold);
            switch (config.output.ToLower().Trim())
            {
            case ("keyboard"):
                handler = new KeyboardHandler(manager, config.keyboardMapping);
                break;

            case ("vjoy"):
                handler = new VJoyHandler(manager, config.vJoyMapping, config.vJoyId, config.micSensitivity);
                break;

            default:
                WriteErrorToConsoleAndExit("Unsupported output method");
                break;
            }

            bongos = HidDevices.Enumerate(config.vendorID, config.productID).FirstOrDefault();
            if (bongos == null)
            {
                WriteErrorToConsoleAndExit("No device found");
            }

            bongos.OpenDevice();
            bongos.Removed += () => WriteErrorToConsoleAndExit("Device disconnected");

            pollRate = config.pollRate;
            polling  = new Thread(PollDevice);
            polling.Start();

            Console.WriteLine($"Beginning bongo translation with method '{config.output}'");
            while (polling.IsAlive)
            {
                Console.ReadKey();
            }
        }