Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
valuex opened this issue May 15, 2021 · 1 comment
Open

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

valuex opened this issue May 15, 2021 · 1 comment

Comments

@valuex
Copy link

valuex commented May 15, 2021

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 valuex changed the title How to surpress the overide PPT's internal shortcut combination? How to override PPT's internal shortcut combination? May 15, 2021
@mike-lee-dev
Copy link

mike-lee-dev commented Jul 8, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants