This project has moved and is read-only. For the latest updates, please go here.

SendKeys.SendWait Issue

Jul 17, 2011 at 6:14 PM

Hey Sebastian,

Amazing project you have here. I ran into one issue with where System.Windows.Forms.SendKeys.SendWait does not function properly after running LateBindingApi.Core.Factory.Initialize(); in an Excel Add-In. Essentially, I'm trying to simulate keyboard actions within Excel but initializing the factory somehow disrupts the SendWait function and Excel does not interpret the keyboard actions correctly. Would you have any idea what could be causing that? It happens whether or not I use the Excel Api (in NetOffice) to get the Application or another framework like Excel DNA. Here's some example code (using ExcelDna):


using System;
using System.Text;
using ExcelDna.Integration;
using SWF = System.Windows.Forms;

using Microsoft.Office.Interop.Excel;

//using Excel = NetOffice.ExcelApi;
//using Office = NetOffice.OfficeApi;

namespace SkeletonAddIn

    public class SkeletonAddIn : IExcelAddIn
        private static Application XL;

        public SkeletonAddIn()
            XL = (Application)ExcelDna.Integration.ExcelDnaUtil.Application;
            LateBindingApi.Core.Factory.Initialize(); // Commenting this makes the SendWait below function properly

        public void AutoOpen()
            XL.OnKey("^k", "Macro_Test");

        public void AutoClose()

        public static void Macro_Test()
            SWF.SendKeys.SendWait("{DOWN}"); // Doesn't work for any key combination when the factory is initialized




Now, if I use:

XL = new Excel.Application(null, ExcelDnaUtil.Application);

to get the Application object, the same issue is present.


Jul 18, 2011 at 2:04 PM


what a strange problem!
the Initialize function enables also a message filter.
please try follows after Initialize() call:

LateBindingApi.Core.Settings.EnableMessageFilter = false;

and tell me it's helpfull or not.


Aug 1, 2011 at 8:28 AM


That did indeed work. Thank You!! What is the purpose of the message filter within the late binding library?


Aug 1, 2011 at 9:54 AM

if you have long time operations(~90 secs or higher) in your addin or whatver, excel displays a message box "application is waiting for an OLE Task" or similar text.
the scary thing is the messagebox makes impossible to complete your task(rejected exception while try to access excel object model), after click on 'ok' you can finish your operation(s).
DisplayAlerts to false is not helpful here. a messagefilter suspress the dialog box but also sendkey messages as side effect. (i dont know that while devtime, my bad)
the most customers may doesnt need a messagefilter. it was true by default to see it works without problems and thats true :) and now is false by default.



Aug 2, 2011 at 4:52 AM

Great, thanks for the reply. I downloaded v1.1 and noticed that the message filter is still enabled by default:



public static void Initialize()
if (!Settings.EnableMessageFilter)
  Settings.EnableMessageFilter = true;

Aug 2, 2011 at 10:44 AM

holy shit ... you right!

shame on me :/ i do a fix today in current release und update them today.

Aug 3, 2011 at 5:05 AM

Haha, no worries! I'm sure that can wait until a future release ;)