Muller Stephan
Posts: 50
Joined: 2010-03-11
|
Hi,
i want to capture the Word 2007 KeyDown event. Therefore I set HandleShortcuts to true and added a Messagebox in the OnKeyDown event.
However this code is never called, no matter what key I press in Word.
What am I doing wrong, how can i capture the key down/ key press event in word?
Thanks
Stephan
Here is the code I am using
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Windows.Forms;
using AddinExpress.MSO;
using Word = Microsoft.Office.Interop.Word;
namespace Spiegelschrift
{
/// <summary>
/// Add-in Express Add-in Module
/// </summary>
[GuidAttribute("FFF67985-21C9-47AC-B202-D2CCA648B2D7"), ProgId("Spiegelschrift.AddinModule")]
public class AddinModule : AddinExpress.MSO.ADXAddinModule
{
public AddinModule()
{
Application.EnableVisualStyles();
InitializeComponent();
// Please add any initialization code to the AddinInitialize event handler
}
private ADXRibbonTab adxRibbonTab1;
private ADXRibbonGroup adxRibbonGroup1;
private ADXRibbonButton adxRibbonButton1;
private ImageList imageList1;
private ADXWordAppEvents adxWordEvents;
#region Component Designer generated code
/// <summary>
/// Required by designer
/// </summary>
private System.ComponentModel.IContainer components;
/// <summary>
/// Required by designer support - do not modify
/// the following method
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddinModule));
this.adxRibbonTab1 = new AddinExpress.MSO.ADXRibbonTab(this.components);
this.adxRibbonGroup1 = new AddinExpress.MSO.ADXRibbonGroup(this.components);
this.adxRibbonButton1 = new AddinExpress.MSO.ADXRibbonButton(this.components);
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.adxWordEvents = new AddinExpress.MSO.ADXWordAppEvents(this.components);
//
// adxRibbonTab1
//
this.adxRibbonTab1.Caption = "adxRibbonTab1";
this.adxRibbonTab1.Controls.Add(this.adxRibbonGroup1);
this.adxRibbonTab1.Id = "adxRibbonTab_a52aa6a2a14444358f919109c56f0683";
this.adxRibbonTab1.Ribbons = AddinExpress.MSO.ADXRibbons.msrWordDocument;
//
// adxRibbonGroup1
//
this.adxRibbonGroup1.Caption = "Spiegeln";
this.adxRibbonGroup1.Controls.Add(this.adxRibbonButton1);
this.adxRibbonGroup1.Id = "adxRibbonGroup_41777e6c9ceb44cab66d6e9ee68adf6b";
this.adxRibbonGroup1.ImageTransparentColor = System.Drawing.Color.Transparent;
this.adxRibbonGroup1.Ribbons = AddinExpress.MSO.ADXRibbons.msrWordDocument;
//
// adxRibbonButton1
//
this.adxRibbonButton1.Caption = "aktiv";
this.adxRibbonButton1.Id = "adxRibbonButton_aa4006d77efe469d853676b94d291ace";
this.adxRibbonButton1.Image = 0;
this.adxRibbonButton1.ImageList = this.imageList1;
this.adxRibbonButton1.ImageTransparentColor = System.Drawing.Color.Transparent;
this.adxRibbonButton1.Ribbons = AddinExpress.MSO.ADXRibbons.msrWordDocument;
this.adxRibbonButton1.Size = AddinExpress.MSO.ADXRibbonXControlSize.Large;
this.adxRibbonButton1.ToggleButton = true;
//
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "left.ico");
//
// AddinModule
//
this.AddinName = "Spiegelschrift";
this.HandleShortcuts = true;
this.SupportedApps = AddinExpress.MSO.ADXOfficeHostApp.ohaWord;
this.OnKeyDown += new AddinExpress.MSO.ADXKeyDown_EventHandler(this.AddinModule_OnKeyDown);
}
#endregion
#region Add-in Express automatic code
// Required by Add-in Express - do not modify
// the methods within this region
public override System.ComponentModel.IContainer GetContainer()
{
if (components == null)
components = new System.ComponentModel.Container();
return components;
}
[ComRegisterFunctionAttribute]
public static void AddinRegister(Type t)
{
AddinExpress.MSO.ADXAddinModule.ADXRegister(t);
}
[ComUnregisterFunctionAttribute]
public static void AddinUnregister(Type t)
{
AddinExpress.MSO.ADXAddinModule.ADXUnregister(t);
}
public override void UninstallControls()
{
base.UninstallControls();
}
#endregion
public static new AddinModule CurrentInstance
{
get
{
return AddinExpress.MSO.ADXAddinModule.CurrentInstance as AddinModule;
}
}
public Word._Application WordApp
{
get
{
return (HostApplication as Word._Application);
}
}
private void AddinModule_OnKeyDown(object sender, ADXKeyDownEventArgs e)
{
MessageBox.Show("test");
}
}
}
|
|
Eugene Astafiev
Guest
|
|
Muller Stephan
Posts: 50
Joined: 2010-03-11
|
Hey Eugene,
I am sorry for wasting your time. The addin was not loaded. Thank you!
Stephan |
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
Hello Stephan,
Thank you for letting us know.
Andrei Smolin
Add-in Express Team Leader |
|
Muller Stephan
Posts: 50
Joined: 2010-03-11
|
One more question: Is there also an onKeyUp event? |
|
Andrei Smolin
Add-in Express team
Posts: 18825
Joined: 2006-05-11
|
No, there's no such event.
Andrei Smolin
Add-in Express Team Leader |
|