Click here to Skip to main content
Rate this: bad
good
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 9:08am
Edited 8-Dec-09 11:25am
v2
Rate this: bad
good
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 :
[DllImport("User32")]
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.
  Permalink  
Rate this: bad
good
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);
      }
      
      [DllImport("user32.dll")]
      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 www.pinvoke.net.
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
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 OriginalGriff 200
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 22 Aug 2012
Copyright © CodeProject, 1999-2014
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