- 积分
- 3855
- 明经币
- 个
- 注册时间
- 2003-12-18
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2020-9-26 23:11:06
|
显示全部楼层
- public class RegHotkey : IExtensionApplication
- {
- [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
- 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键也没反应,哪位能帮忙看看 |
|