by Fenton Webb
With ObjectARX you can add a filter function into the AutoCAD's Windows message loop (you can also PInvoke this functionality in .NET too).
The following example shows how to trap and filter out the cursor keys allowing your application to respond to the keys, rather than let the command line editor do it (return TRUE from the filterCurs()). It uses acedRegisterFilterWinMsg() to register a windows hook, and acedRemoveFilterWinMsg() to unregister the hook...
#include "rxmfcapi.h"
// After a call of this function AutoCAD will use filterCurs() function
// to process key presses.
//------------------------------------------------------------------------
void curskeys()
{
if( TRUE == cursDone ) // already has the hook??
return;
acutPrintf( _T("Cursor filtering enabled...\n") );
if( FALSE == acedRegisterFilterWinMsg( filterCurs ) )
acutPrintf( _T("Can't register Windows cursor-key msg hook\n"));
else
cursDone = TRUE;
}
static BOOL cursDone = FALSE;
// Stop using filterCurs() for processing key presses
//------------------------------------------------------------------
void nocurskeys()
{
if( TRUE == cursDone )
{
acedRemoveFilterWinMsg( filterCurs );
cursDone = FALSE;
}
}
// In this function your application can control presses of particular keys
// or let AutoCAD do it.
//------------------------------------------------------------------------------
BOOL filterCurs( MSG *pMsg )
{
if( WM_KEYDOWN == pMsg->message && pMsg->wParam >= 37 && pMsg->wParam <= 40 )
{
switch( pMsg->wParam )
{
case 37: // left
acutPrintf( _T("Left\n") );
break;
case 38: // up
acutPrintf( _T("Up\n") );
break;
case 39: // right
acutPrintf( _T("Right\n") );
break;
case 40: // down
acutPrintf( _T("Down\n") );
break;
}
return TRUE; // filter message
}
return FALSE;
}