Fix Ctrl+Alt and right mouse button usage in input learn window

This commit is contained in:
stax76
2023-10-31 12:30:28 +01:00
parent 4c4088b28a
commit 4baa26d7a0
3 changed files with 32 additions and 10 deletions

View File

@@ -26,6 +26,7 @@
customizing the conf directory location. customizing the conf directory location.
- Improved support for third party osc scripts like uosc. - Improved support for third party osc scripts like uosc.
- Support of the mpv property `focused`. - Support of the mpv property `focused`.
- Fix Ctrl+Alt and right mouse button usage in input learn window.
# v6.0.3.2 Beta (2022-10-14) # v6.0.3.2 Beta (2022-10-14)

View File

@@ -26,6 +26,9 @@ public partial class LearnWindow : Window
int VK_LCONTROL = 0xA2; int VK_LCONTROL = 0xA2;
int VK_RCONTROL = 0xA3; int VK_RCONTROL = 0xA3;
bool BlockMBTN_LEFT;
bool BlockMBTN_RIGHT;
public LearnWindow() public LearnWindow()
{ {
InitializeComponent(); InitializeComponent();
@@ -47,7 +50,7 @@ public partial class LearnWindow : Window
[DllImport("user32.dll")] [DllImport("user32.dll")]
static extern bool GetKeyboardState(byte[] lpKeyState); static extern bool GetKeyboardState(byte[] lpKeyState);
string ToUnicode(uint vk) string ToUnicode(uint vk, ref bool firstEmpty)
{ {
byte[] keys = new byte[256]; byte[] keys = new byte[256];
@@ -61,11 +64,14 @@ public partial class LearnWindow : Window
string ret = ToUnicode(vk, scanCode, keys); string ret = ToUnicode(vk, scanCode, keys);
firstEmpty = ret == "";
if (ret.Length == 1 && ret[0] < 32) if (ret.Length == 1 && ret[0] < 32)
return ""; return "";
if (ret == "" && (keys[VK_MENU] & 0x80) != 0) if (firstEmpty)
{ {
keys[VK_LCONTROL] = keys[VK_RCONTROL] = keys[VK_CONTROL] = 0;
keys[VK_LMENU] = keys[VK_RMENU] = keys[VK_MENU] = 0; keys[VK_LMENU] = keys[VK_RMENU] = keys[VK_MENU] = 0;
ret = ToUnicode(vk, scanCode, keys); ret = ToUnicode(vk, scanCode, keys);
} }
@@ -93,6 +99,7 @@ public partial class LearnWindow : Window
void OnKeyDown(uint vk) void OnKeyDown(uint vk)
{ {
bool firstEmpty = false;
Keys key = (Keys)vk; Keys key = (Keys)vk;
if (key == Keys.ControlKey || key == Keys.ShiftKey || if (key == Keys.ControlKey || key == Keys.ShiftKey ||
@@ -100,7 +107,7 @@ public partial class LearnWindow : Window
return; return;
string text = ToUnicode(vk); string text = ToUnicode(vk, ref firstEmpty);
if ((int)key > 111 && (int)key < 136) if ((int)key > 111 && (int)key < 136)
text = "F" + ((int)key - 111); text = "F" + ((int)key - 111);
@@ -162,16 +169,18 @@ public partial class LearnWindow : Window
if (isLetter && isShift) if (isLetter && isShift)
text = text.ToUpper(); text = text.ToUpper();
string keyString = ToUnicode(vk); string keyString = ToUnicode(vk, ref firstEmpty);
if (isAlt && !isCtrl) if (isAlt && !isCtrl)
text = "ALT+" + text; text = "Alt+" + text;
if (isShift && keyString == "") if (isShift && keyString == "")
text = "SHIFT+" + text; text = "Shift+" + text;
if (isCtrl && !(keyString != "" && isCtrl && isAlt)) if (isCtrl && isAlt && firstEmpty)
text = "CTRL+" + text; text = "Ctrl+Alt+" + text;
else if (isCtrl && !(keyString != "" && isCtrl && isAlt))
text = "Ctrl+" + text;
if (!string.IsNullOrEmpty(text)) if (!string.IsNullOrEmpty(text))
SetKey(text); SetKey(text);
@@ -238,6 +247,12 @@ public partial class LearnWindow : Window
else else
SetKey("MBTN_LEFT"); SetKey("MBTN_LEFT");
break; break;
case MouseButton.Right:
if (BlockMBTN_RIGHT)
BlockMBTN_RIGHT = false;
else
SetKey("MBTN_RIGHT");
break;
case MouseButton.Middle: case MouseButton.Middle:
SetKey("MBTN_MID"); SetKey("MBTN_MID");
break; break;
@@ -250,8 +265,6 @@ public partial class LearnWindow : Window
} }
} }
bool BlockMBTN_LEFT;
void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e) void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{ {
if (e.ChangedButton == MouseButton.Left) if (e.ChangedButton == MouseButton.Left)
@@ -259,6 +272,12 @@ public partial class LearnWindow : Window
SetKey("MBTN_LEFT_DBL"); SetKey("MBTN_LEFT_DBL");
BlockMBTN_LEFT = true; BlockMBTN_LEFT = true;
} }
if (e.ChangedButton == MouseButton.Right)
{
SetKey("MBTN_RIGHT_DBL");
BlockMBTN_RIGHT = true;
}
} }
void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)

View File

@@ -91,8 +91,10 @@ public class MainPlayer : MpvClient
SetPropertyLong("wid", formHandle.ToInt64()); SetPropertyLong("wid", formHandle.ToInt64());
SetPropertyInt("osd-duration", 2000); SetPropertyInt("osd-duration", 2000);
SetPropertyBool("input-default-bindings", true); SetPropertyBool("input-default-bindings", true);
SetPropertyBool("input-builtin-bindings", false); SetPropertyBool("input-builtin-bindings", false);
SetPropertyString("watch-later-options", "mute"); SetPropertyString("watch-later-options", "mute");
SetPropertyString("screenshot-directory", "~~desktop/"); SetPropertyString("screenshot-directory", "~~desktop/");
SetPropertyString("osd-playing-msg", "${media-title}"); SetPropertyString("osd-playing-msg", "${media-title}");