Skip to content

Commit

Permalink
#3 proposal 2 (maybe)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingrottin committed Feb 25, 2024
1 parent 241406b commit 78b14f4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 50 deletions.
5 changes: 4 additions & 1 deletion MapTP.App/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@
<Border x:Name="OpCard" Grid.Row="3" Background="#99FFFFFF" Style="{StaticResource BorderRegion}" Effect="{StaticResource EffectShadow2}" Margin="20,20,20,0">
<StackPanel>
<TextBlock HorizontalAlignment="Left" Margin="5,5,5,10" Text="Options" Style="{StaticResource TextBlockTitle}"/>
<Button HorizontalAlignment="Left" Click="OnLaunchInspectorClick">Launch Inspector</Button>
<WrapPanel>
<Button HorizontalAlignment="Left" Click="OnLaunchInspectorClick" Margin="0,0,10,0">Launch Inspector</Button>
<CheckBox x:Name="TurtleBox" IsChecked="{Binding Path=Turtle, Mode=TwoWay}">Turtle mode</CheckBox>
</WrapPanel>
</StackPanel>
</Border>

Expand Down
10 changes: 7 additions & 3 deletions MapTP.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ private void OnWindowCloses(object sender, System.ComponentModel.CancelEventArgs
return;
}


public bool Turtle;
private int nowTipSwitch=0;

/// <summary>
/// This method is for processing touchpad inputs
/// </summary>
Expand All @@ -461,7 +463,6 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
{
InputX = x.X;
InputY = x.Y;

if (started)
{
try
Expand All @@ -478,13 +479,16 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
: (int)Math.Floor((decimal)scey / ScreenSizeY * 65535) )
: (int)Math.Floor((decimal)scsy / ScreenSizeY * 65535) );
mouseProcessor.MoveCursor(X, Y);

if (nowTipSwitch == 1 && x.TipSwitch == 0 && Turtle) mouseProcessor.MouseUp();
if (nowTipSwitch == 0 && x.TipSwitch == 1 && Turtle) mouseProcessor.MouseDown();
}
catch (Exception e)
{
HandyControl.Controls.MessageBox.Show(e.ToString());
}
}
nowTipSwitch = x.TipSwitch;


}
}
Expand Down
2 changes: 1 addition & 1 deletion MapTP.App/MapAreaWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:MapTP.App"
mc:Ignorable="d"
Title="MapAreaWindow" Height="450" Width="800" WindowStyle="None"
AllowsTransparency="True"
AllowsTransparency="True" Topmost="True"
Background="#00ffffff">
<WindowChrome.WindowChrome>
<WindowChrome ResizeBorderThickness="5" x:Name="WindowChrome"></WindowChrome>
Expand Down
12 changes: 1 addition & 11 deletions MapTP.App/MapAreaWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@ namespace MapTP.App
/// </summary>
public partial class MapAreaWindow : Window
{
#region Win32
private const int WS_EX_TRANSPARENT = 0x20;

private const int GWL_EXSTYLE = -20;

[DllImport("user32", EntryPoint = "SetWindowLong")]
private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);

[DllImport("user32", EntryPoint = "GetWindowLong")]
private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);
#endregion


public delegate void SendArea(int scsx, int scsy, int scex, int scey);
public SendArea sendArea;
Expand Down
45 changes: 45 additions & 0 deletions MapTP.App/MouseProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,51 @@ public void MoveCursor(int x, int y)
return;

}

public void MouseDown()
{
INPUT[] _input = new INPUT[1];
_input[0] = new INPUT
{
type = 0, // INPUT_MOUSE
mkhi = new MOUSEKEYBDHARDWAREINPUT
{
mi = new MOUSEINPUT
{
dx = 0,
dy = 0,
mouseData = 0,
dwFlags = 0x0002, // MOUSEEVENTF_LEFTDOWN
time = 0 // Windows will provide this
}
}
};
SendInput((uint)1, _input, Marshal.SizeOf(typeof(INPUT)));
return;
}

