示例#1
0
        bool mapTouchPad(DS4Controls padControl, bool release = false)
        {
            ushort key = Global.getCustomKey(padControl);

            if (key == 0)
            {
                return(false);
            }
            else
            {
                DS4KeyType keyType = Global.getCustomKeyType(padControl);
                if (!release)
                {
                    if (keyType.HasFlag(DS4KeyType.ScanCode))
                    {
                        performSCKeyPress(key);
                    }
                    else
                    {
                        performKeyPress(key);
                    }
                }
                else
                if (!keyType.HasFlag(DS4KeyType.Repeat))
                {
                    if (keyType.HasFlag(DS4KeyType.ScanCode))
                    {
                        performSCKeyRelease(key);
                    }
                    else
                    {
                        performKeyRelease(key);
                    }
                }
                return(true);
            }
        }
示例#2
0
		private static async void PlayMacro(int device, bool[] macrocontrol, string macro, DS4Controls control, DS4KeyType keyType)
		{
			if (macro.StartsWith("164/9/9/164", StringComparison.Ordinal) || macro.StartsWith("18/9/9/18", StringComparison.Ordinal))
			{
				int wait = 1000;
				if (!string.IsNullOrEmpty(macro))
				{
					string[] skeys = macro.Split('/');
					ushort delay;
					if (ushort.TryParse(skeys[skeys.Length - 1], out delay) && (delay > 300))
					{
						wait = delay - 300;
					}
				}
				AltTabSwapping(wait, device);
				if (control != DS4Controls.None)
				{
					macrodone[DS4ControltoInt(control)] = true;
				}
			}
			else
			{
				string[] skeys;
				int[] keys;
				if (!string.IsNullOrEmpty(macro))
				{
					skeys = macro.Split('/');
					keys = new int[skeys.Length];
				}
				else
				{
					skeys = new string[0];
					keys = new int[0];
				}
				for (int i = 0; i < keys.Length; i++)
				{
					keys[i] = int.Parse(skeys[i]);
				}
				bool[] keydown = new bool[286];
				if ((control == DS4Controls.None) || !macrodone[DS4ControltoInt(control)])
				{
					if (control != DS4Controls.None)
					{
						macrodone[DS4ControltoInt(control)] = true;
					}
					foreach (int i in keys)
					{
						if (i >= 1000000000)
						{
							string lb = i.ToString().Substring(1);
							if (i > 1000000000)
							{
								byte r = (byte)(int.Parse(lb[0].ToString()) * 100 + int.Parse(lb[1].ToString()) * 10 + int.Parse(lb[2].ToString()));
								byte g = (byte)(int.Parse(lb[3].ToString()) * 100 + int.Parse(lb[4].ToString()) * 10 + int.Parse(lb[5].ToString()));
								byte b = (byte)(int.Parse(lb[6].ToString()) * 100 + int.Parse(lb[7].ToString()) * 10 + int.Parse(lb[8].ToString()));
								DS4LightBar.forcelight[device] = true;
								DS4LightBar.forcedFlash[device] = 0;
								DS4LightBar.forcedColor[device] = new DS4Color(r, g, b);
							}
							else
							{
								DS4LightBar.forcedFlash[device] = 0;
								DS4LightBar.forcelight[device] = false;
							}
						}
						else if (i >= 1000000)
						{
							DS4Device d = Program.RootHub.DS4Controllers[device];
							string r = i.ToString().Substring(1);
							byte heavy = (byte)(int.Parse(r[0].ToString()) * 100 + int.Parse(r[1].ToString()) * 10 + int.Parse(r[2].ToString()));
							byte light = (byte)(int.Parse(r[3].ToString()) * 100 + int.Parse(r[4].ToString()) * 10 + int.Parse(r[5].ToString()));
							d.SetRumble(light, heavy);
						}
						else if (i >= 300) //ints over 300 used to delay
						{
							await Task.Delay(i - 300);
						}
						else if (!keydown[i])
						{
							switch (i)
							{
								case 256:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_LEFTDOWN); //anything above 255 is not a keyvalue
									break;
								case 257:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_RIGHTDOWN);
									break;
								case 258:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_MIDDLEDOWN);
									break;
								case 259:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONDOWN, 1);
									break;
								case 260:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONDOWN, 2);
									break;
								case 261:
									macroControl[0] = true;
									break;
								case 262:
									macroControl[1] = true;
									break;
								case 263:
									macroControl[2] = true;
									break;
								case 264:
									macroControl[3] = true;
									break;
								case 265:
									macroControl[4] = true;
									break;
								case 266:
									macroControl[5] = true;
									break;
								case 267:
									macroControl[6] = true;
									break;
								case 268:
									macroControl[7] = true;
									break;
								case 269:
									macroControl[8] = true;
									break;
								case 270:
									macroControl[9] = true;
									break;
								case 271:
									macroControl[10] = true;
									break;
								case 272:
									macroControl[11] = true;
									break;
								case 273:
									macroControl[12] = true;
									break;
								case 274:
									macroControl[13] = true;
									break;
								case 275:
									macroControl[14] = true;
									break;
								case 276:
									macroControl[15] = true;
									break;
								case 277:
									macroControl[16] = true;
									break;
								case 278:
									macroControl[17] = true;
									break;
								case 279:
									macroControl[18] = true;
									break;
								case 280:
									macroControl[19] = true;
									break;
								case 281:
									macroControl[20] = true;
									break;
								case 282:
									macroControl[21] = true;
									break;
								case 283:
									macroControl[22] = true;
									break;
								case 284:
									macroControl[23] = true;
									break;
								case 285:
									macroControl[24] = true;
									break;
								default:
									if (keyType.HasFlag(DS4KeyType.ScanCode))
									{
										InputMethods.PerformScKeyPress((ushort)i);
									}
									else
									{
										InputMethods.PerformKeyPress((ushort)i);
									}
									break;
							}
							keydown[i] = true;
						}
						else
						{
							switch (i)
							{
								case 256:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_LEFTUP); //anything above 255 is not a keyvalue
									break;
								case 257:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_RIGHTUP);
									break;
								case 258:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_MIDDLEUP);
									break;
								case 259:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 1);
									break;
								case 260:
									InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 2);
									break;
								case 261:
									macroControl[0] = false;
									break;
								case 262:
									macroControl[1] = false;
									break;
								case 263:
									macroControl[2] = false;
									break;
								case 264:
									macroControl[3] = false;
									break;
								case 265:
									macroControl[4] = false;
									break;
								case 266:
									macroControl[5] = false;
									break;
								case 267:
									macroControl[6] = false;
									break;
								case 268:
									macroControl[7] = false;
									break;
								case 269:
									macroControl[8] = false;
									break;
								case 270:
									macroControl[9] = false;
									break;
								case 271:
									macroControl[10] = false;
									break;
								case 272:
									macroControl[11] = false;
									break;
								case 273:
									macroControl[12] = false;
									break;
								case 274:
									macroControl[13] = false;
									break;
								case 275:
									macroControl[14] = false;
									break;
								case 276:
									macroControl[15] = false;
									break;
								case 277:
									macroControl[16] = false;
									break;
								case 278:
									macroControl[17] = false;
									break;
								case 279:
									macroControl[18] = false;
									break;
								case 280:
									macroControl[19] = false;
									break;
								case 281:
									macroControl[20] = false;
									break;
								case 282:
									macroControl[21] = false;
									break;
								case 283:
									macroControl[22] = false;
									break;
								case 284:
									macroControl[23] = false;
									break;
								case 285:
									macroControl[24] = false;
									break;
								default:
									if (keyType.HasFlag(DS4KeyType.ScanCode))
									{
										InputMethods.PerformScKeyRelease((ushort)i);
									}
									else
									{
										InputMethods.PerformKeyRelease((ushort)i);
									}
									break;
							}
							keydown[i] = false;
						}
					}
					for (ushort i = 0; i < keydown.Length; i++)
					{
						if (!keydown[i])
						{
							continue;
						}

						switch (i)
						{
							case 256:
								InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_LEFTUP); //anything above 255 is not a keyvalue
								break;
							case 257:
								InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_RIGHTUP);
								break;
							case 258:
								InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_MIDDLEUP);
								break;
							case 259:
								InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 1);
								break;
							case 260:
								InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 2);
								break;
							case 261:
								macroControl[0] = false;
								break;
							case 262:
								macroControl[1] = false;
								break;
							case 263:
								macroControl[2] = false;
								break;
							case 264:
								macroControl[3] = false;
								break;
							case 265:
								macroControl[4] = false;
								break;
							case 266:
								macroControl[5] = false;
								break;
							case 267:
								macroControl[6] = false;
								break;
							case 268:
								macroControl[7] = false;
								break;
							case 269:
								macroControl[8] = false;
								break;
							case 270:
								macroControl[9] = false;
								break;
							case 271:
								macroControl[10] = false;
								break;
							case 272:
								macroControl[11] = false;
								break;
							case 273:
								macroControl[12] = false;
								break;
							case 274:
								macroControl[13] = false;
								break;
							case 275:
								macroControl[14] = false;
								break;
							case 276:
								macroControl[15] = false;
								break;
							case 277:
								macroControl[16] = false;
								break;
							case 278:
								macroControl[17] = false;
								break;
							case 279:
								macroControl[18] = false;
								break;
							case 280:
								macroControl[19] = false;
								break;
							case 281:
								macroControl[20] = false;
								break;
							case 282:
								macroControl[21] = false;
								break;
							case 283:
								macroControl[22] = false;
								break;
							case 284:
								macroControl[23] = false;
								break;
							case 285:
								macroControl[24] = false;
								break;
							default:
								if (keyType.HasFlag(DS4KeyType.ScanCode))
								{
									InputMethods.PerformScKeyRelease(i);
								}
								else
								{
									InputMethods.PerformKeyRelease(i);
								}
								break;
						}
					}
					DS4LightBar.forcedFlash[device] = 0;
					DS4LightBar.forcelight[device] = false;
					Program.RootHub.DS4Controllers[device].SetRumble(0, 0);
					if (!keyType.HasFlag(DS4KeyType.HoldMacro))
					{
						return;
					}
					await Task.Delay(50);
					if (control != DS4Controls.None)
					{
						macrodone[DS4ControltoInt(control)] = false;
					}
				}
			}
		}
示例#3
0
        public static void mapButtons(ref DS4State nextState, ref DS4State cState, ref DS4State prevState, Mouse touchpad)
        {
            foreach (KeyValuePair <DS4Controls, ushort> customKey in Global.getCustomKeys())
            {
                DS4KeyType keyType = Global.getCustomKeyType(customKey.Key);
                bool       PrevOn  = getBoolMapping(customKey.Key, prevState);
                if (getBoolMapping(customKey.Key, cState))
                {
                    resetToDefaultValue(customKey.Key, ref cState);
                    if (!PrevOn)
                    {
                        if (keyType.HasFlag(DS4KeyType.ScanCode))
                        {
                            touchpad.performSCKeyPress(customKey.Value);
                        }
                        else
                        {
                            touchpad.performKeyPress(customKey.Value);
                        }
                    }
                    else if (keyType.HasFlag(DS4KeyType.Repeat))
                    {
                        if (keyType.HasFlag(DS4KeyType.ScanCode))
                        {
                            touchpad.performSCKeyPress(customKey.Value);
                        }
                        else
                        {
                            touchpad.performKeyPress(customKey.Value);
                        }
                    }
                }
                else if (PrevOn)
                {
                    if (keyType.HasFlag(DS4KeyType.ScanCode))
                    {
                        touchpad.performSCKeyRelease(customKey.Value);
                    }
                    else
                    {
                        touchpad.performKeyRelease(customKey.Value);
                    }
                }
            }

            bool LX = false, LY = false, RX = false, RY = false;

            nextState.LX = 127;
            nextState.LY = 127;
            nextState.RX = 127;
            nextState.RY = 127;

            foreach (KeyValuePair <DS4Controls, X360Controls> customButton in Global.getCustomButtons())
            {
                bool LXChanged = nextState.LX == 127;
                bool LYChanged = nextState.LY == 127;
                bool RXChanged = nextState.RX == 127;
                bool RYChanged = nextState.RY == 127;
                switch (customButton.Value)
                {
                case X360Controls.A:
                    nextState.Cross = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.B:
                    nextState.Circle = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.X:
                    nextState.Square = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.Y:
                    nextState.Triangle = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.LB:
                    nextState.L1 = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.LS:
                    nextState.L3 = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.RB:
                    nextState.R1 = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.RS:
                    nextState.R3 = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.DpadUp:
                    nextState.DpadUp = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.DpadDown:
                    nextState.DpadDown = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.DpadLeft:
                    nextState.DpadLeft = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.DpadRight:
                    nextState.DpadRight = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.Guide:
                    nextState.PS = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.Back:
                    nextState.Share = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.Start:
                    nextState.Options = getBoolMapping(customButton.Key, cState);
                    break;

                case X360Controls.LXNeg:
                    if (LXChanged)
                    {
                        nextState.LX = getXYAxisMapping(customButton.Key, cState);
                        LX           = true;
                    }
                    break;

                case X360Controls.LYNeg:
                    if (LYChanged)
                    {
                        nextState.LY = getXYAxisMapping(customButton.Key, cState);
                        LY           = true;
                    }
                    break;

                case X360Controls.RXNeg:
                    if (RXChanged)
                    {
                        nextState.RX = getXYAxisMapping(customButton.Key, cState);
                        RX           = true;
                    }
                    break;

                case X360Controls.RYNeg:
                    if (RYChanged)
                    {
                        nextState.RY = getXYAxisMapping(customButton.Key, cState);
                        RY           = true;
                    }
                    break;

                case X360Controls.LXPos:
                    if (LXChanged)
                    {
                        nextState.LX = getXYAxisMapping(customButton.Key, cState, true);
                        LX           = true;
                    }
                    break;

                case X360Controls.LYPos:
                    if (LYChanged)
                    {
                        nextState.LY = getXYAxisMapping(customButton.Key, cState, true);
                        LY           = true;
                    }
                    break;

                case X360Controls.RXPos:
                    if (RXChanged)
                    {
                        nextState.RX = getXYAxisMapping(customButton.Key, cState, true);
                        RX           = true;
                    }
                    break;

                case X360Controls.RYPos:
                    if (RYChanged)
                    {
                        nextState.RY = getXYAxisMapping(customButton.Key, cState, true);
                        RY           = true;
                    }
                    break;

                case X360Controls.LT:
                    nextState.L2 = getByteMapping(customButton.Key, cState);
                    break;

                case X360Controls.RT:
                    nextState.R2 = getByteMapping(customButton.Key, cState);
                    break;

                case X360Controls.LeftMouse:
                    bool PrevOn = getBoolMapping(customButton.Key, prevState);
                    bool CurOn  = getBoolMapping(customButton.Key, cState);
                    if (!PrevOn && CurOn)
                    {
                        touchpad.MouseEvent(Mouse.MOUSEEVENTF_LEFTDOWN);
                    }
                    else if (PrevOn && !CurOn)
                    {
                        touchpad.MouseEvent(Mouse.MOUSEEVENTF_LEFTUP);
                    }
                    break;

                case X360Controls.RightMouse:
                    PrevOn = getBoolMapping(customButton.Key, prevState);
                    CurOn  = getBoolMapping(customButton.Key, cState);
                    if (!PrevOn && CurOn)
                    {
                        touchpad.MouseEvent(Mouse.MOUSEEVENTF_RIGHTDOWN);
                    }
                    else if (PrevOn && !CurOn)
                    {
                        touchpad.MouseEvent(Mouse.MOUSEEVENTF_RIGHTUP);
                    }
                    break;

                case X360Controls.MiddleMouse:
                    PrevOn = getBoolMapping(customButton.Key, prevState);
                    CurOn  = getBoolMapping(customButton.Key, cState);
                    if (!PrevOn && CurOn)
                    {
                        touchpad.MouseEvent(Mouse.MOUSEEVENTF_MIDDLEDOWN);
                    }
                    else if (PrevOn && !CurOn)
                    {
                        touchpad.MouseEvent(Mouse.MOUSEEVENTF_MIDDLEUP);
                    }
                    break;

                case X360Controls.Unbound:
                    resetToDefaultValue(customButton.Key, ref nextState);
                    break;
                }
            }

            if (!LX)
            {
                nextState.LX = cState.LX;
            }
            if (!LY)
            {
                nextState.LY = cState.LY;
            }
            if (!RX)
            {
                nextState.RX = cState.RX;
            }
            if (!RY)
            {
                nextState.RY = cState.RY;
            }
        }