Exemple #1
0
        string RegisterHotKeyWorker(
            Action hotKeyHandler, string keyName, bool hasAlt, bool hasCtrl, bool hasShift)
        {
            if (hkWindow == null)
            {
                CreateHotKeyWindow();
            }

            var context = VgcApis.Models.Datas.HotKeyContext.Create(
                hotKeyHandler, keyName, hasAlt, hasCtrl, hasShift);

            if (context == null)
            {
                return(null);
            }

            context.evCode = currentEvCode++;
            var keyMsg = context.KeyMessage;
            var handle = keyMsg.ToString();

            if (hkContexts.ContainsKey(handle) ||
                !hkWindow.RegisterHotKey(context))
            {
                return(null);
            }

            if (hkContexts.TryAdd(handle, context))
            {
                return(handle);
            }
            return(null);
        }
Exemple #2
0
        void CreateHotKeyWindow()
        {
            if (hkWindow != null)
            {
                return;
            }

            hkWindow = new VgcApis.WinForms.HotKeyWindow(niMenuRoot);
            var wndHandle = hkWindow.Handle;

            VgcApis.Libs.Sys.FileLogger.Info($"Create hot key window {wndHandle}.");
            var handles = hkContexts.Keys;

            foreach (var handle in handles)
            {
                if (hkContexts.TryGetValue(handle, out var context))
                {
                    try
                    {
                        hkWindow.RegisterHotKey(context);
                    }
                    catch { }
                }
            }

            hkWindow.OnHotKeyMessage += HandleHotKeyEvent;
        }