Strg+B via WndProc-Hook - greift auch wenn WebView2 Fokus hat
This commit is contained in:
parent
c435c0fbe2
commit
362050820b
1 changed files with 32 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue