1

我目前正在开发 Enterprise Architect 插件,我确实需要使用一些自定义热键来满足用户偏好。通过使用本文中的功能,它可以正常工作:https ://community.sparxsystems.com/community-resources/805-triggering-add-in-functionality-with-custom-hotkeys-in-enterprise-architect ,但是有了这个使用自定义热键的方式 Enterprise Architect 经常大量使用处理器的一个核心 -> 如果我删除插件 dll,并从注册表中删除该键,这个问题就会消失,我现在确信自定义热键功能会导致它。

任何人都可以通过提供另一种在企业架构师插件中使用自定义热键的方式来帮助我吗?一直在寻找其他解决方案,但尚未取得任何进展。

塔马斯

编辑...找到解决方案:修改 InvisibleHotKeyForm.cs 和 Hotkey.cs

InvisibleHotKeyForm.cs 修改:删除“worker_DoWork”方法和

public partial class InvisibleHotKeyForm : Form
{
    private const double Button_MilliSec = 10.0;
    private readonly IEnumerable<Hotkey> _hotkeys;
    private readonly int _thisProcessId;
    private int _lastActiveProcessId;
    private readonly BackgroundWorker _worker;
    private System.Timers.Timer Timer_Button;

public InvisibleHotKeyForm(IEnumerable<Hotkey> hotkeys)
{
    InitializeComponent();

    this._thisProcessId = Process.GetCurrentProcess().Id;
    this._worker = new BackgroundWorker();
    this.Timer_Init(10.0);
    this._hotkeys = hotkeys;
    this._lastActiveProcessId = this._thisProcessId;
    Closing += (sender, eventArgs) => ((List<Hotkey>)_hotkeys).ForEach(key => key.Dispose());
}

private void Timer_Init(double Millisec)
{
    this.Timer_Button = new System.Timers.Timer();
    this.Timer_Button.Elapsed += new ElapsedEventHandler(OnTimedEvent);
    this.Timer_Button.Interval = Millisec;
    this.Timer_Button.Enabled = true;
}

private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
    int id = ActiveProcess.GetActiveProcess().Id;
    if (this._lastActiveProcessId == id)
        return;
    if (this._thisProcessId == id)
    {
        this.BeginInvoke((Delegate)new MethodInvoker(RegisterHotKeys));
    }
    else if (this._thisProcessId != id)
    {
        this.BeginInvoke((Delegate)new MethodInvoker(UnregisterHotKeys));
    }
    this._lastActiveProcessId = id;
}

. . .

和 Hotkey.cs 修改:

public class Hotkey : IDisposable
{
    public const int WM_HOTKEY_MSG_ID = 786;
    private Keys Key { get; set; }
    private Modifiers Modifiers { get; set; }
    public HotkeyHandler Handler { get; private set; }
    private int Id { get; set; }

private IWin32Window _registeredWindow;
private bool _registered;

public Hotkey(Keys key, Modifiers modifiers, HotkeyHandler handler)
{
    this._registeredWindow = (IWin32Window)null;
    this._registered = false;
    this.Key = key;
    this.Modifiers = modifiers;
    this.Handler = handler;
    Id = GetHashCode();
}

. . .

4

0 回答 0