事件处理函数忽略某些函数

本文关键字:函数 处理函数 事件 | 更新日期: 2023-09-27 17:54:34

我正在使用一个globalhook类从代码项目来控制powerpoint幻灯片自定义键(windows窗体应用程序)我希望powerpoint对象关闭时按下任何键,但事件处理程序忽略此函数并拒绝做出任何动作,除非它在主窗体的范围内。下面是我的代码:

public partial class Form1 : Form
{
    PowerPoint.Application objApp;
    PowerPoint.Presentations objPresSet;
    PowerPoint._Presentation objPres;
    PowerPoint.Slides objSlides;
    PowerPoint._Slide objSlide;
    public Form1()
    {
        InitializeComponent();
        UserActivityHook actHook;
        objApp = new PowerPoint.Application();
        actHook = new UserActivityHook(); // crate an instance with global hooks
        // hang on events
        actHook.KeyPress += new KeyPressEventHandler(MyKeyPress);
        objPresSet = objApp.Presentations;
        objPres = objPresSet.Add(MsoTriState.msoTrue);
        objSlides = objPres.Slides;
    }
    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new Form1());
    }
    // UserActivityHook actHook;
    public void MyKeyPress(object sender, KeyPressEventArgs e)
    {
        Form2 Form2 = new Form2();
         button1.Hide(); //executes normally 
         Form2.Show(); //no action
         objApp.Quit(); // no action
    }
    private void button1_Click(object sender, EventArgs e)
    {
        Form2 Form2 = new Form2();
        Form2.Show();
    }   
}

事件处理函数忽略某些函数

尝试从这里使用HookManager类,它对我来说很好。