public void MouseUp()
{
INPUT[] _input = new INPUT[1];
_input[0] = new INPUT
{
type = 0, // INPUT_MOUSE
mkhi = new MOUSEKEYBDHARDWAREINPUT
{
mi = new MOUSEINPUT
{
dx = 0,
dy = 0,
mouseData = 0,
dwFlags = 0x0004, // MOUSEEVENTF_LEFTUP
time = 0 // Windows will provide this
}
}
};
SendInput((uint)1, _input, Marshal.SizeOf(typeof(INPUT)));
return;
}

public MouseProcessor()
{
}
Expand Down
16 changes: 9 additions & 7 deletions MapTP.App/Touchpad/Contact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,36 @@ public struct TouchpadContact : IEquatable<TouchpadContact>
public int ContactId { get; }
public int X { get; }
public int Y { get; }
public int TipSwitch {get;}

public TouchpadContact(int contactId, int x, int y) =>
(this.ContactId, this.X, this.Y) = (contactId, x, y);
public TouchpadContact(int contactId, int x, int y, int tipSwitch) =>
(this.ContactId, this.X, this.Y, this.TipSwitch) = (contactId, x, y, tipSwitch);

public override bool Equals(object obj) => (obj is TouchpadContact other) && Equals(other);

public bool Equals(TouchpadContact other) =>
(this.ContactId == other.ContactId) && (this.X == other.X) && (this.Y == other.Y);
(this.ContactId == other.ContactId) && (this.X == other.X) && (this.Y == other.Y) && (this.TipSwitch==other.TipSwitch);

public static bool operator ==(TouchpadContact a, TouchpadContact b) => a.Equals(b);
public static bool operator !=(TouchpadContact a, TouchpadContact b) => !(a == b);

public override int GetHashCode() => (this.ContactId, this.X, this.Y).GetHashCode();
public override int GetHashCode() => (this.ContactId, this.X, this.Y, this.TipSwitch).GetHashCode();

public override string ToString() => $"Contact ID:{ContactId} Point:{X},{Y}";
public override string ToString() => $"Contact ID:{ContactId} Point:{X},{Y} Tip Switch:{TipSwitch}";
}

internal class TouchpadContactCreator
{
public int? ContactId { get; set; }
public int? X { get; set; }
public int? Y { get; set; }
public int? TipSwitch { get; set; }

public bool TryCreate(out TouchpadContact contact)
{
if (ContactId.HasValue && X.HasValue && Y.HasValue)
if (ContactId.HasValue && X.HasValue && Y.HasValue && TipSwitch.HasValue)
{
contact = new TouchpadContact(ContactId.Value, X.Value, Y.Value);
contact = new TouchpadContact(ContactId.Value, X.Value, Y.Value, TipSwitch.Value);
return true;
}
contact = default;
Expand Down
31 changes: 4 additions & 27 deletions MapTP.App/Touchpad/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,6 @@ public static TouchpadContact[] ParseInput(IntPtr lParam)
switch (valueCap.LinkCollection)
{
case 0:
/*
switch (valueCap.UsagePage, valueCap.Usage)
{
case (0x0D, 0x56): // Scan Time
scanTime = value;
break;
case (0x0D, 0x54): // Contact Count
contactCount = value;
break;
}*/
if (valueCap.UsagePage == 0x0D)
{
switch (valueCap.Usage)
Expand All @@ -235,21 +224,6 @@ public static TouchpadContact[] ParseInput(IntPtr lParam)
break;

default:
/*
switch (valueCap.UsagePage, valueCap.Usage)
{
case (0x0D, 0x51): // Contact ID
creator.ContactId = (int)value;
break;
case (0x01, 0x30): // X
creator.X = (int)value;
break;
case (0x01, 0x31): // Y
creator.Y = (int)value;
break;
}*/
if (valueCap.UsagePage == 0x0D)
{
if (valueCap.Usage == 0x51)
Expand All @@ -268,7 +242,10 @@ public static TouchpadContact[] ParseInput(IntPtr lParam)
creator.Y = (int)value;
break;
}
}
}else if(valueCap.UsagePage == 0x09 && valueCap.Usage == 0x42)
{
creator.TipSwitch = (int)value;
}
break;
}

Expand Down

0 comments on commit 78b14f4

Please sign in to comment.