From 706070656c083f8f5e8d29e138c765e30ddbb394 Mon Sep 17 00:00:00 2001 From: uberhalit Date: Sun, 5 Feb 2017 18:14:42 +0100 Subject: [PATCH] Added TapMode --- CitraTouchControl/App.config | 3 + CitraTouchControl/GlobalVars.cs | 1 + CitraTouchControl/MainWindow.xaml.cs | 63 ++++++++-------- CitraTouchControl/MenuWindow.xaml | 18 ++--- CitraTouchControl/MenuWindow.xaml.cs | 31 ++++++-- .../Properties/Settings.Designer.cs | 12 ++++ .../Properties/Settings.settings | 3 + README.md | 71 +++++++++++++++++++ 8 files changed, 154 insertions(+), 48 deletions(-) create mode 100644 README.md diff --git a/CitraTouchControl/App.config b/CitraTouchControl/App.config index f9f6abd..f216d88 100644 --- a/CitraTouchControl/App.config +++ b/CitraTouchControl/App.config @@ -55,6 +55,9 @@ 50 + + False + diff --git a/CitraTouchControl/GlobalVars.cs b/CitraTouchControl/GlobalVars.cs index cc55900..dffae86 100644 --- a/CitraTouchControl/GlobalVars.cs +++ b/CitraTouchControl/GlobalVars.cs @@ -19,5 +19,6 @@ class GlobalVars internal static bool IsTouchEnabled = false; internal static bool AreControlsHidden = false; internal static int KeyPressDuration = 50; + internal static bool IsTapOnly = false; } } diff --git a/CitraTouchControl/MainWindow.xaml.cs b/CitraTouchControl/MainWindow.xaml.cs index 23f20bb..345db43 100644 --- a/CitraTouchControl/MainWindow.xaml.cs +++ b/CitraTouchControl/MainWindow.xaml.cs @@ -72,6 +72,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e) GlobalVars.AreControlsHidden = true; ToggleControls(true); } + GlobalVars.IsTapOnly = Properties.Settings.Default.IsTapOnly; GlobalVars.KeyPressDuration = Properties.Settings.Default.KeyPressDuration; } @@ -88,6 +89,9 @@ private void controlButton_TouchDown(object sender, TouchEventArgs e) /// private void controlButton_TouchUp(object sender, TouchEventArgs e) { + // ignore TouchUp in TapOnly mode + if (GlobalVars.IsTapOnly) + return; e.Handled = true; ControlButtonUp(sender); } @@ -97,6 +101,9 @@ private void controlButton_TouchUp(object sender, TouchEventArgs e) /// private void controlButton_TouchLeave(object sender, TouchEventArgs e) { + // ignore TouchLeave in TapOnly mode + if (GlobalVars.IsTapOnly) + return; ControlButtonUp(sender); } @@ -140,16 +147,24 @@ private void ControlButtonDown(object sender) // actually send keydown SendMessage(citraMainControlHwnd, WM_KEYDOWN, key, IntPtr.Zero); - // add pressed key to list - if (!pressedControls.Contains(key)) - pressedControls.Add(key); + // if TapMode is tap only then send KeyUp directly + if (GlobalVars.IsTapOnly) + { + SendButtonUp(key); + } + else + { + // add pressed key to list + if (!pressedControls.Contains(key)) + pressedControls.Add(key); + } } /// /// Control leave handler which supports asynchronous waiting. /// /// The caller UI element. - private async void ControlButtonUp(object sender) + private void ControlButtonUp(object sender) { // get calling button var button = (sender as System.Windows.Controls.Image); @@ -165,6 +180,15 @@ private async void ControlButtonUp(object sender) return; pressedControls.Remove(key); + SendButtonUp(key); + } + + /// + /// Sends a KeyButtonUp after a short delay. + /// + /// The IntPtr of the key. + private async void SendButtonUp(IntPtr key) + { // wait 50ms asynchronously, then send keyup of selected button await Task.Delay(GlobalVars.KeyPressDuration); SendMessage(citraMainControlHwnd, WM_KEYUP, key, IntPtr.Zero); @@ -332,37 +356,6 @@ private struct RECT #region UNUSED /* - private const int WS_EX_TRANSPARENT = 0x00000020; - private const int GWL_EXSTYLE = (-20); - - [DllImport("user32.dll")] - private static extern Int32 GetWindowLong(IntPtr hwnd, int index); - - [DllImport("user32.dll")] - private static extern Int32 SetWindowLong(IntPtr hwnd, int index, int newStyle); - - public static void SetWindowExTransparent(IntPtr hwnd) - { - var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); - SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT); - } - - public static void SetWindowExNormal(IntPtr hwnd) - { - var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); - SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle & ~WS_EX_TRANSPARENT); - } - - /// - /// Make window clickthrough and hittest invisible. - /// - protected override void OnSourceInitialized(EventArgs e) - { - base.OnSourceInitialized(e); - var hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle; - SetWindowExTransparent(hwnd); - } - /// /// Uses FindWindowEx() to recursively search for a child window with the given class and/or title. /// diff --git a/CitraTouchControl/MenuWindow.xaml b/CitraTouchControl/MenuWindow.xaml index af1a799..5970ecb 100644 --- a/CitraTouchControl/MenuWindow.xaml +++ b/CitraTouchControl/MenuWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:CitraTouchControl" mc:Ignorable="d" - Title="CitraTouchControl - Menu" Height="450" Width="400" Topmost="True" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow" Background="LightGray" Loaded="Window_Loaded" Closing="Window_Closing"> + Title="CitraTouchControl - Menu" Height="475" Width="400" Topmost="True" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow" Background="LightGray" Loaded="Window_Loaded" Closing="Window_Closing"> @@ -20,15 +20,17 @@ + -