gmamaladze / globalmousekeyhook

This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.
MIT License
1.04k stars 257 forks source link

How to override PPT's internal shortcut combination? #144

Open valuex opened 3 years ago

valuex commented 3 years ago

I was lucky to find this project. With its help, I can set a shortcut to my PPT VSTO addin. The core part code is as below. When I pressed the defined shortcut, both my addin's function and PPT's internal command will be executed. This has one side effect that the window triggered by my addin won't be focused. I've tried to add frm.activate() or frm.focus, but none of them works. What can I do to excute only my addin's function? Any comments will be apprciated.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Gma.System.MouseKeyHook;
namespace PowerPointAddIn1
{
    public partial class ThisAddIn
    {
        public static PowerPoint.Application PPTApp;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        { 
            var QRun = Combination.FromString("Alt+E");
            Action actionQRun = ShowQRunWin;
            var assignment = new Dictionary<Combination, Action>
            {
                {QRun, actionQRun}
            };
            Hook.AppEvents().OnCombination(assignment);
        }

        public void ShowQRunWin()
        {            
            CMDForm frm = new CMDForm();
            frm.FormBorderStyle = FormBorderStyle.FixedSingle;   //set it un-resizeable       
            frm.MaximizeBox = false;  //remove maximize button
            frm.MinimizeBox = false;  //remove minimize button                
            frm.Show();
            frm.Activate();
            frm.Focus();           
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
        protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            return new RibbonUI();
        }
    }
}
mike-lee-dev commented 3 years ago

@valuex I am using this package also and want to define a mouse click event to powerpoint chart object. But the error is showing about Chart Object has no mouseevents. How can you solve this problem? Please help. Thanks

I am working on Office PowerPoint 2019