fix:无焦点无法翻页
This commit is contained in:
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -292,9 +293,15 @@ namespace Ink_Canvas
|
|||||||
if (StackPanelPPTControls.Visibility == Visibility.Visible)
|
if (StackPanelPPTControls.Visibility == Visibility.Visible)
|
||||||
{
|
{
|
||||||
if (gest.ApplicationGesture == ApplicationGesture.Left)
|
if (gest.ApplicationGesture == ApplicationGesture.Left)
|
||||||
BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
|
{
|
||||||
|
// 直接发送翻页请求到PPT放映软件
|
||||||
|
SendKeyToPPTSlideShow(false); // 下一页
|
||||||
|
}
|
||||||
if (gest.ApplicationGesture == ApplicationGesture.Right)
|
if (gest.ApplicationGesture == ApplicationGesture.Right)
|
||||||
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
|
{
|
||||||
|
// 直接发送翻页请求到PPT放映软件
|
||||||
|
SendKeyToPPTSlideShow(true); // 上一页
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
@@ -1667,6 +1674,8 @@ namespace Ink_Canvas
|
|||||||
private static extern bool BringWindowToTop(IntPtr hWnd);
|
private static extern bool BringWindowToTop(IntPtr hWnd);
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern bool SetForegroundWindow(IntPtr hWnd);
|
private static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
|
||||||
private const int GWL_EXSTYLE = -20;
|
private const int GWL_EXSTYLE = -20;
|
||||||
@@ -2128,5 +2137,47 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region PPT翻页直接传递
|
||||||
|
/// <summary>
|
||||||
|
/// 直接发送翻页请求到PPT放映软件,让PPT软件处理翻页
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isPrevious">是否为上一页</param>
|
||||||
|
private void SendKeyToPPTSlideShow(bool isPrevious)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 查找PPT放映窗口并发送按键
|
||||||
|
var pptWindows = Process.GetProcessesByName("POWERPNT");
|
||||||
|
var wpsWindows = Process.GetProcessesByName("wpp");
|
||||||
|
|
||||||
|
foreach (var process in pptWindows.Concat(wpsWindows))
|
||||||
|
{
|
||||||
|
if (process.MainWindowHandle != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
// 激活PPT窗口
|
||||||
|
SetForegroundWindow(process.MainWindowHandle);
|
||||||
|
|
||||||
|
// 发送翻页按键消息
|
||||||
|
int keyCode = isPrevious ? 0x21 : 0x22; // VK_PRIOR : VK_NEXT
|
||||||
|
|
||||||
|
// 发送按键按下和释放消息
|
||||||
|
PostMessage(process.MainWindowHandle, 0x0100, (IntPtr)keyCode, IntPtr.Zero); // WM_KEYDOWN
|
||||||
|
PostMessage(process.MainWindowHandle, 0x0101, (IntPtr)keyCode, IntPtr.Zero); // WM_KEYUP
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// 如果直接发送失败,回退到原来的方法
|
||||||
|
if (isPrevious)
|
||||||
|
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
|
||||||
|
else
|
||||||
|
BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Ink_Canvas
|
namespace Ink_Canvas
|
||||||
{
|
{
|
||||||
@@ -8,19 +12,36 @@ namespace Ink_Canvas
|
|||||||
private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
|
private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
|
||||||
{
|
{
|
||||||
if (StackPanelPPTControls.Visibility != Visibility.Visible || currentMode != 0) return;
|
if (StackPanelPPTControls.Visibility != Visibility.Visible || currentMode != 0) return;
|
||||||
|
|
||||||
|
// 直接发送翻页请求到PPT放映软件,不通过软件处理
|
||||||
if (e.Delta >= 120)
|
if (e.Delta >= 120)
|
||||||
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
|
{
|
||||||
else if (e.Delta <= -120) BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
|
// 上一页 - 发送PageUp键到PPT放映窗口
|
||||||
|
SendKeyToPPTSlideShow(true);
|
||||||
|
}
|
||||||
|
else if (e.Delta <= -120)
|
||||||
|
{
|
||||||
|
// 下一页 - 发送PageDown键到PPT放映窗口
|
||||||
|
SendKeyToPPTSlideShow(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Main_Grid_PreviewKeyDown(object sender, KeyEventArgs e)
|
private void Main_Grid_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (StackPanelPPTControls.Visibility != Visibility.Visible || currentMode != 0) return;
|
if (StackPanelPPTControls.Visibility != Visibility.Visible || currentMode != 0) return;
|
||||||
|
|
||||||
|
// 直接发送翻页请求到PPT放映软件,不通过软件处理
|
||||||
if (e.Key == Key.Down || e.Key == Key.PageDown || e.Key == Key.Right || e.Key == Key.N ||
|
if (e.Key == Key.Down || e.Key == Key.PageDown || e.Key == Key.Right || e.Key == Key.N ||
|
||||||
e.Key == Key.Space) BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
|
e.Key == Key.Space)
|
||||||
if (e.Key == Key.Up || e.Key == Key.PageUp || e.Key == Key.Left || e.Key == Key.P)
|
{
|
||||||
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
|
e.Handled = true; // 阻止事件继续传播
|
||||||
|
SendKeyToPPTSlideShow(false); // 下一页
|
||||||
|
}
|
||||||
|
else if (e.Key == Key.Up || e.Key == Key.PageUp || e.Key == Key.Left || e.Key == Key.P)
|
||||||
|
{
|
||||||
|
e.Handled = true; // 阻止事件继续传播
|
||||||
|
SendKeyToPPTSlideShow(true); // 上一页
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Window_KeyDown(object sender, KeyEventArgs e)
|
private void Window_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user