打开开始菜单 [英] Open Start Menu

查看:99
本文介绍了打开开始菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中打开开始菜单?请帮助我

How do I open the start menu in C#? Please help me

推荐答案

将此添加到标题中:
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.


这可以通过将"Ctrl + Esc"发送到系统来完成,就好像它是通过按下Windows键(或Ctrl + Esc在键盘上生成)一样旧式键盘).

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



此解决方案是使用位于以下位置的文档开发的:
使用keybd_event()函数进行键盘事件模拟 [



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.


感谢您引用代码.这真的很有帮助.现在我也可以做其他键了.
Thanks for referencing your code. It was really helpful. Now i can do for other keys too.


这篇关于打开开始菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