标题: [即时预览] 在Jig中检测Shift和Control的按键状态 [打印本页] 作者: 萧闫子 时间: 2014-1-8 16:35 标题: [即时预览] 在Jig中检测Shift和Control的按键状态 Detecting the use of the shift and control keys during an AutoCAD jig using .NET
Another interesting little problem, that of how to detect the use of modifier keys during a jig operation (to indicate different jig behaviour). In this case the specific task was to detect the use of the Control and Shift keys, which – if held down during the jig – should cause our object to display differently.
I started with the code from this previous post which uses a DrawJig to place text in the plane of the screen during the jig operation. I initially thought I’d have to use a message filter (as shown in this previous post), but I eventually realised it wasn’t needed: it’s simply a matter of querying the state of System.Windows.Forms.Control.ModifierKeys at the appropriate moment during our WorldDraw().
Here’s the C# code
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
namespace JigTextPlanarToScreen
{
public class TextJig : DrawJig
{
private Point3d _position;
public Point3d Position
{
get { return _position; }
}
// We'll keep our styles alive rather than recreating them