void SetReport(IXbox360Controller controller, GamepadState state) { PreprocessState(state); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.Up, state.Up); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.Down, state.Down); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.Left, state.Left); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.Right, state.Right); controller.SetAxisValue(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Axis.LeftThumbX, (short)state.LX); controller.SetAxisValue(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Axis.LeftThumbY, (short)state.LY); controller.SetAxisValue(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Axis.RightThumbX, (short)state.RX); controller.SetAxisValue(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Axis.RightThumbY, (short)state.RY); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.A, state.A); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.B, state.B); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.X, state.X); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.Y, state.Y); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.Back, state.Select); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.Start, state.Start); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.LeftShoulder, state.L1); controller.SetSliderValue(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Slider.LeftTrigger, (byte)(state.L2 ? 255 : 0)); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.LeftThumb, state.L3); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.RightShoulder, state.R1); controller.SetSliderValue(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Slider.RightTrigger, (byte)(state.R2 ? 255 : 0)); controller.SetButtonState(Nefarius.ViGEm.Client.Targets.Xbox360.Xbox360Button.RightThumb, state.R3); }
public void DeviceArrived(IDualShockDevice device) { Log.Information("ViGEmNavMergeX360: Device with index {Index} attached", device.DeviceIndex); // Only create virtual 360 controller if one hasn't been created yet if (_target == null) { _target = _client.CreateXbox360Controller(); _target.AutoSubmitReport = false; _target.FeedbackReceived += (sender, args) => { //TODO: Check if needed }; try { Log.Information("ViGEmNavMergeX360: Connecting ViGEm target {Target}", _target); _target.Connect(); Log.Information("ViGEmNavMergeX360: ViGEm target {Target} connected successfully", _target); } catch (Exception ex) { Log.Error("ViGEmNavMergeX360: Failed to connect target {@Target}: {Exception}", _target, ex); } } _deviceCount++; }
public PS3Turntable(UsbDevice dongle, IXbox360Controller newController) { device = dongle; controller = newController; // Thread to constantly read inputs t = new System.Threading.Thread(new System.Threading.ThreadStart(updateRoutine)); t.Start(); controller.Connect(); }
public ViGEmXboxDevice(IXbox360Controller controller) { this.controller = controller; controller.AutoSubmitReport = false; controller.Connect(); SetValueIfNeeded(Xbox360Axis.LeftThumbX, 0.5); SetValueIfNeeded(Xbox360Axis.LeftThumbY, 0.5); SetValueIfNeeded(Xbox360Axis.RightThumbX, 0.5); SetValueIfNeeded(Xbox360Axis.RightThumbY, 0.5); controller.SubmitReport(); }
public override void Disconnect() { if (forceFeedbackCall != null) { cont.FeedbackReceived -= forceFeedbackCall; forceFeedbackCall = null; } connected = false; cont.Disconnect(); cont = null; }
public BaseHIDController(HidDevice device, HidStream stream, ViGEmClient client, int index) { _device = device; _stream = stream; _client = client; _index = index; running = true; target360 = _client.CreateXbox360Controller(); targetDS4 = _client.CreateDualShock4Controller(); target360.AutoSubmitReport = false; targetDS4.AutoSubmitReport = false; }
public override void Disconnect() { foreach (KeyValuePair <int, Xbox360FeedbackReceivedEventHandler> pair in forceFeedbacksDict) { cont.FeedbackReceived -= pair.Value; } forceFeedbacksDict.Clear(); connected = false; cont.Disconnect(); cont = null; }
public JoyHandler() { //Create a new ViGem Client var client = new ViGEmClient(); //create the controller _controller = client.CreateXbox360Controller(); //connect the controller? _controller.Connect(); Thread.Sleep(500); _controller.SetButtonState(Xbox360Button.X, false); }
private static void TryWaitUntilConnected(IXbox360Controller controller) { for (var i = 0; i < 5; i++) { try { var _ = controller.UserIndex; break; } catch (Xbox360UserIndexNotReportedException) { System.Threading.Thread.Sleep(1000); } } }
public ViGEmXboxDevice(IXbox360Controller controller) { this.controller = controller; controller.AutoSubmitReport = false; controller.Connect(); controller.FeedbackReceived += FeedbackReceived; Connected = true; SendInput(new XboxInput { LX = 0.5, LY = 0.5, RX = 0.5, RY = 0.5, }); }
public PS3Guitar(UsbDevice dongle, IXbox360Controller newController) { device = dongle; controller = newController; // Timer to send control packets runTimer = new Timer(10000); runTimer.Elapsed += sendControlPacket; runTimer.Start(); // Thread to constantly read inputs t = new System.Threading.Thread(new System.Threading.ThreadStart(updateRoutine)); t.Start(); controller.Connect(); }
public XboxController() { try { client = new ViGEmClient(); Global.PushMessage(LogLevel.INFO, "Create ViGEmClient..."); controller = client.CreateXbox360Controller(); Global.PushMessage(LogLevel.INFO, "Create vitrual Xbox360 Controller..."); controller.Connect(); Global.PushMessage(LogLevel.INFO, "Connect vitrual Xbox360 Controller..."); } catch (Exception e) { MessageBox.Show(Global.MainForm, String.Format("You must install ViGemBus to use this tool:\nCution! This is a driver-level simulation, which may cause unexpected factors. When you install, please pay attention to the safety and stability of your computer.\n\n{0}\n\nOr this tool cannot create a vitrual xbox controller by ViGemBus.\nPlease try again or report this problems:\n\n{1}\n\nThis program will be close...\n\n{2}", "https://github.com/ViGEm/ViGEmBus", "https://github.com/HaoJun0823/CODEVEIN-Piano-Helper", e.Message), "Error! Unable to initialize device!", MessageBoxButtons.OK, MessageBoxIcon.Error); System.Environment.Exit(0); } }
public MiGamepad(string device, ViGEmClient client) { _Logger.Information("Initializing MiGamepad handler for device {Device}", device); _Device = HidDevices.GetDevice(device); _Device.MonitorDeviceEvents = false; _Target = client.CreateXbox360Controller(); _Target.AutoSubmitReport = false; _Target.FeedbackReceived += Target_OnFeedbackReceived; // TODO mark the threads as background? _InputThread = new Thread(DeviceWorker); _CTS = new CancellationTokenSource(); _VibrationTimer = new Timer(VibrationTimer_Trigger); LedNumber = 0xFF; }
public StadiaController(HidDevice device, HidStream stream, ViGEmClient client, int index) { _device = device; _stream = stream; _client = client; _index = index; running = true; target360 = _client.CreateXbox360Controller(); targetDS4 = _client.CreateDualShock4Controller(); target360.AutoSubmitReport = false; targetDS4.AutoSubmitReport = false; target360.FeedbackReceived += this.Target360_FeedbackReceived; targetDS4.FeedbackReceived += this.TargetDS4_FeedbackReceived; inputThread = new Thread(() => input_thread()); inputThread.Priority = ThreadPriority.AboveNormal; inputThread.Name = "Controller #" + index + " Input"; inputThread.Start(); }
public void DeviceRemoved(IDualShockDevice device) { Log.Information("ViGEmNavMergeX360: Device with index {Index} detached", device.DeviceIndex); // Only remove the virtual 360 controller if we only had one controller left connected if (_deviceCount == 1) { _target.Disconnect(); _target = null; } _deviceCount--; if (device.DeviceIndex == 0) { _Nav0Report = null; } if (device.DeviceIndex == 1) { _Nav1Report = null; } }
public DualSense_Base(IDevice _device) { device = _device; if (!device.IsInitialized) { device.InitializeAsync().Wait(); } if (!device.ConnectedDeviceDefinition.WriteBufferSize.HasValue) { throw new AccessViolationException("Write Buffer Size is null"); } if (!device.ConnectedDeviceDefinition.ReadBufferSize.HasValue) { throw new AccessViolationException("Read Buffer Size is null"); } WriteBufferSize = device.ConnectedDeviceDefinition.WriteBufferSize.Value; ReadBufferSize = device.ConnectedDeviceDefinition.ReadBufferSize.Value; ++_VirtualXboxId; controller = client.CreateXbox360Controller(); controller.Connect(); controller.FeedbackReceived += Controller_FeedbackReceived; new Thread(() => { try { while (true) { RefreshButtonStatus(); Thread.Sleep(RefreshInterval); } }catch (Exception e) { Console.WriteLine($"An error occurs.\n{e.ToString()}\n{e.StackTrace}\n"); } }).Start(); }
public static void Main(string[] args) { Console.Title = "GHL HID Emulator"; UsbDevice guitar = null; bool isPS4 = false; foreach (WinUsbRegistry device in LibUsbDotNet.UsbDevice.AllWinUsbDevices) { // USB\VID_12BA&PID_074B if ((device.Vid == 0x12BA && device.Pid == 0x074B) || (device.Vid == 0x1430 && device.Pid == 0x07BB)) { guitar = device.Device; isPS4 = (device.Pid == 0x07BB); } } if (guitar == null) { Console.WriteLine("Could not find any Guitar Hero Live guitars."); Console.WriteLine("Make sure you are using a PS3/Wii U/PS4 Guitar Hero Live dongle with the WinUSB driver installed."); Console.WriteLine("Press any key to exit..."); Console.ReadKey(true); return; } // Set up Virtual Xbox 360 controller ViGEmClient client; try { client = new ViGEmClient(); } catch (Exception) { Console.WriteLine("Failed to initialise ViGEm Client. Make sure you have the ViGEm bus driver installed."); Console.WriteLine("Press any key to exit..."); Console.ReadKey(true); return; } IXbox360Controller controller = client.CreateXbox360Controller(); controller.Connect(); Console.WriteLine($"Found a Guitar Hero Live guitar!"); var reader = guitar.OpenEndpointReader(ReadEndpointID.Ep01); byte[] readBuffer = new byte[100]; int runner = 0; while (true) { if (runner == 0) { // Send control packet (to enable strumming) byte[] buffer; if (isPS4) { buffer = new byte[9] { 0x30, 0x02, 0x08, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00 } } ; else { buffer = new byte[9] { 0x02, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; int bytesWrote; UsbSetupPacket setupPacket = new UsbSetupPacket(0x21, 0x09, 0x0201, 0x0000, 0x0008); guitar.ControlTransfer(ref setupPacket, buffer, 0x0008, out bytesWrote); } runner++; if (runner > 500) { runner = 0; } int bytesRead; reader.Read(readBuffer, 100, out bytesRead); Console.SetCursorPosition(0, 1); Console.WriteLine("Frets: " + BitConverter.ToString(new byte[] { readBuffer[0] })); Console.WriteLine("Buttons: " + BitConverter.ToString(new byte[] { readBuffer[1] })); Console.WriteLine("Tilt: " + BitConverter.ToString(new byte[] { readBuffer[19] })); Console.WriteLine("Whammy: " + BitConverter.ToString(new byte[] { readBuffer[6] })); Console.WriteLine("Strum: " + (readBuffer[4] == 0x00 || readBuffer[4] == 0xFF) + " "); Console.WriteLine("Raw Data: " + BitConverter.ToString(readBuffer)); byte frets = readBuffer[0]; controller.SetButtonState(Xbox360Button.A, (frets & 0x02) != 0x00); // B1 controller.SetButtonState(Xbox360Button.B, (frets & 0x04) != 0x00); // B2 controller.SetButtonState(Xbox360Button.Y, (frets & 0x08) != 0x00); // B3 controller.SetButtonState(Xbox360Button.X, (frets & 0x01) != 0x00); // W1 controller.SetButtonState(Xbox360Button.LeftShoulder, (frets & 0x10) != 0x00); // W2 controller.SetButtonState(Xbox360Button.RightShoulder, (frets & 0x20) != 0x00); // W3 byte strum = readBuffer[4]; if (strum == 0xFF) { // Strum Down controller.SetButtonState(Xbox360Button.Down, true); controller.SetButtonState(Xbox360Button.Up, false); } else if (strum == 0x00) { // Strum Up controller.SetButtonState(Xbox360Button.Down, false); controller.SetButtonState(Xbox360Button.Up, true); } else { // No Strum controller.SetButtonState(Xbox360Button.Down, false); controller.SetButtonState(Xbox360Button.Up, false); } byte buttons = readBuffer[1]; controller.SetButtonState(Xbox360Button.Start, (buttons & 0x02) != 0x00); // Pause controller.SetButtonState(Xbox360Button.Back, (buttons & 0x01) != 0x00); // Hero Power // ViGEm isn't co-operating here - setting to some weird value causes an issue. //controller.SetAxisValue(Xbox360Axis.RightThumbY, (short)(~readBuffer[6]-128)); //controller.SetAxisValue(Xbox360Axis.RightThumbX, readBuffer[19]); Console.WriteLine("Emulating as Xbox 360 Controller " + (controller.UserIndex + 1)); } } }
public void UpdateController(IXbox360Controller controller) { // Only update controller if it is plugged in. if (IsPlugged) { controller.SetButtonState(Xbox360Button.A, BUTTON_B); // Button layouts on Xbox controllers are swapped from Nintendo layout controller.SetButtonState(Xbox360Button.B, BUTTON_A); controller.SetButtonState(Xbox360Button.X, BUTTON_Y); controller.SetButtonState(Xbox360Button.Y, BUTTON_X); controller.SetButtonState(Xbox360Button.Left, DPAD_LEFT); controller.SetButtonState(Xbox360Button.Right, DPAD_RIGHT); controller.SetButtonState(Xbox360Button.Up, DPAD_UP); controller.SetButtonState(Xbox360Button.Down, DPAD_DOWN); controller.SetButtonState(Xbox360Button.Start, BUTTON_START); // If enabled, the triggers act as digital buttons. if (ApplicationSettings.EnableDigitalPress) { if ((ANALOG_LEFT / 255f) > ApplicationSettings.TriggerDeadzone) { controller.SetButtonState(Xbox360Button.LeftShoulder, true); } else { controller.SetButtonState(Xbox360Button.LeftShoulder, false); } if ((ANALOG_RIGHT / 255f) > ApplicationSettings.TriggerDeadzone) { controller.SetButtonState(Xbox360Button.RightShoulder, true); } else { controller.SetButtonState(Xbox360Button.RightShoulder, false); } if (BUTTON_Z) { controller.SetSliderValue(Xbox360Slider.RightTrigger, 255); } else { controller.SetSliderValue(Xbox360Slider.RightTrigger, 0); } } // Use normal triggerThreshold/deadzone values else { controller.SetSliderValue(Xbox360Slider.LeftTrigger, ANALOG_LEFT); controller.SetSliderValue(Xbox360Slider.RightTrigger, ANALOG_RIGHT); controller.SetButtonState(Xbox360Button.RightShoulder, BUTTON_Z); } // Check if calibration has been done. If not generate it if (_Calibration.CurrentState == CalibrationState.Calibrating) { _Calibration.GenerateCalibrations(); } // Full calibration scales generated if (_Calibration.CurrentState == CalibrationState.Calibrated) { LeftStickX = Math.Round(LEFT_STICK_X * _Calibration.LeftStickCalibration[0] - _Calibration.LeftStickCalibration[2]); LeftStickY = Math.Round(LEFT_STICK_Y * _Calibration.LeftStickCalibration[1] - _Calibration.LeftStickCalibration[3]); CStickX = Math.Round(C_STICK_X * _Calibration.CStickCalibration[0] - _Calibration.CStickCalibration[2]); CStickY = Math.Round(C_STICK_Y * _Calibration.CStickCalibration[1] - _Calibration.CStickCalibration[3]); } // Stick centers generated else if (_Calibration.CurrentState == CalibrationState.SticksCentered) { LeftStickX = LEFT_STICK_X + _Calibration.StickCenters[0]; LeftStickY = LEFT_STICK_Y + _Calibration.StickCenters[1]; CStickX = C_STICK_X + _Calibration.StickCenters[2]; CStickY = C_STICK_Y + _Calibration.StickCenters[3]; } // No calibration done else { LeftStickX = LEFT_STICK_X; LeftStickY = LEFT_STICK_Y; CStickX = C_STICK_X; CStickY = C_STICK_Y; } LeftStickX = Extensions.ByteToShort((byte)Extensions.Clamp(LeftStickX, 0, 255)); // ensure stick values are within byte range LeftStickY = Extensions.ByteToShort((byte)Extensions.Clamp(LeftStickY, 0, 255)); CStickX = Extensions.ByteToShort((byte)Extensions.Clamp(CStickX, 0, 255)); CStickY = Extensions.ByteToShort((byte)Extensions.Clamp(CStickY, 0, 255)); if (GetDeadzone((float)LeftStickX, (float)LeftStickY)) // This means they are within the deadzone, take no input { LeftStickX = 0; LeftStickY = 0; } if (GetDeadzone((float)CStickX, (float)CStickY)) { CStickX = 0; CStickY = 0; } controller.SetAxisValue(Xbox360Axis.LeftThumbX, (short)LeftStickX); controller.SetAxisValue(Xbox360Axis.LeftThumbY, (short)LeftStickY); controller.SetAxisValue(Xbox360Axis.RightThumbX, (short)CStickX); controller.SetAxisValue(Xbox360Axis.RightThumbY, (short)CStickY); controller.FeedbackReceived += Controller_FeedbackReceived; controller.SubmitReport(); } }
public Xbox360OutDevice(ViGEmClient client) { cont = client.CreateXbox360Controller(); cont.AutoSubmitReport = false; }
public virtual bool Report(byte[] input, byte[] output) { byte id = (byte)(input[4] - 1); if (targets.Count <= id || targets[id] == null) { return(false); } IXbox360Controller controller = targets[id]; controller.ResetReport(); if ((input[10] & 32) != 0) { controller.SetButtonState(Xbox360Button.Back, true); } if ((input[10] & 64) != 0) { controller.SetButtonState(Xbox360Button.LeftThumb, true); } if ((input[10] & 128) != 0) { controller.SetButtonState(Xbox360Button.RightThumb, true); } if ((input[10] & 16) != 0) { controller.SetButtonState(Xbox360Button.Start, true); } if ((input[10] & 1) != 0) { controller.SetButtonState(Xbox360Button.Up, true); } if ((input[10] & 2) != 0) { controller.SetButtonState(Xbox360Button.Down, true); } if ((input[10] & 4) != 0) { controller.SetButtonState(Xbox360Button.Left, true); } if ((input[10] & 8) != 0) { controller.SetButtonState(Xbox360Button.Right, true); } if ((input[11] & 1) != 0) { controller.SetButtonState(Xbox360Button.LeftShoulder, true); } if ((input[11] & 2) != 0) { controller.SetButtonState(Xbox360Button.RightShoulder, true); } if ((input[11] & 128) != 0) { controller.SetButtonState(Xbox360Button.Y, true); } if ((input[11] & 32) != 0) { controller.SetButtonState(Xbox360Button.B, true); } if ((input[11] & 16) != 0) { controller.SetButtonState(Xbox360Button.A, true); } if ((input[11] & 64) != 0) { controller.SetButtonState(Xbox360Button.X, true); } if ((input[11] & 4) != 0) { controller.SetButtonState(Xbox360Button.Guide, true); } controller.SetSliderValue(Xbox360Slider.LeftTrigger, input[12]); controller.SetSliderValue(Xbox360Slider.RightTrigger, input[13]); controller.SetAxisValue(Xbox360Axis.LeftThumbX, BitConverter.ToInt16(input, 14)); controller.SetAxisValue(Xbox360Axis.LeftThumbY, BitConverter.ToInt16(input, 16)); controller.SetAxisValue(Xbox360Axis.RightThumbX, BitConverter.ToInt16(input, 18)); controller.SetAxisValue(Xbox360Axis.RightThumbY, BitConverter.ToInt16(input, 20)); controller.SubmitReport(); return(true); }
public iOSGuitar(BluetoothLEDevice guitar, IXbox360Controller newController) { device = guitar; controller = newController; prepareGuitar(); }
public OutputControllerXbox360() { xbox_controller = Program.emClient.CreateXbox360Controller(); Init(); }
static void Main(string[] args) { ViGEmClient client = new ViGEmClient(); IXbox360Controller controller = client.CreateXbox360Controller(); controller.AutoSubmitReport = false; controller.Connect(); using (Host server = new Host()) { server.InitializeServer(6789, 2); Event netEvent; while (true) { bool polled = false; while (!polled) { if (server.CheckEvents(out netEvent) == false) { if (server.Service(15, out netEvent) == false) { break; } polled = true; } switch (netEvent.Type) { case EventType.None: break; case EventType.Connect: Console.WriteLine("Client connected - ID: " + netEvent.ChannelID + ", IP: " + netEvent.Peer.Host); break; case EventType.Disconnect: Console.WriteLine("Client disconnected - ID: " + netEvent.ChannelID + ", IP: " + netEvent.Peer.Host); break; case EventType.Receive: Console.WriteLine("Packet received from - ID: " + netEvent.ChannelID + ", IP: " + netEvent.Peer.Host + ", Channel ID: " + netEvent.ChannelID + ", Data length: " + netEvent.Packet.Length); int t; Console.WriteLine(System.Text.Encoding.Default.GetString(netEvent.Packet.GetBytes())); if (Int32.TryParse(System.Text.Encoding.Default.GetString(netEvent.Packet.GetBytes()), out t)) { bool press = t < 20; if (!keyboard_mode) { if (t % 20 < 14) { controller.SetButtonState(t % 20, press); } else if (t % 20 == 14) { controller.SetSliderValue(Xbox360Slider.LeftTrigger, press ? (byte)0xFF : (byte)0x00); } else if (t % 20 == 15) { controller.SetSliderValue(Xbox360Slider.RightTrigger, press ? (byte)0xFF : (byte)0x00); } controller.SubmitReport(); } else { switch (t % 20) { case 0: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.D4).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.D4).Invoke(); } break; case 1: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.D5).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.D5).Invoke(); } break; case 2: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.D6).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.D6).Invoke(); } break; case 3: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.D7).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.D7).Invoke(); } break; case 4: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.R).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.R).Invoke(); } break; case 5: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.T).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.T).Invoke(); } break; case 6: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.Y).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.Y).Invoke(); } break; case 7: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.U).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.U).Invoke(); } break; case 8: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.F).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.F).Invoke(); } break; case 9: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.G).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.G).Invoke(); } break; case 10: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.H).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.H).Invoke(); } break; case 11: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.J).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.J).Invoke(); } break; case 12: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.V).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.V).Invoke(); } break; case 13: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.B).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.B).Invoke(); } break; case 14: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.N).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.N).Invoke(); } break; case 15: if (press) { WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.M).Invoke(); } else { WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.M).Invoke(); } break; } } } netEvent.Packet.Dispose(); break; } } } server.Flush(); } controller.Disconnect(); }
private XboxControllerAdapter(ViGEmClient client, IXbox360Controller controller) { _client = client; _controller = controller; }
public OutputControllerXbox360(ushort vendor_id, ushort product_id) { xbox_controller = Program.emClient.CreateXbox360Controller(vendor_id, product_id); Init(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); try { client = new ViGEmClient(); controller = client.CreateXbox360Controller(); controller.Connect(); Console.WriteLine("Virtual Xbox360 gamepad connected."); } catch (Exception e) { Console.WriteLine("Could not connect to ViGEmClient\n"); Console.WriteLine(e); Console.WriteLine("\nNote that you need to install ViGemBus for this app to work\n"); Console.Read(); return; } int i = 0; while (true) { // We'll cycle through 8 different stick states i++; i %= 80; int state = i / 10; short amount = Int16.MaxValue / 2; if (i == 0) { controller.SetButtonState(Xbox360Button.A, true); } else { controller.SetButtonState(Xbox360Button.A, false); } if (state == 0) { controller.SetAxisValue(Xbox360Axis.LeftThumbX, amount); } else if (state == 1) { controller.SetAxisValue(Xbox360Axis.LeftThumbX, (short)(-amount)); } else { controller.SetAxisValue(Xbox360Axis.LeftThumbX, 0); } if (state == 2) { controller.SetAxisValue(Xbox360Axis.LeftThumbY, amount); } else if (state == 3) { controller.SetAxisValue(Xbox360Axis.LeftThumbY, (short)(-amount)); } else { controller.SetAxisValue(Xbox360Axis.LeftThumbY, 0); } if (state == 4) { controller.SetAxisValue(Xbox360Axis.RightThumbX, amount); } else if (state == 5) { controller.SetAxisValue(Xbox360Axis.RightThumbX, (short)(-amount)); } else { controller.SetAxisValue(Xbox360Axis.RightThumbX, 0); } if (state == 6) { controller.SetAxisValue(Xbox360Axis.RightThumbY, amount); } else if (state == 7) { controller.SetAxisValue(Xbox360Axis.RightThumbY, (short)(-amount)); } else { controller.SetAxisValue(Xbox360Axis.RightThumbY, 0); } System.Threading.Thread.Sleep(50); } }