请问,如何接管autocad的热键?
本帖最后由 ynioba 于 2011-3-24 11:25 编辑我想在autocad热键之前做点事情,例如,在saveas的时候...或者说,autocad在调用这个热键的时候,虽然还是这个命令,但是处理程序是我自己定义的.也不会去执行原有的同名命令...是不是要用后来的热键去覆盖??
ps:还有个问题,autocad是不是只能打开dwg扩展名结尾的文件,凡是不是这个扩展名结尾的,都直接提示找不到文件??
本帖最后由 ynioba 于 2011-3-24 11:09 编辑
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75730
我按照这篇文章的方法,貌似搞不定呀..
using aApp = Autodesk.AutoCAD.ApplicationServices.Application;
aApp.DocumentManager.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(vetoCommand);
static void vetoCommand(object sender, DocumentLockModeChangedEventArgs e)
{
switch (e.GlobalCommandName.ToLower())
{
case "properties":
m_DbClick = false;
e.Veto();
break;
}
} public class RegHotkey : IExtensionApplication
{
public static extern IntPtr GetForegroundWindow();
IntPtr myPtr = GetForegroundWindow();
public void Initialize()
{
IntPtr myPtr = GetForegroundWindow();
Hotkey hotkey = new Hotkey(myPtr);
Hotkey.Hotkey1 = hotkey.RegisterHotkey(Keys.F3, Hotkey.KeyFlags.MOD_NONE); //定义快键(Alt + F3) ,如果是hotkey.RegisterHotkey(System.Windows.Forms.Keys.F3, Hotkey.KeyFlags.MOD_NONE);//只注册F3
hotkey.OnHotkey += new HotkeyEventHandler(OnHotkey);
Editor ed = ap.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("注册成功");
}
//卸载方法
public void Terminate()
{
}
public void OnHotkey(int HotkeyID) //设置热键的行为
{
Editor ed = ap.DocumentManager.MdiActiveDocument.Editor;
if (HotkeyID == Hotkey.Hotkey1)
{
object obj = ap.GetSystemVariable("osmode");
string os = obj.ToString();
int os1 = Convert.ToInt32(os);
ed.WriteMessage("捕捉到alt+F3。" + os1 + "\n");
if (os1 == 0 || os1 == 16384)
{
ap.SetSystemVariable("osmode", 161);
ed.WriteMessage("\n已设置为默认捕捉“端点、交点、垂足。”");
return;
}
else if (os1 > 16384)
{
int os2 = os1 - 16384;
ap.SetSystemVariable("osmode", os2);
ed.WriteMessage("\n打开捕捉。");
return;
}
}
}
}
我用这个试了一下,重新定义F3键,结果回调函数没响应,系统的F3键也没反应,哪位能帮忙看看
页:
[1]