I found how to avoid crashes:
First step is to set something else, not empty string in Application.OnKey
Application.OnKey("{F5}", " ")
If you just leave it alone, Excel will show the message about wrong macro name.
I removed this message temporarily setting Application.DisplayAlerts = false
when key event happens:
static int HookCallback(int nCode, IntPtr wParam, IntPtr lParam) {
if (nCode < 0) {
return (int) WinApi.CallNextHookEx(_hookID, nCode, wParam, lParam);
}
if (nCode == HC_ACTION) {
ExcelAddIn.ExcelApp.DisplayAlerts = false;
ExecuteAsync(() => {
ExecuteInUIThread(() => {
OnKeyPress((uint) wParam);
Application.DisplayAlerts = true;
});
});
}
return (int) WinApi.CallNextHookEx(_hookID, nCode, wParam, lParam);
}
But after that I found that this bug is fixed already and fix version is goning to be released soon (if not yet).