Advertisement
Guest User

connect

a guest
Nov 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. using SharpDX.DirectInput;
  7.  
  8. namespace UPJoystick
  9. {
  10.     static class Program
  11.     {
  12.         /// <summary>
  13.         /// Główny punkt wejścia dla aplikacji.
  14.         /// </summary>
  15.         [STAThread]
  16.         static void Main()
  17.         {
  18.             Application.EnableVisualStyles();
  19.             Application.SetCompatibleTextRenderingDefault(false);
  20.             MainWindow mainWindow = new MainWindow(GetJoystick());
  21.             Application.Run(mainWindow);
  22.         }
  23.  
  24.         static Joystick GetJoystick()
  25.         {
  26.             DirectInput directInput = new DirectInput();
  27.  
  28.             List<Guid> joysticksList = new List<Guid>();
  29.             List<DeviceType> types = new List<DeviceType>();
  30.             Guid joystickGuid = Guid.Empty;
  31.  
  32.  
  33.             foreach (DeviceInstance device in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices))
  34.             {
  35.                 types.Add(device.Type);
  36.                 joysticksList.Add(device.InstanceGuid);
  37.             }
  38.             //jakis wybor trzeba zrobic
  39.             if(joysticksList.Any())
  40.             {
  41.                 joystickGuid = joysticksList.ElementAt(0);
  42.             }
  43.  
  44.             Joystick joystick = null;
  45.  
  46.             if (joystickGuid != Guid.Empty)
  47.             {
  48.                joystick  = new Joystick(directInput, joystickGuid);
  49.             }
  50.  
  51.             return joystick;
  52.  
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement