Skip to content
This repository has been archived by the owner on Oct 24, 2021. It is now read-only.

Commit

Permalink
Version 1.4.21
Browse files Browse the repository at this point in the history
Added Presets for Dpad, Left and Right Sticks, Face Buttons, Sixaxis,
and Touchpad Swipes; right click on those controls to select a preset)
Fully fixed Scan code, now will work fine in old DirectX games
Macros for Special Actions can now have scan code enabled (if you didn't
know you can enable scan code on macros for single controls as well,
even after you've configured the macro)
Control list now shows if scan code is enabled
  • Loading branch information
Jays2Kings committed Dec 17, 2014
1 parent 1d31d71 commit f8dd4c6
Show file tree
Hide file tree
Showing 24 changed files with 8,352 additions and 6,490 deletions.
4 changes: 4 additions & 0 deletions DS4Control/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ protected virtual void On_Report(object sender, EventArgs e)
{
if (Global.getFlushHIDQueue(ind))
device.FlushHID();
if (!string.IsNullOrEmpty(device.error))
{
LogDebug(device.error);
}
device.getExposedState(ExposedState[ind], CurrentState[ind]);
DS4State cState = CurrentState[ind];
device.getPreviousState(PreviousState[ind]);
Expand Down
1 change: 1 addition & 0 deletions DS4Control/DS4Control.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
3 changes: 2 additions & 1 deletion DS4Control/InputMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ public static void performKeyPress(ushort key)

public static void performSCKeyRelease(ushort key)
{
Console.WriteLine((System.Windows.Forms.Keys)key);
lock (lockob)
{
sendInputs[0].Type = INPUT_KEYBOARD;
sendInputs[0].Data.Keyboard.ExtraInfo = IntPtr.Zero;
sendInputs[0].Data.Keyboard.Flags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
sendInputs[0].Data.Keyboard.Scan = MapVirtualKey(key, MAPVK_VK_TO_VSC);
sendInputs[0].Data.Keyboard.Time = 0;
sendInputs[0].Data.Keyboard.Vk = key;
//sendInputs[0].Data.Keyboard.Vk = MapVirtualKey(key, MAPVK_VK_TO_VSC);
uint result = SendInput(1, sendInputs, Marshal.SizeOf(sendInputs[0]));
}
}
Expand Down
24 changes: 12 additions & 12 deletions DS4Control/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public static void Commit(int device)
gkp.current = kvp.Value.current;
globalState.keyPresses[kvp.Key] = gkp;
}

if (gkp.current.toggleCount != 0 && gkp.previous.toggleCount == 0 && gkp.current.toggle)
{
if (gkp.current.scanCodeCount != 0)
Expand Down Expand Up @@ -236,7 +235,7 @@ public static void Commit(int device)
}
}
}
else if ((gkp.current.toggleCount == 0 && gkp.previous.toggleCount == 0) && gkp.current.vkCount + gkp.current.scanCodeCount == 0 && gkp.previous.vkCount + gkp.previous.scanCodeCount != 0)
if ((gkp.current.toggleCount == 0 && gkp.previous.toggleCount == 0) && gkp.current.vkCount + gkp.current.scanCodeCount == 0 && gkp.previous.vkCount + gkp.previous.scanCodeCount != 0)
{
if (gkp.previous.scanCodeCount != 0) // use the last type of VK/SC
{
Expand Down Expand Up @@ -421,7 +420,9 @@ public static DS4State SetCurveAndDeadzone(int device, DS4State cState)
public static bool[] pressedonce = new bool[261], macrodone = new bool[34];
public static int test = 0;
static bool[] macroControl = new bool[25];
/** Map DS4 Buttons/Axes to other DS4 Buttons/Axes (largely the same as Xinput ones) and to keyboard and mouse buttons. */
/// <summary>
/// Map DS4 Buttons/Axes to other DS4 Buttons/Axes (largely the same as Xinput ones) and to keyboard and mouse buttons.
/// </summary>
public static async void MapCustom(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState, Mouse tp, Control ctrl)
{
bool shift;
Expand Down Expand Up @@ -1491,6 +1492,7 @@ public static async void MapCustomAction(int device, DS4State cState, DS4State M
{
if (!actionDone[device,index])
{
DS4KeyType keyType = action.keyType;
actionDone[device,index] = true;
foreach (DS4Controls dc in action.trigger)
resetToDefaultValue(dc, MappedState);
Expand Down Expand Up @@ -1532,8 +1534,8 @@ public static async void MapCustomAction(int device, DS4State cState, DS4State M
else if (i == 283) macroControl[22] = true;
else if (i == 284) macroControl[23] = true;
else if (i == 285) macroControl[24] = true;
//else if (keyType.HasFlag(DS4KeyType.ScanCode))
//InputMethods.performSCKeyPress((ushort)i);
else if (keyType.HasFlag(DS4KeyType.ScanCode))
InputMethods.performSCKeyPress((ushort)i);
else
InputMethods.performKeyPress((ushort)i);
keydown[i] = true;
Expand Down Expand Up @@ -1570,8 +1572,8 @@ public static async void MapCustomAction(int device, DS4State cState, DS4State M
else if (i == 283) macroControl[22] = false;
else if (i == 284) macroControl[23] = false;
else if (i == 285) macroControl[24] = false;
//else if (keyType.HasFlag(DS4KeyType.ScanCode))
//InputMethods.performSCKeyRelease((ushort)i);
else if (keyType.HasFlag(DS4KeyType.ScanCode))
InputMethods.performSCKeyRelease((ushort)i);
else
InputMethods.performKeyRelease((ushort)i);
keydown[i] = false;
Expand Down Expand Up @@ -1610,15 +1612,15 @@ public static async void MapCustomAction(int device, DS4State cState, DS4State M
else if (i == 283) macroControl[22] = false;
else if (i == 284) macroControl[23] = false;
else if (i == 285) macroControl[24] = false;
//else if (keyType.HasFlag(DS4KeyType.ScanCode))
//InputMethods.performSCKeyRelease(i);
else if (keyType.HasFlag(DS4KeyType.ScanCode))
InputMethods.performSCKeyRelease(i);
else
InputMethods.performKeyRelease(i);
}
/*if (keyType.HasFlag(DS4KeyType.HoldMacro))
{
await Task.Delay(50);
macrodoneA[index] = false;
actionDone[device,index] = false;
}*/
}
}
Expand Down Expand Up @@ -1839,8 +1841,6 @@ public static byte getByteMapping(int device, DS4Controls control, DS4State cSta

public static bool getBoolMapping(DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
{
//if (control == DS4Controls.Up)
//Cons
switch (control)
{
case DS4Controls.Share: return cState.Share;
Expand Down
52 changes: 36 additions & 16 deletions DS4Control/ScpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ public Boolean SaveProfile(int device, String propath, System.Windows.Forms.Cont
hasvalue = true;
break;
}
if (hasvalue)
if (hasvalue && !string.IsNullOrEmpty(String.Join(",", extras)))
{
XmlNode extraNode = m_Xdoc.CreateNode(XmlNodeType.Element, button.Name, null);
extraNode.InnerText = String.Join(",", extras);
Expand Down Expand Up @@ -1701,9 +1701,12 @@ public Boolean LoadProfile(int device, System.Windows.Forms.Control[] buttons, S
if (UInt16.TryParse(item.InnerText, out wvk))
customMapKeys.Add(getDS4ControlsByName(item.Name), wvk);
ParentItem = m_Xdoc.SelectSingleNode("/" + rootname + "/Control/Extras");
if (ParentItem != null)
if (ParentItem != null)
foreach (XmlNode item in ParentItem.ChildNodes)
customMapExtras.Add(getDS4ControlsByName(item.Name), item.InnerText);
if (item.InnerText != string.Empty)
customMapExtras.Add(getDS4ControlsByName(item.Name), item.InnerText);
else
ParentItem.RemoveChild(item);
ParentItem = m_Xdoc.SelectSingleNode("/" + rootname + "/Control/KeyType");
if (ParentItem != null)
foreach (XmlNode item in ParentItem.ChildNodes)
Expand Down Expand Up @@ -1840,8 +1843,16 @@ public void LoadButtons(System.Windows.Forms.Control[] buttons, string control,
Item = m_Xdoc.SelectSingleNode(String.Format("/" + rootname + "/" + control + "/Extras/{0}", button.Name));
if (Item != null)
{
extras = Item.InnerText;
customMapExtras.Add(getDS4ControlsByName(button.Name), Item.InnerText);
if (Item.InnerText != string.Empty)
{
extras = Item.InnerText;
customMapExtras.Add(getDS4ControlsByName(button.Name), Item.InnerText);
}
else
{
m_Xdoc.RemoveChild(Item);
extras = "0,0,0,0,0,0,0,0";
}
}
else
extras = "0,0,0,0,0,0,0,0";
Expand Down Expand Up @@ -2015,7 +2026,7 @@ private void CreateAction()
m_Xdoc.Save(m_Actions);
}

public bool SaveAction(string name, string controls, int mode, string details, bool edit, string ucontrols = "")
public bool SaveAction(string name, string controls, int mode, string details, bool edit, string extras = "")
{
bool saved = true;
if (!File.Exists(m_Actions))
Expand All @@ -2036,6 +2047,8 @@ public bool SaveAction(string name, string controls, int mode, string details, b
case 1:
el.AppendChild(m_Xdoc.CreateElement("Type")).InnerText = "Macro";
el.AppendChild(m_Xdoc.CreateElement("Details")).InnerText = details;
if (extras != string.Empty)
el.AppendChild(m_Xdoc.CreateElement("Extras")).InnerText = extras;
break;
case 2:
el.AppendChild(m_Xdoc.CreateElement("Type")).InnerText = "Program";
Expand All @@ -2044,7 +2057,7 @@ public bool SaveAction(string name, string controls, int mode, string details, b
case 3:
el.AppendChild(m_Xdoc.CreateElement("Type")).InnerText = "Profile";
el.AppendChild(m_Xdoc.CreateElement("Details")).InnerText = details;
el.AppendChild(m_Xdoc.CreateElement("UnloadTrigger")).InnerText = ucontrols;
el.AppendChild(m_Xdoc.CreateElement("UnloadTrigger")).InnerText = extras;
break;
}
if (edit)
Expand Down Expand Up @@ -2083,7 +2096,7 @@ public bool LoadActions()
XmlDocument doc = new XmlDocument();
doc.Load(Global.appdatapath + "\\Actions.xml");
XmlNodeList actionslist = doc.SelectNodes("Actions/Action");
string name, controls, type, details, ucontrols;
string name, controls, type, details, extras;
foreach (XmlNode x in actionslist)
{
name = x.Attributes["Name"].Value;
Expand All @@ -2092,11 +2105,15 @@ public bool LoadActions()
details = x.ChildNodes[2].InnerText;
if (type == "Profile")
{
ucontrols = x.ChildNodes[3].InnerText;
actions.Add(new SpecialAction(name, controls, type, details, ucontrols));
extras = x.ChildNodes[3].InnerText;
actions.Add(new SpecialAction(name, controls, type, details, extras));
}
else if (type == "Macro")
{
if (x.ChildNodes[3] != null) extras = x.ChildNodes[3].InnerText;
else extras = string.Empty;
actions.Add(new SpecialAction(name, controls, type, details, extras));
}
else
actions.Add(new SpecialAction(name, controls, type, details));
}
}
catch { saved = false; }
Expand All @@ -2114,7 +2131,8 @@ public class SpecialAction
public string details;
public List<DS4Controls> uTrigger = new List<DS4Controls>();
public string ucontrols;
public SpecialAction(string name, string controls, string type, string details, string ucontrols = "")
public DS4KeyType keyType;
public SpecialAction(string name, string controls, string type, string details, string extras = "")
{
this.name = name;
this.type = type;
Expand All @@ -2131,13 +2149,15 @@ public SpecialAction(string name, string controls, string type, string details,
if (int.TryParse(s, out v))
macro.Add(v);
}
if (extras.Contains("Scan Code"))
keyType |= DS4KeyType.ScanCode;
}
else
this.details = details;
if (!string.IsNullOrEmpty(ucontrols))
if (!string.IsNullOrEmpty(extras))
{
this.ucontrols = ucontrols;
string[] uctrls = ucontrols.Split('/');
this.ucontrols = extras;
string[] uctrls = extras.Split('/');
foreach (string s in uctrls)
uTrigger.Add(getDS4ControlsByName(s));
}
Expand Down
Loading

0 comments on commit f8dd4c6

Please sign in to comment.