Question

my code is:

protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
    if (keyData == (Keys.LWin | Keys.M))
    {
        MessageBox.Show("LWin M");
        return true;
    }
    return base.ProcessCmdKey(ref msg, keyData);
}

private void Form1_Load(object sender, EventArgs e)
{
    this.FormBorderStyle = FormBorderStyle.None;
}

but the MessageBox.Show("LWin M"); never work,who can help me?thanks

update

the

MessageBos.Show("LWin M"); 

just for test ,the real code is:

this.WindowState = FormWindowState.Minimized;
Was it helpful?

Solution

This doesn't have anything to do with the FormBorderStyle, your code doesn't work when you omit the Load event as well. The Win + M shortcut keystroke is used by Windows before it sends it to a program. You can easily tell what it does, it minimizes the active window.

Never use the Windows key for your own shortcuts, you'll need to stick with Ctrl, Alt and Shift. Even using unassigned shortcuts is a Bad Idea, that will break in the next Windows version.

OTHER TIPS

it depends what you want

if you want to check if "M" or "LWin" is pressed than try the following part:

if (keyData == Keys.LWin || keyData == Keys.M)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top