Click here to Skip to main content
11,721,289 members (83,359 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
How do I open the start menu in C#? Please help me
Posted 8-Dec-09 8:08am
Edited 8-Dec-09 10:25am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Add this in your header:
using System.Runtime.InteropServices;

Place the variable declarations on the class level :
private static extern int keybd_event(Byte bVk, Byte bScan, long dwFlags, long dwExtraInfo);
private const byte UP = 2;
private const byte CTRL = 17;
private const byte ESC = 27;

Finally on the event where you want to open start menu use :
// Press Ctrl-Esc key to open Start menu
keybd_event(CTRL, 0, 0, 0);
keybd_event(ESC, 0, 0, 0);
// Need to Release those two keys
keybd_event(CTRL, 0, UP, 0);
keybd_event(ESC, 0, UP, 0);

The start menu will open.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This can be done by sending "Ctrl+Esc" to the system as if it was generated on the keyboard by pressing the Windows key (or Ctrl+Esc on legacy keyboards).

private static void ShowStartMenu()
   // key down event:
   const byte keyControl = 0x11;
   const byte keyEscape = 0x1B;
   keybd_event(keyControl, 0, 0, UIntPtr.Zero);
   keybd_event(keyEscape, 0, 0, UIntPtr.Zero);
   // key up event:
   const uint KEYEVENTF_KEYUP = 0x02;
   keybd_event(keyControl, 0, KEYEVENTF_KEYUP, UIntPtr.Zero);
   keybd_event(keyEscape, 0, KEYEVENTF_KEYUP, UIntPtr.Zero);
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
   UIntPtr dwExtraInfo);

This solution was developed using the documentation found at:
Keyboard Events Simulation using keybd_event() function[^].

The PInvoke signature was otained from
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Thanks for referencing your code. It was really helpful. Now i can do for other keys too.
Collin Jasnoch at 22-Aug-12 14:26pm
You should never bring threads back from the dead!

The last post from this was in '09!!! Nearly 3 years ago!

If you want to thank the ones that answered it you could have either left a comment or sent them a message (if they have it enabled). Or give them a 5 as that is what it is for.

In no circumstance does it make sense for you to add a solution thus reincarnating this question from the dead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 515
1 OriginalGriff 279
2 Mika Wendelius 170
3 F-ES Sitecore 150
4 cyycoish 70
0 Sergey Alexandrovich Kryukov 2,209
1 OriginalGriff 969
2 F-ES Sitecore 660
3 Maciej Los 609
4 Richard MacCutchan 560

Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 22 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100