globalmousekeyhook icon indicating copy to clipboard operation
globalmousekeyhook copied to clipboard

How to override PPT's internal shortcut combination?

Open valuex opened this issue 3 years ago • 1 comments

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();
        }
    }
}

valuex avatar May 15 '21 02:05 valuex

@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

mike-lee-dev avatar Jul 08 '21 08:07 mike-lee-dev