Skip to content

Commit

Permalink
Fix Ctrl+Alt and right mouse button usage in input learn window
Browse files Browse the repository at this point in the history
  • Loading branch information
stax76 committed Oct 31, 2023
1 parent 4c4088b commit 4baa26d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
customizing the conf directory location.
- Improved support for third party osc scripts like uosc.
- 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)
Expand Down
39 changes: 29 additions & 10 deletions src/MpvNet.Windows/WPF/LearnWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public partial class LearnWindow : Window
int VK_LCONTROL = 0xA2;
int VK_RCONTROL = 0xA3;

bool BlockMBTN_LEFT;
bool BlockMBTN_RIGHT;

public LearnWindow()
{
InitializeComponent();
Expand All @@ -47,7 +50,7 @@ static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpKeyState,
[DllImport("user32.dll")]
static extern bool GetKeyboardState(byte[] lpKeyState);

string ToUnicode(uint vk)
string ToUnicode(uint vk, ref bool firstEmpty)
{
byte[] keys = new byte[256];

Expand All @@ -61,11 +64,14 @@ string ToUnicode(uint vk)

string ret = ToUnicode(vk, scanCode, keys);

firstEmpty = ret == "";

if (ret.Length == 1 && ret[0] < 32)
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;
ret = ToUnicode(vk, scanCode, keys);
}
Expand Down Expand Up @@ -93,14 +99,15 @@ IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool hand

void OnKeyDown(uint vk)
{
bool firstEmpty = false;
Keys key = (Keys)vk;

if (key == Keys.ControlKey || key == Keys.ShiftKey ||
key == Keys.Menu || key == Keys.None)

return;

string text = ToUnicode(vk);
string text = ToUnicode(vk, ref firstEmpty);

if ((int)key > 111 && (int)key < 136)
text = "F" + ((int)key - 111);
Expand Down Expand Up @@ -162,16 +169,18 @@ void OnKeyDown(uint vk)
if (isLetter && isShift)
text = text.ToUpper();

string keyString = ToUnicode(vk);
string keyString = ToUnicode(vk, ref firstEmpty);

if (isAlt && !isCtrl)
text = "ALT+" + text;
text = "Alt+" + text;

if (isShift && keyString == "")
text = "SHIFT+" + text;
text = "Shift+" + text;

if (isCtrl && !(keyString != "" && isCtrl && isAlt))
text = "CTRL+" + text;
if (isCtrl && isAlt && firstEmpty)
text = "Ctrl+Alt+" + text;
else if (isCtrl && !(keyString != "" && isCtrl && isAlt))
text = "Ctrl+" + text;

if (!string.IsNullOrEmpty(text))
SetKey(text);
Expand Down Expand Up @@ -238,6 +247,12 @@ void Window_MouseUp(object sender, MouseButtonEventArgs e)
else
SetKey("MBTN_LEFT");
break;
case MouseButton.Right:
if (BlockMBTN_RIGHT)
BlockMBTN_RIGHT = false;
else
SetKey("MBTN_RIGHT");
break;
case MouseButton.Middle:
SetKey("MBTN_MID");
break;
Expand All @@ -250,15 +265,19 @@ void Window_MouseUp(object sender, MouseButtonEventArgs e)
}
}

bool BlockMBTN_LEFT;

void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
SetKey("MBTN_LEFT_DBL");
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)
Expand Down
2 changes: 2 additions & 0 deletions src/MpvNet/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ public void Init(IntPtr formHandle)

SetPropertyLong("wid", formHandle.ToInt64());
SetPropertyInt("osd-duration", 2000);

SetPropertyBool("input-default-bindings", true);
SetPropertyBool("input-builtin-bindings", false);

SetPropertyString("watch-later-options", "mute");
SetPropertyString("screenshot-directory", "~~desktop/");
SetPropertyString("osd-playing-msg", "${media-title}");
Expand Down

0 comments on commit 4baa26d

Please sign in to comment.