Hi Team,
Can anyone please send me sample code to detect if the "Enter" key is pressed in the word document in the WordApp_WindowSelectionChange event using VSTO word add-in in c#.Thanks.
Hi Team,
Can anyone please send me sample code to detect if the "Enter" key is pressed in the word document in the WordApp_WindowSelectionChange event using VSTO word add-in in c#.Thanks.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Daniel WrightRank #2,947 · 489 reputationPosted Apr 29, 2025, 7:37 AM EDT
Hi there!
To detect if the "Enter" key is pressed in a Word document within the WordApp_WindowSelectionChange event using a VSTO Word add-in in C#, you can achieve this by handling the KeyDown event within the event handler. Here's a sample code snippet that demonstrates how you can accomplish this:
private void ThisAddIn_Startup(object sender, EventArgs e) { Application.WindowSelectionChange += Application_WindowSelectionChange; } private void Application_WindowSelectionChange(Selection selection) { ((Word.Document)selection.Document).Application.KeyBindings.Add(Word.WdKeyCategory.wdKeyCategoryCommand, "DetectEnterKeyPress", "^r", true, true); } private void ThisAddIn_Shutdown(object sender, EventArgs e) { // Cleanup code if needed }In this code snippet, we're adding a key binding for the "CTRL + Enter" key combination to the Word application. When the user presses "CTRL + Enter" in the Word document, the "DetectEnterKeyPress" action will be triggered.
You can then handle this key binding action in your code to perform the desired functionality, such as detecting the "Enter" key press event.
I hope this helps! Let me know if you have any further questions or need additional clarification.
JosephsRank #1,506 · 1.1K reputationPosted Apr 29, 2025, 10:53 AM EDT
Are you expect Macro code?