示例#1
0
        public static void addButtonToAltTabCommand(StateControllerMapping scm,
                                                    FFXICompanion.Settings.Button controllerButton,
                                                    Settings.Action buttonAction)
        {
            ControllerMapping cm = new ControllerMapping();

            cm.button        = new ControllerButton(controllerButton, buttonAction);
            cm.altTabCommand = new AltTabCommand();
            scm.controllerMappings.Add(cm);
        }
示例#2
0
        public static void addButtonToOneKeyPressAndReleaseMapping(StateControllerMapping scm,
                                                                   FFXICompanion.Settings.Button controllerButton,
                                                                   Settings.Action buttonAction,
                                                                   Settings.Key key)
        {
            ControllerMapping cm = new ControllerMapping();

            cm.button            = new ControllerButton(controllerButton, buttonAction);
            cm.keyPressesCommand = new KeyPressesCommand();
            cm.keyPressesCommand.keyPresses.Add(new KeyPress(key, Settings.Action.PRESSED));
            cm.keyPressesCommand.keyPresses.Add(new KeyPress(key, Settings.Action.RELEASED));
            scm.controllerMappings.Add(cm);
        }
示例#3
0
        public static void addButtonToKeyPressMapping(StateControllerMapping scm,
                                                      FFXICompanion.Settings.Button controllerButton,
                                                      Settings.Action buttonAction,
                                                      Settings.Key key,
                                                      Settings.Action keyPress1)
        {
            ControllerMapping cm = new ControllerMapping();

            cm.button            = new ControllerButton(controllerButton, buttonAction);
            cm.keyPressesCommand = new KeyPressesCommand();
            cm.keyPressesCommand.keyPresses.Add(new KeyPress(key, keyPress1));
            scm.controllerMappings.Add(cm);
        }
示例#4
0
        /// <summary>
        /// Creates an action given the ServiceScope and the action settings.
        /// </summary>
        /// <param name="scope">The service scope.</param>
        /// <param name="actionSettings">The action settings to create the action from.</param>
        /// <returns>Action.IAction.</returns>
        public Action.IAction CreateAction(IServiceScope scope, Settings.Action actionSettings)
        {
            Logger.LogTrace($"Creating {actionSettings.Type} on \"{actionSettings.Name}\" Action");

            var actionFactory = scope.ServiceProvider.GetNamedFactory <IActionFactory>(actionSettings.Type);

            Logger.LogInformation($"Running {actionSettings.Type} on \"{actionSettings.Name}\" Action");
            var action = actionFactory.Create(actionSettings);

            if (action is IInitializable initializable)
            {
                initializable.Initialize();
            }

            return(action);
        }
 /// <summary>
 /// Creates the specified action.
 /// </summary>
 /// <param name="actionSettings">The settings associated with the action.</param>
 /// <returns>Returns an instance of the SyncAction which is an instance of IAction.</returns>
 /// <exception cref="ArgumentNullException">actionSettings
 /// or
 /// settings
 /// or
 /// serviceProvider</exception>
 /// <exception cref="InvalidOperationException">
 /// </exception>
 /// <exception cref="NotImplementedException"></exception>
 public abstract IAction Create(Settings.Action actionSettings);
示例#6
0
        // public static void GetVidPid(string str, ref int vid, ref int pid)
        // {
        //     var matches = Regex.Matches(str, @"VID_(\w{4})&PID_(\w{4})");
        //     if (matches.Count <= 0 || matches[0].Groups.Count <= 1) return;
        //     vid = Convert.ToInt32(matches[0].Groups[1].Value, 16);
        //     pid = Convert.ToInt32(matches[0].Groups[2].Value, 16);
        // }

        public void start()
        {
            // var stroke = new ManagedWrapper.Stroke();
            // stroke.key.code = (ushort)Keys.J;
            // stroke.key.state = (ushort)ManagedWrapper.KeyState.Down;
            // int devId = 1;
            // ManagedWrapper.Send(_deviceContext, devId, ref stroke, 1);

            //use this code to determine keys
            // ManagedWrapper.SetFilter(deviceContext, ManagedWrapper.IsKeyboard, ManagedWrapper.Filter.All);
            // var stroke = new ManagedWrapper.Stroke();
            // int device = 0;
            // while (ManagedWrapper.Receive(deviceContext, device = ManagedWrapper.Wait(deviceContext), ref stroke, 1) > 0)
            // {
            //     if(ManagedWrapper.IsKeyboard(device) > 0) {
            //         Console.WriteLine(stroke.key.code);
            //         if(stroke.key.code == 1)
            //             break;
            //     }
            // }
            // ManagedWrapper.SetFilter(deviceContext, ManagedWrapper.IsKeyboard, ManagedWrapper.Filter.None);

            // var ret = new List<DeviceInfo>();
            for (var i = 1; i < 21; i++)
            {
                var handle = ManagedWrapper.GetHardwareStr(deviceContext, i, 1000);
                if (handle == "")
                {
                    continue;
                }
                // int foundVid = 0, foundPid = 0;
                // GetVidPid(handle, ref foundVid, ref foundPid);
                //if (foundVid == 0 || foundPid == 0) continue;
                // Console.WriteLine(i + " " + handle);
                // ret.Add(new DeviceInfo {Id = i, IsMouse = i > 10, Handle = handle});
            }

            // foreach (var device in ret)
            // {
            //     Console.WriteLine(device);
            // }


            var controllers = new[] { new Controller(), new Controller(UserIndex.One), new Controller(UserIndex.Two), new Controller(UserIndex.Three), new Controller(UserIndex.Four) };

            // Get 1st controller available
            Controller controller = controllers[0];

            foreach (var selectControler in controllers)
            {
                // Console.WriteLine(selectControler);
                if (selectControler.IsConnected)
                {
                    controller = selectControler;
                    break;
                }
            }

            if (controller == null)
            {
                Console.WriteLine("No XInput controller installed");
            }
            else
            {
                Console.WriteLine("KeyMapper loaded");
                // Console.WriteLine("Found a XInput controller available");
                // Console.WriteLine("Press buttons on the controller to display events or escape key to exit... ");

                // Poll events from joystick
                SharpDX.XInput.State      previousControllerState = controller.GetState();
                Dictionary <Button, bool> lastSimpleGamepadState  = determineSimpleButtonState(previousControllerState);

                StateTransition lastState = null;

                while (!ModuleData.getInstance().cancellationToken.IsCancellationRequested)
                {
                    if (controller.IsConnected)
                    {
                        SharpDX.XInput.State controllerState = controller.GetState();
                        if (previousControllerState.PacketNumber != controllerState.PacketNumber)
                        {
                            // Console.WriteLine(controllerState.Gamepad);

                            Dictionary <Button, bool>            simpleGamepadState = determineSimpleButtonState(controllerState);
                            Dictionary <Button, Settings.Action> changedState       = determineStateDifferences(lastSimpleGamepadState, simpleGamepadState);
                            printStateChanges(changedState);
                            // Console.WriteLine(GetActiveWindowTitle());

                            //determine if we are transitioning to a new 'state'
                            //  this is based on the current state, the game state and the keys pressed/not pressed
                            //  NOTE: the first state wins, for speed
                            StateTransition newState = getNewState(simpleGamepadState, ModuleData.getInstance().companionSettings.stateTransitions);
                            if (newState == null && lastState == null)
                            {
                                //nothing to do
                            }
                            else if (newState != null && lastState == null)
                            {
                                activateState(newState);
                            }
                            else if (newState == null && lastState != null)
                            {
                                deactivateState(lastState);
                            }
                            else if (newState != null && lastState != null && !newState.transitionName.Equals(lastState.transitionName))
                            {
                                deactivateState(lastState);
                                activateState(newState);
                            }

                            //now that we have the state name determined, load the correct mappings
                            StateControllerMapping stateControllerMappings = findStateControllerMappings(newState, ModuleData.getInstance().companionSettings.stateMappings);

                            //apply button presses and such
                            foreach (Button key in changedState.Keys)
                            {
                                Settings.Action action = changedState[key];
                                foreach (ControllerMapping controllerMapping in stateControllerMappings.controllerMappings)
                                {
                                    if (controllerMapping.button.button == key && action == controllerMapping.button.action)
                                    {
                                        handleCommand(controllerMapping);
                                    }
                                }
                            }

                            lastState = newState;
                            lastSimpleGamepadState = simpleGamepadState;
                        }
                        Thread.Sleep(10);
                        previousControllerState = controllerState;
                    }
                }
            }
        }