From 5c87cb14952fc92d7b274117f5cb67b9ecef66f3 Mon Sep 17 00:00:00 2001 From: Maxime Cauvin Date: Fri, 16 Mar 2018 16:03:15 +0100 Subject: [PATCH 01/24] TabletButtonHandling(feat): New editing button control window implemented --- TabletDriverGUI/ButtonMapping.xaml | 40 +++++++++ TabletDriverGUI/ButtonMapping.xaml.cs | 119 +++++++++++++++++++++++++ TabletDriverGUI/Configuration.cs | 6 +- TabletDriverGUI/MainWindow.xaml | 25 +----- TabletDriverGUI/MainWindow.xaml.cs | 75 +++++----------- TabletDriverGUI/TabletDriverGUI.csproj | 7 ++ TabletDriverGUI/WacomArea.xaml | 2 +- 7 files changed, 197 insertions(+), 77 deletions(-) create mode 100644 TabletDriverGUI/ButtonMapping.xaml create mode 100644 TabletDriverGUI/ButtonMapping.xaml.cs diff --git a/TabletDriverGUI/ButtonMapping.xaml b/TabletDriverGUI/ButtonMapping.xaml new file mode 100644 index 0000000..afac361 --- /dev/null +++ b/TabletDriverGUI/ButtonMapping.xaml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + Run at Windows startup + @@ -457,8 +519,8 @@ - - 0.0.0 + + 0.0.0 diff --git a/TabletDriverGUI/MainWindow.xaml.cs b/TabletDriverGUI/MainWindow.xaml.cs index 159b219..089182b 100644 --- a/TabletDriverGUI/MainWindow.xaml.cs +++ b/TabletDriverGUI/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Win32; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -160,6 +161,10 @@ public MainWindow() }; timerConsoleUpdate.Tick += TimerConsoleUpdate_Tick; + // Tooltip timeout + ToolTipService.ShowDurationProperty.OverrideMetadata( + typeof(DependencyObject), new FrameworkPropertyMetadata(60000)); + // // Buttom Map ComboBoxes @@ -167,9 +172,9 @@ public MainWindow() comboBoxButton1.Items.Clear(); comboBoxButton2.Items.Clear(); comboBoxButton3.Items.Clear(); - comboBoxButton1.Items.Add("Disabled"); - comboBoxButton2.Items.Add("Disabled"); - comboBoxButton3.Items.Add("Disabled"); + comboBoxButton1.Items.Add("Disable"); + comboBoxButton2.Items.Add("Disable"); + comboBoxButton3.Items.Add("Disable"); for (int i = 1; i <= 5; i++) { comboBoxButton1.Items.Add("Mouse " + i); @@ -191,6 +196,8 @@ public MainWindow() } comboBoxFilterRate.SelectedIndex = 2; + // Process command line arguments + ProcessCommandLineArguments(); // Events Closing += MainWindow_Closing; @@ -259,14 +266,50 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e) // Load settings from configuration LoadSettingsFromConfiguration(); - // + // Update the settings back to the configuration UpdateSettingsToConfiguration(); + // Console timer timerConsoleUpdate.Start(); + // Set run at startup + SetRunAtStartup(config.RunAtStartup); + + // Hide the window if the GUI is started as minimized + if (WindowState == WindowState.Minimized) + { + Hide(); + } + + // Start the driver Start(); } + + // + // Process command line arguments + // + void ProcessCommandLineArguments() + { + string[] args = Environment.GetCommandLineArgs(); + for (int i = 0; i < args.Length; i++) + { + // Skip values + if (!args[i].StartsWith("-") && !args[i].StartsWith("/")) continue; + + // Remove '-' and '/' characters at the start of the argument + string parameter = Regex.Replace(args[i], "^[\\-/]+", "").ToLower(); + + // + // Parameter: --hide + // + if (parameter == "hide") + { + WindowState = WindowState.Minimized; + } + } + } + #endregion @@ -453,6 +496,10 @@ private void LoadSettingsFromConfiguration() } + // Run at startup + checkRunAtStartup.IsChecked = config.RunAtStartup; + + // // Custom commands // @@ -485,6 +532,8 @@ private void UpdateSettingsToConfiguration() if (isLoadingSettings) return; + bool oldValue; + // Tablet area if (ParseNumber(textTabletAreaWidth.Text, out double value)) config.TabletArea.Width = value; @@ -588,6 +637,14 @@ private void UpdateSettingsToConfiguration() comboBoxFilterRate.IsEnabled = false; } + // + // Run at startup + // + oldValue = config.RunAtStartup; + config.RunAtStartup = (bool)checkRunAtStartup.IsChecked; + if (config.RunAtStartup != oldValue) + SetRunAtStartup(config.RunAtStartup); + // Custom commands List commandList = new List(); @@ -608,7 +665,6 @@ private void UpdateSettingsToConfiguration() } - // // String to Number // @@ -636,6 +692,28 @@ private string GetNumberString(double value, string format) } + // + // Set run at startup + // + private void SetRunAtStartup(bool enabled) + { + try + { + string path = System.Reflection.Assembly.GetExecutingAssembly().Location; + string entryName = "TabletDriverGUI"; + RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); + if (enabled) + rk.SetValue(entryName, "\"" + path + "\" --hide"); + else + rk.DeleteValue(entryName, false); + + rk.Close(); + } + catch (Exception) + { + } + } + // // Get desktop size // @@ -1049,7 +1127,7 @@ private void Canvas_MouseMove(object sender, MouseEventArgs e) if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) dx = 0; - if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.LeftCtrl)) + if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) dy = 0; // Screen map canvas @@ -1168,8 +1246,11 @@ private void ItemSelectionChanged(object sender, SelectionChangedEventArgs e) private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e) { if (!IsLoaded || isLoadingSettings) return; - config.WindowWidth = (int)e.NewSize.Width; - config.WindowHeight = (int)e.NewSize.Height; + if (WindowState != WindowState.Maximized) + { + config.WindowWidth = (int)e.NewSize.Width; + config.WindowHeight = (int)e.NewSize.Height; + } } // Monitor combobox clicked -> create new monitor list @@ -1293,7 +1374,7 @@ private void SetStatusWarning(string text) timerStatusbar.Stop(); timerStatusbar.Start(); } - + // // Statusbar warning text click From 632e3fea916076e50c35d2dc8e200b09d3f69d11 Mon Sep 17 00:00:00 2001 From: hawku Date: Mon, 19 Mar 2018 20:21:53 +0200 Subject: [PATCH 18/24] v0.1.0 --- README.md | 21 ++++++++++++++++++--- TabletDriverGUI/MainWindow.xaml.cs | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1c26c19..c0361f5 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,26 @@ # TabletDriver +This is a low latency graphics tablet driver that is meant to be used with rhythm game [osu!](https://osu.ppy.sh/home) + Currently the driver only works when the TabletDriverGUI is running. The GUI minimizes to system tray / notification area. You can reopen the GUI by double clicking the system tray icon. +**If you have problems with the driver, please read the FAQ:** + +**https://github.com/hawku/TabletDriver/wiki/FAQ** + ## Download -### http://hwk.fi/TabletDriver/TabletDriverV0.0.18.zip +### http://hwk.fi/TabletDriver/TabletDriverV0.1.0.zip -**If you have problems with the driver, please read the FAQ:** +# -**https://github.com/hawku/TabletDriver/wiki/FAQ** +### Supported operating systems: + - Windows 7 64-bit + - Windows 8 64-bit + - Windows 8.1 64-bit + - Windows 10 64-bit # @@ -74,6 +84,11 @@ If you want to compile the code and don't want to install anything from the Tabl ### Changelog +>**v0.1.0:** +> - Added `Bench` / `Benchmark` command. +> - Added `-hide` GUI command line parameter. GUI will start as minimized when you run `TabletDriverGUI.exe -hide` +> - Added an option to run the TabletDriverGUI at Windows startup. + >**v0.0.18:** > - Added TabletDriverService.exe multi-instance prevention. > - Added yet another Wacom 490 tip click fix. diff --git a/TabletDriverGUI/MainWindow.xaml.cs b/TabletDriverGUI/MainWindow.xaml.cs index 089182b..0fe8ee7 100644 --- a/TabletDriverGUI/MainWindow.xaml.cs +++ b/TabletDriverGUI/MainWindow.xaml.cs @@ -24,7 +24,7 @@ public partial class MainWindow : Window { // Version - public string Version = "0.0.18"; + public string Version = "0.1.0"; // Console stuff private List commandHistory; From 143d16e6d9595e67c5424ee9caff4c4dc21267d7 Mon Sep 17 00:00:00 2001 From: hawku Date: Tue, 20 Mar 2018 12:11:35 +0200 Subject: [PATCH 19/24] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c0361f5..b899b37 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,10 @@ The GUI minimizes to system tray / notification area. You can reopen the GUI by ### Install 1. You might need to install these libraries, but usually these are already installed: -* https://aka.ms/vs/15/release/vc_redist.x86.exe -* https://aka.ms/vs/15/release/vc_redist.x64.exe -* https://www.microsoft.com/en-us/download/details.aspx?id=53587 (x64 and x86) + * https://www.microsoft.com/net/download/dotnet-framework-runtime + * https://aka.ms/vs/15/release/vc_redist.x86.exe + * https://aka.ms/vs/15/release/vc_redist.x64.exe + * https://www.microsoft.com/en-us/download/details.aspx?id=53587 (x64 and x86) 2. Unzip the driver to a folder (Shorter path is recommended, for example C:\Temp\TabletDriver) 3. Uninstall all other tablet drivers. From 3b413ac087c1ef2db66b640ae0295907bc81e9d9 Mon Sep 17 00:00:00 2001 From: hawku Date: Tue, 20 Mar 2018 13:44:51 +0200 Subject: [PATCH 20/24] Update README.md --- README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b899b37..d7acb0f 100644 --- a/README.md +++ b/README.md @@ -50,28 +50,30 @@ The GUI minimizes to system tray / notification area. You can reopen the GUI by # -### Install +## Installation 1. You might need to install these libraries, but usually these are already installed: * https://www.microsoft.com/net/download/dotnet-framework-runtime * https://aka.ms/vs/15/release/vc_redist.x86.exe - * https://aka.ms/vs/15/release/vc_redist.x64.exe - * https://www.microsoft.com/en-us/download/details.aspx?id=53587 (x64 and x86) -2. Unzip the driver to a folder (Shorter path is recommended, for example C:\Temp\TabletDriver) +2. Unzip the driver to a folder (Shorter path is recommended, for example `C:\Temp\TabletDriver`) 3. Uninstall all other tablet drivers. -4. Run "install_vmulti_driver.bat". It might need a restart if there is another vmulti driver installed. -5. If you have Huion or Gaomon tablet, you need to run "install_huion_64.bat", which is located at the "driver_huion" directory. +4. Run `install_vmulti_driver.bat`. It might need a restart if there is another vmulti driver installed. +5. If you have Huion or Gaomon tablet, you need to run `install_huion_64.bat`, which is in the `driver_huion` directory. 6. Start the TabletDriverGUI.exe +## Updating to a new version +1. Unzip the new version +2. Start the TabletDriverGUI.exe -### Uninstall -1. Run "remove_vmulti_driver.bat" -2. Run "remove_huion_64.bat", which is located at the "driver_huion" directory. +## Uninstallation +1. Uncheck the "Run at Windows startup" option in the GUI. +2. Run `remove_vmulti_driver.bat` +3. Run `remove_huion_64.bat`, which is in the `driver_huion` directory. # -### VMulti and Huion drivers +## VMulti and Huion driver binaries If you want to compile the code and don't want to install anything from the TabletDriver binary package, you will need extract the missing drivers from these installation packages: @@ -83,7 +85,7 @@ If you want to compile the code and don't want to install anything from the Tabl # -### Changelog +## Changelog >**v0.1.0:** > - Added `Bench` / `Benchmark` command. From 50d6405f23a72bc0a289dbe7ad3202465f1f580e Mon Sep 17 00:00:00 2001 From: Maxime Cauvin Date: Tue, 20 Mar 2018 17:44:45 +0100 Subject: [PATCH 21/24] TabletButtonHandling(feat): First approach sending shortcut macro --- TabletDriverGUI/ButtonMapping.xaml.cs | 8 +++++-- TabletDriverGUI/ShortcutMapWindow.xaml.cs | 26 ++++++++--------------- TabletDriverService/Main.cpp | 10 +++++++++ TabletDriverService/ProcessCommand.cpp | 21 ++++++++++++++++++ TabletDriverService/Tablet.cpp | 15 +++++++++++-- TabletDriverService/Tablet.h | 1 + 6 files changed, 60 insertions(+), 21 deletions(-) diff --git a/TabletDriverGUI/ButtonMapping.xaml.cs b/TabletDriverGUI/ButtonMapping.xaml.cs index b96d36c..f733fd2 100644 --- a/TabletDriverGUI/ButtonMapping.xaml.cs +++ b/TabletDriverGUI/ButtonMapping.xaml.cs @@ -26,7 +26,7 @@ public enum ButtonActionEnum : uint }; /// - /// Logique d'interaction pour ButtonMapping.xaml + /// Interaction logic for ButtonMapping.xaml /// public partial class ButtonMapping : Window { @@ -179,7 +179,11 @@ private void PromptShortcutWindow(object sender) if (shortcutMapWindow.DialogResult == true) { - + Console.WriteLine(shortcutMapWindow.PressedKey.ToString()); + for (var i = 0; i < shortcutMapWindow.ModifierKey.Count; ++i) + { + Console.WriteLine(shortcutMapWindow.ModifierKey[i].ToString()); + } } shortcutMapWindow.Close(); diff --git a/TabletDriverGUI/ShortcutMapWindow.xaml.cs b/TabletDriverGUI/ShortcutMapWindow.xaml.cs index 1840d9d..392f2e8 100644 --- a/TabletDriverGUI/ShortcutMapWindow.xaml.cs +++ b/TabletDriverGUI/ShortcutMapWindow.xaml.cs @@ -8,8 +8,6 @@ using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; -using WindowsInput.Native; -using WindowsInput; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; @@ -26,22 +24,26 @@ public partial class ShortcutMapWindow : Window [DllImport("User32.Dll", EntryPoint = "PostMessageA")] private static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam); - public Key PressedKey; + public List ModifierKey; + public Key PressedKey; public ShortcutMapWindow() { + ModifierKey = new List(); InitializeComponent(); } private void Window_KeyDown(object sender, KeyEventArgs e) { - PressedKey = e.Key; + ModifierKey.Clear(); e.Handled = true; // Fetch the actual shortcut key. Key key = (e.Key == Key.System ? e.SystemKey : e.Key); + PressedKey = key; + // Ignore modifier keys. if (key == Key.LeftShift || key == Key.RightShift || key == Key.LeftCtrl || key == Key.RightCtrl @@ -55,14 +57,17 @@ private void Window_KeyDown(object sender, KeyEventArgs e) StringBuilder shortcutText = new StringBuilder(); if ((Keyboard.Modifiers & ModifierKeys.Control) != 0) { + ModifierKey.Add(ModifierKeys.Control); shortcutText.Append("Ctrl+"); } if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0) { + ModifierKey.Add(ModifierKeys.Shift); shortcutText.Append("Shift+"); } if ((Keyboard.Modifiers & ModifierKeys.Alt) != 0) { + ModifierKey.Add(ModifierKeys.Alt); shortcutText.Append("Alt+"); } shortcutText.Append(key.ToString()); @@ -78,19 +83,6 @@ private void ButtonSet_Click(object sender, RoutedEventArgs e) private void ButtonCancel_Click(object sender, RoutedEventArgs e) { DialogResult = false; - //Process[] processes = Process.GetProcesses(); - //foreach (Process proc in processes) - //{ - // const uint WM_KEYDOWN = 0x0100; - // PostMessage(proc.MainWindowHandle, WM_KEYDOWN, 0xBE, 0); - // PostMessage(proc.MainWindowHandle, WM_KEYDOWN, 0x63, 0); - //SetForegroundWindow(proc.MainWindowHandle); - //System.Windows.Forms.SendKeys.SendWait("(.3)"); - //} - - //InputSimulator inputSimulator = new InputSimulator(); - //inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.MENU, VirtualKeyCode.F4); - //System.Windows.Forms.SendKeys.SendWait("(%{F4})"); } } } diff --git a/TabletDriverService/Main.cpp b/TabletDriverService/Main.cpp index 2de742b..c47a613 100644 --- a/TabletDriverService/Main.cpp +++ b/TabletDriverService/Main.cpp @@ -23,6 +23,7 @@ Tablet *tablet; VMulti *vmulti; ScreenMapper *mapper; thread *tabletThread; +thread *tabletButtonThread; // // Init console parameters @@ -161,6 +162,13 @@ void RunTabletThread() { } +void RunTabletButtonThread() { + while (true) + { + + } +} + // // Tablet filter timer callback // @@ -249,6 +257,7 @@ int main(int argc, char**argv) { vmulti = NULL; tablet = NULL; tabletThread = NULL; + tabletButtonThread = NULL; // Init console InitConsole(); @@ -352,6 +361,7 @@ int main(int argc, char**argv) { // Start the tablet thread tabletThread = new thread(RunTabletThread); + tabletButtonThread = new thread(RunTabletButtonThread); LOG_INFO("TabletDriver started!\n"); LOG_INFO("Tablet: %s\n", tablet->name.c_str()); diff --git a/TabletDriverService/ProcessCommand.cpp b/TabletDriverService/ProcessCommand.cpp index 8631a6f..530e578 100644 --- a/TabletDriverService/ProcessCommand.cpp +++ b/TabletDriverService/ProcessCommand.cpp @@ -276,6 +276,27 @@ bool ProcessCommand(CommandLine *cmd) { } + + // + // Tablet buttons macro + // + else if (cmd->is("TabletMacro") && cmd->valueCount == 2) { + if (!CheckTablet()) return true; + int indexToBeAssigned = cmd->GetInt(0, -1); + string macroToBeAssigned = cmd->GetString(1, "undefined"); + + if (indexToBeAssigned != -1 && macroToBeAssigned != "undefined") + { + tablet->buttonTabletMap[indexToBeAssigned] = macroToBeAssigned; + LOG_INFO("Set the macro '%s' to the tablet button [%d]", macroToBeAssigned, indexToBeAssigned); + } + else + { + LOG_INFO("Invalid command for TabletMacro, try this instead: TabletMacro index_to_modify macro_to_assign"); + } + } + + // Screen Map Area else if(cmd->is("ScreenArea") || cmd->is("Screen")) { if(!CheckTablet()) return true; diff --git a/TabletDriverService/Tablet.cpp b/TabletDriverService/Tablet.cpp index 8c8b365..8186696 100644 --- a/TabletDriverService/Tablet.cpp +++ b/TabletDriverService/Tablet.cpp @@ -26,12 +26,21 @@ Tablet::Tablet(string usbGUID, int stringId, string stringMatch) : Tablet() { Tablet::Tablet(USHORT vendorId, USHORT productId, USHORT usagePage, USHORT usage) : Tablet() { //_construct(); hidDevice = new HIDDevice(vendorId, productId, usagePage, usage); - if(hidDevice->isOpen) { + if (hidDevice->isOpen) { this->isOpen = true; - } else { + } + else { delete hidDevice; hidDevice = NULL; } + hidDevice2 = new HIDDevice(vendorId, productId, usagePage, usage); + if (hidDevice2->isOpen) { + this->isOpen = true; + } + else { + delete hidDevice2; + hidDevice2 = NULL; + } } // @@ -83,6 +92,7 @@ Tablet::Tablet() { // Button map memset(&buttonMap, 0, sizeof(buttonMap)); + memset(&buttonTabletMap, 0, sizeof(buttonTabletMap)); buttonMap[0] = 1; buttonMap[1] = 2; buttonMap[2] = 3; @@ -345,6 +355,7 @@ void Tablet::CloseDevice() { usbDevice->CloseDevice(); } else if(hidDevice != NULL) { hidDevice->CloseDevice(); + hidDevice2->CloseDevice(); } } isOpen = false; diff --git a/TabletDriverService/Tablet.h b/TabletDriverService/Tablet.h index 71082b8..9fcd05b 100644 --- a/TabletDriverService/Tablet.h +++ b/TabletDriverService/Tablet.h @@ -90,6 +90,7 @@ class Tablet { // Button map BYTE buttonMap[16]; + string buttonTabletMap[16]; // string name = "Unknown"; From 1c6ca87656d5854925e1ee6926f41dff31bf8602 Mon Sep 17 00:00:00 2001 From: Maxime Cauvin Date: Wed, 21 Mar 2018 22:42:54 +0100 Subject: [PATCH 22/24] TabletButtonHandling(feat): GUI part done + sending correct informations to the driver --- TabletDriverGUI/ButtonMapping.xaml.cs | 64 +++++++--- TabletDriverGUI/Configuration.cs | 5 +- TabletDriverGUI/MacroButton.cs | 26 ++++ TabletDriverGUI/MainWindow.xaml.cs | 115 +++++++++++++++++- TabletDriverGUI/ShortcutMapWindow.xaml.cs | 3 - TabletDriverGUI/TabletDriverGUI.csproj | 1 + TabletDriverService/ProcessCommand.cpp | 34 ++++-- TabletDriverService/ProcessCommand.h | 1 + TabletDriverService/Tablet.cpp | 1 - TabletDriverService/Tablet.h | 3 +- .../TabletDriverService.vcxproj | 2 + .../TabletDriverService.vcxproj.filters | 6 + TabletDriverService/Utils.cpp | 44 +++++++ TabletDriverService/Utils.h | 19 +++ 14 files changed, 283 insertions(+), 41 deletions(-) create mode 100644 TabletDriverGUI/MacroButton.cs create mode 100644 TabletDriverService/Utils.cpp create mode 100644 TabletDriverService/Utils.h diff --git a/TabletDriverGUI/ButtonMapping.xaml.cs b/TabletDriverGUI/ButtonMapping.xaml.cs index f733fd2..2bf1fd9 100644 --- a/TabletDriverGUI/ButtonMapping.xaml.cs +++ b/TabletDriverGUI/ButtonMapping.xaml.cs @@ -31,6 +31,7 @@ public enum ButtonActionEnum : uint public partial class ButtonMapping : Window { private Dictionary NbTabletButtonsMap; + public Dictionary MacroButtonMap; public ButtonMapping(Configuration config, string tabletName) { @@ -48,12 +49,17 @@ public ButtonMapping(Configuration config, string tabletName) { "Huion H640P", 6 }, { "Gaomon S56K", 0 }, }; + MacroButtonMap = new Dictionary(); - //if (tabletName != null && NbTabletButtonsMap.ContainsKey(tabletName)) - //{ + if (tabletName != null && NbTabletButtonsMap.ContainsKey(tabletName)) + { InitializeComponent(); - //for (var i = 0; i < NbTabletButtonsMap[tabletName]; ++i) - for (var i = 0; i < 4; ++i) + + PenTipComboBox.DropDownClosed += new EventHandler(PromptShortcutWindowEvent); + PenBottomComboBox.DropDownClosed += new EventHandler(PromptShortcutWindowEvent); + PenTopComboBox.DropDownClosed += new EventHandler(PromptShortcutWindowEvent); + + for (var i = 0; i < NbTabletButtonsMap[tabletName]; ++i) { ComboBox cb = new ComboBox { @@ -114,22 +120,28 @@ public ButtonMapping(Configuration config, string tabletName) // // Buttons // - if (config.ButtonMap.Count() == 3) + PenTipComboBox.SelectedIndex = config.ButtonMap[0]; + PenBottomComboBox.SelectedIndex = config.ButtonMap[1]; + PenTopComboBox.SelectedIndex = config.ButtonMap[2]; + + for (var i = 0; i < NbTabletButtonsMap[tabletName]; ++i) { - PenTipComboBox.SelectedIndex = config.ButtonMap[0]; - PenBottomComboBox.SelectedIndex = config.ButtonMap[1]; - PenTopComboBox.SelectedIndex = config.ButtonMap[2]; + for (var j = 0; j < TabletButtonsContainer.Children.Count && j + 3 < config.ButtonMap.Length; ++j) + { + var gb = TabletButtonsContainer.Children[j] as GroupBox; + var cb = gb.Content as ComboBox; + + cb.SelectedIndex = config.ButtonMap[3 + j]; + } } - else - config.ButtonMap = new int[] { 1, 2, 3 }; CheckBoxDisablePenButtons.IsChecked = config.DisablePenButtons; CheckBoxDisableTabletButtons.IsChecked = config.DisableTabletButtons; - //} - //else - //{ - // throw new TabletNotRecognizedException("Tablet not recognized"); - //} + } + else + { + throw new TabletNotRecognizedException("Tablet not recognized"); + } } private void ButtonSet_Click(object sender, RoutedEventArgs e) @@ -179,12 +191,26 @@ private void PromptShortcutWindow(object sender) if (shortcutMapWindow.DialogResult == true) { - Console.WriteLine(shortcutMapWindow.PressedKey.ToString()); + int idx = -1; + if (cb.Name == "PenTipComboBox") + idx = 0; + else if (cb.Name == "PenBottomComboBox") + idx = 1; + else if (cb.Name == "PenTopComboBox") + idx = 2; + else + idx = Int32.Parse(cb.Name.Remove(0, 12)) + 2; + List l = new List(); + for (var i = 0; i < shortcutMapWindow.ModifierKey.Count; ++i) - { - Console.WriteLine(shortcutMapWindow.ModifierKey[i].ToString()); - } + l.Add((int)shortcutMapWindow.ModifierKey[i]); + l.Add((int)shortcutMapWindow.PressedKey); + if (shortcutMapWindow.PressedKey == Key.None) + cb.SelectedIndex = (int)ButtonActionEnum.DISABLED; + MacroButtonMap[idx] = l.ToArray(); } + else + cb.SelectedIndex = (int)ButtonActionEnum.DISABLED; shortcutMapWindow.Close(); } diff --git a/TabletDriverGUI/Configuration.cs b/TabletDriverGUI/Configuration.cs index 3767447..e278377 100644 --- a/TabletDriverGUI/Configuration.cs +++ b/TabletDriverGUI/Configuration.cs @@ -4,6 +4,7 @@ using System.IO; using System.Xml; using System.Xml.Serialization; +using System.Collections.Generic; namespace TabletDriverGUI { @@ -35,6 +36,7 @@ public enum OutputModes [XmlArray("ButtonMap")] [XmlArrayItem("Button")] public int[] ButtonMap; + public MacroButton[] MacroButtonMap; public bool DisablePenButtons; public bool DisableTabletButtons; @@ -73,7 +75,8 @@ public Configuration() DesktopSize = new Area(0, 0, 0, 0); AutomaticDesktopSize = true; - ButtonMap = new int[] { 1, 2, 3 }; + ButtonMap = new int[] { 1, 2, 3, 0, 0, 0, 0, 0, 0 }; + MacroButtonMap = new MacroButton[] { }; DisablePenButtons = false; DisableTabletButtons = false; diff --git a/TabletDriverGUI/MacroButton.cs b/TabletDriverGUI/MacroButton.cs new file mode 100644 index 0000000..cc410a5 --- /dev/null +++ b/TabletDriverGUI/MacroButton.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace TabletDriverGUI +{ + //[XmlType("MacroButton")] + public class MacroButton + { + public int Index; + [XmlArray("MacroKeys")] + [XmlArrayItem("Key")] + public int[] MacroKeys; + + public MacroButton() { } + + public MacroButton(int index, int[] macroKeys) + { + Index = index; + MacroKeys = macroKeys; + } + } +} diff --git a/TabletDriverGUI/MainWindow.xaml.cs b/TabletDriverGUI/MainWindow.xaml.cs index 4310505..41d2467 100644 --- a/TabletDriverGUI/MainWindow.xaml.cs +++ b/TabletDriverGUI/MainWindow.xaml.cs @@ -1168,13 +1168,14 @@ private void SaveSettings(object sender, RoutedEventArgs e) SendSettingsToDriver(); SetStatus("Settings saved!"); } - catch (Exception) + catch (Exception ex) { string dir = Directory.GetCurrentDirectory(); MessageBox.Show("Error occured while saving the configuration.\n" + "Make sure that it is possible to create and edit files in the '" + dir + "' directory.\n", "ERROR!", MessageBoxButton.OK, MessageBoxImage.Error ); + Console.WriteLine(ex.Message); } } @@ -1285,6 +1286,20 @@ private void TimerRestart_Tick(object sender, EventArgs e) // private void ParseDriverMessage(string line) { + Dictionary NbTabletButtonsMap = new Dictionary() + { + { "Wacom CTL-470", 0 }, + { "Wacom CTL-471", 0 }, + { "Wacom CTL-472", 0 }, + { "Wacom CTL-480", 4 }, + { "Wacom CTH-480", 4 }, + { "Wacom CTL-490", 4 }, + { "XP Pen G430", 0 }, + { "XP Pen G640", 0 }, + { "Huion 420", 0 }, + { "Huion H640P", 6 }, + { "Gaomon S56K", 0 }, + }; // // Tablet Name @@ -1401,11 +1416,28 @@ private void SendSettingsToDriver() // Button map if (config.DisablePenButtons) { - driver.SendCommand("ButtonMap 0 0 0"); + string cmd = "ButtonMap 0 0 0 " + String.Join(" ", config.ButtonMap, 3, 6); + driver.SendCommand(cmd); + if (config.MacroButtonMap.Length != 0) + { + cmd = "TabletMacro " + string.Join(";", config.MacroButtonMap.Select(t => string.Format("{0},{1}", t.Index, string.Join(",", t.MacroKeys)))); + driver.SendCommand(cmd); + } + } + else if (config.DisableTabletButtons) + { + string cmd = String.Join(" ", config.ButtonMap, 0, 3) + " 0 0 0 0 0 0"; + driver.SendCommand(cmd); } else { - driver.SendCommand("ButtonMap " + String.Join(" ", config.ButtonMap)); + string cmd = "ButtonMap " + String.Join(" ", config.ButtonMap); + driver.SendCommand(cmd); + if (config.MacroButtonMap.Length != 0) + { + cmd = "TabletMacro " + string.Join(";", config.MacroButtonMap.Select(t => string.Format("{0},{1}", t.Index, string.Join(",", t.MacroKeys)))); + driver.SendCommand(cmd); + } } // Filter @@ -1689,9 +1721,80 @@ private void EditButtonMapping_Click(object sender, RoutedEventArgs e) if (bm.DialogResult == true) { - config.ButtonMap[0] = bm.PenTipComboBox.SelectedIndex; - config.ButtonMap[1] = bm.PenBottomComboBox.SelectedIndex; - config.ButtonMap[2] = bm.PenTopComboBox.SelectedIndex; + List macroButtonsToRemove = new List(); + for (var i = 0; i < 3; ++i) + { + if (config.ButtonMap[i] != 6) + macroButtonsToRemove.Add(i); + + if (bm.MacroButtonMap.ContainsKey(i) && bm.MacroButtonMap[i].Length == 1 && bm.MacroButtonMap[i][0] == 0) + bm.MacroButtonMap.Remove(i); + else + { + switch (i) + { + case 0: + config.ButtonMap[i] = bm.PenTipComboBox.SelectedIndex; + break; + case 1: + config.ButtonMap[i] = bm.PenBottomComboBox.SelectedIndex; + break; + case 2: + config.ButtonMap[i] = bm.PenTopComboBox.SelectedIndex; + break; + } + } + } + + for (var i = 0; i < bm.TabletButtonsContainer.Children.Count; ++i) + { + var gb = bm.TabletButtonsContainer.Children[i] as GroupBox; + var cb = gb.Content as ComboBox; + + + if (cb.SelectedIndex != 6) + macroButtonsToRemove.Add(i + 3); + + if (bm.MacroButtonMap.ContainsKey(i + 3) && bm.MacroButtonMap[i + 3].Length == 1 && bm.MacroButtonMap[i + 3][0] == 0) + bm.MacroButtonMap.Remove(i + 3); + else + config.ButtonMap[i + 3] = cb.SelectedIndex; + } + + //Delete removed or empty MacroButtons + var macroButtonList = config.MacroButtonMap.ToList(); + for (var i = 0; i < macroButtonsToRemove.Count; ++i) + { + for (var j = 0; j < macroButtonList.Count; ++j) + { + if (macroButtonsToRemove[i] == macroButtonList[j].Index) + { + macroButtonList.RemoveAt(j); + break; + } + } + } + config.MacroButtonMap = macroButtonList.ToArray(); + + //Concat new results into the local configuration + foreach (var item in bm.MacroButtonMap) + { + bool added = false; + for (var i = 0; i < config.MacroButtonMap.Length && !added; ++i) + { + if (config.MacroButtonMap[i].Index == item.Key) + { + config.MacroButtonMap[i].MacroKeys = item.Value; + added = true; + } + } + if (!added) + { + var list = config.MacroButtonMap.ToList(); + list.Add(new MacroButton(item.Key, item.Value)); + config.MacroButtonMap = list.ToArray(); + } + } config.DisablePenButtons = bm.CheckBoxDisablePenButtons.IsChecked ?? false; config.DisableTabletButtons = bm.CheckBoxDisableTabletButtons.IsChecked ?? false; diff --git a/TabletDriverGUI/ShortcutMapWindow.xaml.cs b/TabletDriverGUI/ShortcutMapWindow.xaml.cs index 392f2e8..4c9411c 100644 --- a/TabletDriverGUI/ShortcutMapWindow.xaml.cs +++ b/TabletDriverGUI/ShortcutMapWindow.xaml.cs @@ -21,9 +21,6 @@ namespace TabletDriverGUI /// public partial class ShortcutMapWindow : Window { - [DllImport("User32.Dll", EntryPoint = "PostMessageA")] - private static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam); - public List ModifierKey; public Key PressedKey; diff --git a/TabletDriverGUI/TabletDriverGUI.csproj b/TabletDriverGUI/TabletDriverGUI.csproj index 89f8583..523c13e 100644 --- a/TabletDriverGUI/TabletDriverGUI.csproj +++ b/TabletDriverGUI/TabletDriverGUI.csproj @@ -80,6 +80,7 @@ ButtonMapping.xaml + ShortcutMapWindow.xaml diff --git a/TabletDriverService/ProcessCommand.cpp b/TabletDriverService/ProcessCommand.cpp index 530e578..52e3a2e 100644 --- a/TabletDriverService/ProcessCommand.cpp +++ b/TabletDriverService/ProcessCommand.cpp @@ -280,20 +280,34 @@ bool ProcessCommand(CommandLine *cmd) { // // Tablet buttons macro // - else if (cmd->is("TabletMacro") && cmd->valueCount == 2) { + else if (cmd->is("TabletMacro")) { + //LOG_INFO("is equal before check: %d\n", cmd->is("TabletMacro")); + //LOG_INFO("cmd->command is: %s\n", cmd->command); if (!CheckTablet()) return true; - int indexToBeAssigned = cmd->GetInt(0, -1); - string macroToBeAssigned = cmd->GetString(1, "undefined"); - - if (indexToBeAssigned != -1 && macroToBeAssigned != "undefined") + if (true) { - tablet->buttonTabletMap[indexToBeAssigned] = macroToBeAssigned; - LOG_INFO("Set the macro '%s' to the tablet button [%d]", macroToBeAssigned, indexToBeAssigned); + std::vector tempSplit = Utils::split(cmd->line.substr(12).c_str(), ';'); + std::vector> tabletMacros; + + for (auto &it : tempSplit) + tabletMacros.push_back(Utils::split(it, ',')); + + for (auto &it : tabletMacros) + { + std::vector keysMacro; + + for (int i = 0; i < it.size(); ++i) + { + if (i != 0) + keysMacro.push_back(std::stoi(it[i])); + } + + tablet->buttonTabletMap[std::stoi(it[0])] = keysMacro; + LOG_INFO("Set the macro to the button [%d]\n", std::stoi(it[0])); + } } else - { - LOG_INFO("Invalid command for TabletMacro, try this instead: TabletMacro index_to_modify macro_to_assign"); - } + LOG_INFO("Invalid command for TabletMacro, try this instead: TabletMacro macro_string\n"); } diff --git a/TabletDriverService/ProcessCommand.h b/TabletDriverService/ProcessCommand.h index d08308c..493d173 100644 --- a/TabletDriverService/ProcessCommand.h +++ b/TabletDriverService/ProcessCommand.h @@ -1,5 +1,6 @@ #pragma once #include "CommandLine.h" +#include "Utils.h" bool ProcessCommand(CommandLine *cmd); bool ReadCommandFile(string filename); diff --git a/TabletDriverService/Tablet.cpp b/TabletDriverService/Tablet.cpp index 8186696..97c5fc0 100644 --- a/TabletDriverService/Tablet.cpp +++ b/TabletDriverService/Tablet.cpp @@ -92,7 +92,6 @@ Tablet::Tablet() { // Button map memset(&buttonMap, 0, sizeof(buttonMap)); - memset(&buttonTabletMap, 0, sizeof(buttonTabletMap)); buttonMap[0] = 1; buttonMap[1] = 2; buttonMap[2] = 3; diff --git a/TabletDriverService/Tablet.h b/TabletDriverService/Tablet.h index 9fcd05b..6ac81eb 100644 --- a/TabletDriverService/Tablet.h +++ b/TabletDriverService/Tablet.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "USBDevice.h" #include "HIDDevice.h" @@ -90,7 +91,7 @@ class Tablet { // Button map BYTE buttonMap[16]; - string buttonTabletMap[16]; + std::unordered_map> buttonTabletMap; // string name = "Unknown"; diff --git a/TabletDriverService/TabletDriverService.vcxproj b/TabletDriverService/TabletDriverService.vcxproj index b176edc..ce153ec 100644 --- a/TabletDriverService/TabletDriverService.vcxproj +++ b/TabletDriverService/TabletDriverService.vcxproj @@ -177,6 +177,7 @@ xcopy /C /Y "$(ProjectDir)config\init.cfg" "$(SolutionDir)TabletDriverGUI\bin\De + @@ -194,6 +195,7 @@ xcopy /C /Y "$(ProjectDir)config\init.cfg" "$(SolutionDir)TabletDriverGUI\bin\De Create + diff --git a/TabletDriverService/TabletDriverService.vcxproj.filters b/TabletDriverService/TabletDriverService.vcxproj.filters index 5f7116d..0d69b36 100644 --- a/TabletDriverService/TabletDriverService.vcxproj.filters +++ b/TabletDriverService/TabletDriverService.vcxproj.filters @@ -45,6 +45,9 @@ Header Files + + Header Files + @@ -77,6 +80,9 @@ Source Files + + Source Files + diff --git a/TabletDriverService/Utils.cpp b/TabletDriverService/Utils.cpp new file mode 100644 index 0000000..9de7090 --- /dev/null +++ b/TabletDriverService/Utils.cpp @@ -0,0 +1,44 @@ +#include "stdafx.h" +#include "Utils.h" + + +Utils::Utils() +{ + +} + + +Utils::~Utils() +{ + +} + +template +void Utils::split(const std::string &s, char delim, Out result, bool addEmpty) { + std::stringstream ss; + ss.str(s); + std::string item; + while (std::getline(ss, item, delim)) { + if (item != "" || addEmpty) + *(result++) = item; + } +} + +std::vector Utils::split(const std::string &s, char delim, bool addEmpty) { + std::vector elems; + split(s, delim, std::back_inserter(elems), addEmpty); + return elems; +} + +std::string Utils::join(std::vector v, std::string j) { + std::string result = ""; + int count = 0; + int size = v.size(); + for (auto it = v.begin(); it != v.end(); it++) { + result += *it; + if (count < size - 1) + result += j; + count++; + } + return result; +} \ No newline at end of file diff --git a/TabletDriverService/Utils.h b/TabletDriverService/Utils.h new file mode 100644 index 0000000..d637b3d --- /dev/null +++ b/TabletDriverService/Utils.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include + +class Utils +{ +public: + Utils(); + ~Utils(); + + template + static void split(const std::string &s, char delim, Out result, bool addEmpty = false); + static std::vector split(const std::string &s, char delim, bool addEmpty = false); + + static std::string join(std::vector, std::string); +}; + From 6ffefd05e9acf8de639d09cf6b5ef6de6ba538ed Mon Sep 17 00:00:00 2001 From: Maxime Cauvin Date: Thu, 22 Mar 2018 17:20:03 +0100 Subject: [PATCH 23/24] TabletButtonHandling(feat/fix): Added shortcut functionnality and fixed buttonMap driver-side --- TabletDriverGUI/ButtonMapping.xaml.cs | 83 +++++++++++++++++++++++++- TabletDriverService/ProcessCommand.cpp | 2 +- TabletDriverService/Tablet.cpp | 6 +- TabletDriverService/Tablet.h | 1 + TabletDriverService/Utils.cpp | 32 ++++++++++ TabletDriverService/Utils.h | 2 + 6 files changed, 121 insertions(+), 5 deletions(-) diff --git a/TabletDriverGUI/ButtonMapping.xaml.cs b/TabletDriverGUI/ButtonMapping.xaml.cs index 2bf1fd9..8446858 100644 --- a/TabletDriverGUI/ButtonMapping.xaml.cs +++ b/TabletDriverGUI/ButtonMapping.xaml.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -174,6 +175,84 @@ private void CheckBoxDisableTabletButtons_Unchecked(object sender, RoutedEventAr TabletButtonsContainer.IsEnabled = true; } + private enum MapType : uint + { + MAPVK_VK_TO_VSC = 0x0, + MAPVK_VSC_TO_VK = 0x1, + MAPVK_VK_TO_CHAR = 0x2, + MAPVK_VSC_TO_VK_EX = 0x3, + } + + [DllImport("user32.dll")] + private static extern int ToUnicode( + uint wVirtKey, + uint wScanCode, + byte[] lpKeyState, + [Out, MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 4)] + StringBuilder pwszBuff, + int cchBuff, + uint wFlags); + + [DllImport("user32.dll")] + private static extern bool GetKeyboardState(byte[] lpKeyState); + + [DllImport("user32.dll")] + private static extern uint MapVirtualKey(uint uCode, MapType uMapType); + + private char GetVKFromModifierKey(ModifierKeys modifierKey) + { + char ch = '\0'; + + switch (modifierKey) + { + case ModifierKeys.Control: + ch = (char)0x11; + break; + case ModifierKeys.Shift: + ch = (char)0x10; + break; + case ModifierKeys.Alt: + ch = (char)0x12; + break; + case ModifierKeys.Windows: + ch = (char)0x5B; + break; + } + return ch; + } + + private char GetCharFromKey(Key key) + { + char ch = '\0'; + + int virtualKey = KeyInterop.VirtualKeyFromKey(key); + byte[] keyboardState = new byte[256]; + GetKeyboardState(keyboardState); + + uint scanCode = MapVirtualKey((uint)virtualKey, MapType.MAPVK_VK_TO_VSC); + StringBuilder stringBuilder = new StringBuilder(2); + + int result = ToUnicode((uint)virtualKey, scanCode, keyboardState, stringBuilder, stringBuilder.Capacity, 0); + switch (result) + { + case -1: + break; + case 0: + break; + case 1: + { + ch = stringBuilder[0]; + break; + } + default: + { + ch = stringBuilder[0]; + break; + } + } + return ch; + } + private void PromptShortcutWindowEvent(object sender, EventArgs e) { PromptShortcutWindow(sender); @@ -203,8 +282,8 @@ private void PromptShortcutWindow(object sender) List l = new List(); for (var i = 0; i < shortcutMapWindow.ModifierKey.Count; ++i) - l.Add((int)shortcutMapWindow.ModifierKey[i]); - l.Add((int)shortcutMapWindow.PressedKey); + l.Add(GetVKFromModifierKey(shortcutMapWindow.ModifierKey[i])); + l.Add(GetCharFromKey(shortcutMapWindow.PressedKey)); if (shortcutMapWindow.PressedKey == Key.None) cb.SelectedIndex = (int)ButtonActionEnum.DISABLED; MacroButtonMap[idx] = l.ToArray(); diff --git a/TabletDriverService/ProcessCommand.cpp b/TabletDriverService/ProcessCommand.cpp index 2d054ec..469be2b 100644 --- a/TabletDriverService/ProcessCommand.cpp +++ b/TabletDriverService/ProcessCommand.cpp @@ -288,7 +288,7 @@ bool ProcessCommand(CommandLine *cmd) { if(!CheckTablet()) return true; char buttonMapBuffer[32]; int index = 0; - for(int i = 0; i < 8; i++) { + for(int i = 0; i < 9; i++) { tablet->buttonMap[i] = cmd->GetInt(i, tablet->buttonMap[i]); index += sprintf_s(buttonMapBuffer + index, 32 - index, "%d ", tablet->buttonMap[i]); } diff --git a/TabletDriverService/Tablet.cpp b/TabletDriverService/Tablet.cpp index 2ae562e..65ae16e 100644 --- a/TabletDriverService/Tablet.cpp +++ b/TabletDriverService/Tablet.cpp @@ -364,14 +364,16 @@ int Tablet::ReadPosition() { state.buttons = 0; for(buttonIndex = 0; buttonIndex < sizeof(buttonMap); buttonIndex++) { - // Button is set - if(buttonMap[buttonIndex] > 0) { + // Button is set (not a macro) + if(buttonMap[buttonIndex] > 0 && buttonMap[buttonIndex] < 6) { // Button is pressed if((reportData.buttons & (1 << buttonIndex)) > 0) { state.buttons |= (1 << (buttonMap[buttonIndex] - 1)); } } + else if (buttonMap[buttonIndex] == 6) + Utils::keyboardShortcutPress(buttonTabletMap[buttonIndex]); } // Convert report data to state diff --git a/TabletDriverService/Tablet.h b/TabletDriverService/Tablet.h index 36ada3b..909ba13 100644 --- a/TabletDriverService/Tablet.h +++ b/TabletDriverService/Tablet.h @@ -5,6 +5,7 @@ #include "USBDevice.h" #include "HIDDevice.h" +#include "Utils.h" using namespace std; diff --git a/TabletDriverService/Utils.cpp b/TabletDriverService/Utils.cpp index 9de7090..c86d537 100644 --- a/TabletDriverService/Utils.cpp +++ b/TabletDriverService/Utils.cpp @@ -41,4 +41,36 @@ std::string Utils::join(std::vector v, std::string j) { count++; } return result; +} + +void Utils::keyboardShortcutPress(std::vector const& keys) +{ + std::vector keyPress; + + for (auto it : keys) + { + INPUT ip; + + ip.type = INPUT_KEYBOARD; + ip.ki.wScan = 0; + ip.ki.time = 0; + ip.ki.dwExtraInfo = 0; + + if (it == VK_CONTROL || it == VK_SHIFT || it == VK_MENU || it == VK_LWIN || it == VK_RWIN) + ip.ki.wVk = it; + else + ip.ki.wVk = VkKeyScan(it); + ip.ki.dwFlags = 0; + + keyPress.push_back(ip); + } + for (auto it : keyPress) + { + SendInput(1, &it, sizeof(INPUT)); + } + for (int i = 0; i < keyPress.size(); ++i) + { + keyPress[i].ki.dwFlags = KEYEVENTF_KEYUP; + SendInput(1, &keyPress[i], sizeof(INPUT)); + } } \ No newline at end of file diff --git a/TabletDriverService/Utils.h b/TabletDriverService/Utils.h index d637b3d..e35311c 100644 --- a/TabletDriverService/Utils.h +++ b/TabletDriverService/Utils.h @@ -15,5 +15,7 @@ class Utils static std::vector split(const std::string &s, char delim, bool addEmpty = false); static std::string join(std::vector, std::string); + + static void keyboardShortcutPress(std::vector const& keys); }; From bfae0c2956ca9b9dbdadb2301a56b33829deb943 Mon Sep 17 00:00:00 2001 From: Maxime Cauvin Date: Thu, 22 Mar 2018 17:28:15 +0100 Subject: [PATCH 24/24] TabletButtonHandling(refactor): Simplifying code when converting into VirtualKey value --- TabletDriverGUI/ButtonMapping.xaml.cs | 48 ++++++--------------------- TabletDriverService/Utils.cpp | 5 +-- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/TabletDriverGUI/ButtonMapping.xaml.cs b/TabletDriverGUI/ButtonMapping.xaml.cs index 8446858..e2c061c 100644 --- a/TabletDriverGUI/ButtonMapping.xaml.cs +++ b/TabletDriverGUI/ButtonMapping.xaml.cs @@ -199,58 +199,32 @@ private static extern int ToUnicode( [DllImport("user32.dll")] private static extern uint MapVirtualKey(uint uCode, MapType uMapType); - private char GetVKFromModifierKey(ModifierKeys modifierKey) + private int GetVKFromModifierKey(ModifierKeys modifierKey) { - char ch = '\0'; + int ch = 0; switch (modifierKey) { case ModifierKeys.Control: - ch = (char)0x11; + ch = 0x11; break; case ModifierKeys.Shift: - ch = (char)0x10; + ch = 0x10; break; case ModifierKeys.Alt: - ch = (char)0x12; + ch = 0x12; break; case ModifierKeys.Windows: - ch = (char)0x5B; + ch = 0x5B; break; } - return ch; + + return (ch); } - private char GetCharFromKey(Key key) + private int GetVKFromKey(Key key) { - char ch = '\0'; - - int virtualKey = KeyInterop.VirtualKeyFromKey(key); - byte[] keyboardState = new byte[256]; - GetKeyboardState(keyboardState); - - uint scanCode = MapVirtualKey((uint)virtualKey, MapType.MAPVK_VK_TO_VSC); - StringBuilder stringBuilder = new StringBuilder(2); - - int result = ToUnicode((uint)virtualKey, scanCode, keyboardState, stringBuilder, stringBuilder.Capacity, 0); - switch (result) - { - case -1: - break; - case 0: - break; - case 1: - { - ch = stringBuilder[0]; - break; - } - default: - { - ch = stringBuilder[0]; - break; - } - } - return ch; + return (KeyInterop.VirtualKeyFromKey(key)); } private void PromptShortcutWindowEvent(object sender, EventArgs e) @@ -283,7 +257,7 @@ private void PromptShortcutWindow(object sender) for (var i = 0; i < shortcutMapWindow.ModifierKey.Count; ++i) l.Add(GetVKFromModifierKey(shortcutMapWindow.ModifierKey[i])); - l.Add(GetCharFromKey(shortcutMapWindow.PressedKey)); + l.Add(GetVKFromKey(shortcutMapWindow.PressedKey)); if (shortcutMapWindow.PressedKey == Key.None) cb.SelectedIndex = (int)ButtonActionEnum.DISABLED; MacroButtonMap[idx] = l.ToArray(); diff --git a/TabletDriverService/Utils.cpp b/TabletDriverService/Utils.cpp index c86d537..4f13aec 100644 --- a/TabletDriverService/Utils.cpp +++ b/TabletDriverService/Utils.cpp @@ -56,10 +56,7 @@ void Utils::keyboardShortcutPress(std::vector const& keys) ip.ki.time = 0; ip.ki.dwExtraInfo = 0; - if (it == VK_CONTROL || it == VK_SHIFT || it == VK_MENU || it == VK_LWIN || it == VK_RWIN) - ip.ki.wVk = it; - else - ip.ki.wVk = VkKeyScan(it); + ip.ki.wVk = it; ip.ki.dwFlags = 0; keyPress.push_back(ip);