Event handler function ignores some functions
I am using a globalhook classfrom code project to control powerpoint slideshow with custom keys (windows form application) I want the powerpoint object to close when anykey is pressed but the event handler ignores this function and refuses to make any actions unless it's in the scope of the main form. here is my code:
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();
}
}
Try to use HookManager class from here it works fine with me.
精彩评论