From 362050820b6593e72dea407503fd87190b864f4a Mon Sep 17 00:00:00 2001 From: administrator Date: Tue, 12 May 2026 21:44:10 +0200 Subject: [PATCH] Strg+B via WndProc-Hook - greift auch wenn WebView2 Fokus hat --- MainWindow.xaml.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index e83fdad..74dc07d 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -41,6 +41,9 @@ public partial class MainWindow : Window // WebView2 für Web-Sender (YouTube, Netflix etc.) private bool _webViewReady = false; + // WndProc-Hook für globale Tastatureingaben (auch wenn WebView2 Fokus hat) + private System.Windows.Interop.HwndSource? _hwndSource; + // Pre-Fullscreen UI-State private WindowStyle _prevStyle = WindowStyle.SingleBorderWindow; private WindowState _prevState = WindowState.Normal; @@ -84,6 +87,7 @@ public partial class MainWindow : Window Loaded += MainWindow_Loaded; Closing += MainWindow_Closing; KeyDown += MainWindow_KeyDown; + PreviewKeyDown += MainWindow_KeyDown; } private void OnVideoDoubleClick(object sender, MouseButtonEventArgs e) @@ -105,6 +109,11 @@ public partial class MainWindow : Window private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { + // WndProc-Hook registrieren damit Strg+B auch greift wenn WebView2 Fokus hat + _hwndSource = System.Windows.Interop.HwndSource.FromHwnd( + new System.Windows.Interop.WindowInteropHelper(this).Handle); + _hwndSource?.AddHook(WndProc); + var initialVolume = (int)SldVolume.Value; await Task.Run(() => InitializePlayerNatives(initialVolume)); VideoView.MediaPlayer = _player; @@ -171,6 +180,7 @@ public partial class MainWindow : Window { try { + _hwndSource?.RemoveHook(WndProc); _epgTimer.Stop(); _zapTimer.Stop(); _epgRefreshTimer.Stop(); @@ -1055,6 +1065,28 @@ public partial class MainWindow : Window // ────────── Hotkeys ────────── + // WM_KEYDOWN abfangen damit Strg+B auch funktioniert wenn WebView2 den Fokus hat + private const int WM_KEYDOWN = 0x0100; + private const int VK_B = 0x42; + + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + if (msg == WM_KEYDOWN && (int)wParam == VK_B) + { + // GetKeyState(VK_CONTROL) - High-bit gesetzt = Taste gedrueckt + var ctrl = (NativeMethods.GetKeyState(0x11) & 0x8000) != 0; + if (ctrl) + Dispatcher.BeginInvoke(() => BtnSidebarToggle_Click(this, new RoutedEventArgs())); + } + return IntPtr.Zero; + } + + private static class NativeMethods + { + [System.Runtime.InteropServices.DllImport("user32.dll")] + internal static extern short GetKeyState(int nVirtKey); + } + private void MainWindow_KeyDown(object sender, KeyEventArgs e) { if (Keyboard.FocusedElement is TextBox) return;