.NET: IMessageFilter Problem with Bricscad
Trying to trap keypress before they get to the Bricscad application window.
In AutoCAD I use an IMessageFilter like so:
using WinForms = System.Windows.Forms;
using Keys = System.Windows.Forms.Keys;
private class BrushSizeKeyFilter : WinForms.IMessageFilter
{
public bool PreFilterMessage(ref WinForms.Message m)
{
const int WM_KEYDOWN = 0x0100;
if (m.Msg==WM_KEYDOWN)
{
Keys kc = (Keys)(int)m.WParam & Keys.KeyCode;
// check for Q or A
if (kc == Keys.Q)
{
Debug.WriteLine("Q captured!");
Active.Document.SendStringToExecute("_Q ", true, false, false);
return true;
}
if (kc == Keys.A)
{
Debug.WriteLine("A captured!");
Active.Document.SendStringToExecute("_A ", true, false, false);
return true;
}
if (kc == Keys.V)
{
Debug.WriteLine("V captured!");
Active.Document.SendStringToExecute("_V ", true, false, false);
return true;
}
}
// never falter
return false;
}
}
BrushSizeKeyFilter qaFilter = new BrushSizeKeyFilter();
WinForms.Application.AddMessageFilter(qaFilter);
For some reason the filter doesn't seem to get added to the Bricscad application. If it does, the Debug.Writeline() lines aren't firing.
Any ideas?
0
Comments
-
I think an Application.PreTranslateMessage event handler should work on both platforms.
0 -
Application.PreTranslateMessage worked a treat, thank you!
0
This discussion has been closed.
