Esempio n. 1
0
        static void Main()
        {
            // set up our Config Tool broadcast message receiver
            ConfigToolMessageFilter cfgToolFilter = new ConfigToolMessageFilter();

            // set up our mailbox monitor thread
            mailslotThread = new MailslotThread();
            mailslotThread.Start();

            // log startup
            Log.Prune(10 * 1024);
            Log.Info("======================================================================");
            Log.Info("PinVol starting up at " + DateTime.Now.ToString());

            // launch the main window
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new UIWin());

            // shut down the mailslot server thread
            mailslotThread.Shutdown();

            // log shutdown
            Log.Info("Exiting at " + DateTime.Now.ToString());

            // clean up DirectInput resources
            JoystickDev.Cleanup();
        }
Esempio n. 2
0
            public String ToString(bool includeMods = true)
            {
                // check the type
                if (this.jsGuid != Guid.Empty)
                {
                    // joystick button
                    JoystickDev dev    = JoystickDev.FromGuid(jsGuid);
                    String      jsName = dev != null ? dev.UnitName : "[Missing Joystick] ";
                    return(jsName + " button " + (jsButton + 1));
                }
                else
                {
                    // keyboard key

                    // build the modifier list
                    String mod = "";
                    if (includeMods)
                    {
                        if (shift)
                        {
                            mod += "Shift+";
                        }
                        if (control)
                        {
                            mod += "Ctrl+";
                        }
                        if (alt)
                        {
                            mod += "Alt+";
                        }
                        if (windows)
                        {
                            mod += "Windows+";
                        }
                    }

                    // Get the key name.  Translate "Dn" keys to just "n".  These are
                    // the ordinary digit keys.  The C# enum names have to add the "D"
                    // prefix to make them valid identifiers for the enum, but we don't
                    // need them or want them in our user-visible representation.
                    String keyname = key.ToString();
                    Match  m       = Regex.Match(keyname, @"^D(\d)$");
                    if (m.Success)
                    {
                        keyname = m.Groups[1].Value;
                    }

                    // the full name is the modifier list plus the key name
                    return(mod + keyname);
                }
            }
Esempio n. 3
0
        // Rescan joysticks.  This can be called after a new joystick has been
        // plugged in, or just on spec that one might have.  We'll run the system
        // discovery scan again, and add new entries to our internal list for any
        // joysticks not already in the list.
        public static void Rescan()
        {
            // log scans for debugging purposes?
            bool log = false;

            if (log)
            {
                Log.Info("Scanning for USB devices");
            }

            // get the list of attached joysticks
            var devices = directInput.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly);
            int unitNo  = joysticks.Count + 1;

            foreach (var dev in devices)
            {
                // if this device is already in our list, there's nothing to do
                if (joysticks.ContainsKey(dev.InstanceGuid))
                {
                    continue;
                }

                // check USB usage to see if it's a joystick
                bool isJoystick = (dev.UsagePage == SharpDX.Multimedia.UsagePage.Generic &&
                                   dev.Usage == SharpDX.Multimedia.UsageId.GenericJoystick);

                // check if it's a gamepad
                bool isGamepad = (dev.UsagePage == SharpDX.Multimedia.UsagePage.Generic &&
                                  dev.Usage == SharpDX.Multimedia.UsageId.GenericGamepad);

                // note the product name for logging purposes
                String productName = dev.ProductName.TrimEnd('\0');

                // log it if desired
                if (log)
                {
                    Log.Info((isJoystick ? "  Found joystick: " : isGamepad ? "  Found gamepad: " : "  Found non-joystick device: ")
                             + productName
                             + ", DirectInput type=" + dev.Type + "/" + dev.Subtype
                             + ", USB usage=" + (int)dev.UsagePage + "." + (int)dev.Usage);
                }

                // skip devices that aren't joysticks or gamepads
                if (!isJoystick && !isGamepad)
                {
                    continue;
                }

                // initialize it
                try
                {
                    // create the instance and add it to our list
                    Joystick    js    = new Joystick(directInput, dev.InstanceGuid);
                    JoystickDev jsdev = new JoystickDev(unitNo++, js, dev.InstanceGuid);
                    joysticks[dev.InstanceGuid] = jsdev;

                    // request non-exclusive background access
                    js.SetCooperativeLevel(win.Handle, CooperativeLevel.NonExclusive | CooperativeLevel.Background);

                    // Set up an input monitor thread for the joystick.  Note that the
                    // DX API requires this to be done before we call 'Acquire'.
                    js.SetNotification(jsdev.hWait);

                    // connect to the joystick
                    js.Acquire();

                    // Start the monitor thread.  Note that we have to do this after
                    // calling 'Acquire', since the thread will want to read state.
                    jsdev.thread = new Thread(jsdev.JoystickThreadMain);
                    jsdev.thread.Start();
                }
                catch (Exception ex)
                {
                    Log.Error("  !!! Error initializing joystick device " + productName + ": " + ex.Message);
                }
            }
        }