如何使用c#中的sendkeys发送键盘组合Shift + Win + LEFT?

时间:2018-01-16 08:39:13

标签: c# keyboard monitor sendkeys

我一直在尝试使用键盘组合键Shift + Win + LEFT使用c#中的sendkeys将焦点窗口发送到第二台显示器,但由于某种原因,窗口没有移动到第二台显示器。当我在键盘上按下这些键但不实用时,它可以正常工作。 注意我已经知道如何将我想要的窗口带到前台并且它正常工作现在我想使用键盘组合使用c#Shift + Win + LEFT将所需窗口发送到第二台显示器我不想要使用SetWindowPos(proceso.MainWindowHandle,0,monitor.Left,monitor.Top,monitor.Width,monitor.Height,0);

这是我尝试过的尝试 感谢您提前寻求您的帮助,我还在寻找和尝试。

试验1:

private void btnSendToSecondDisplay_Click(object sender, EventArgs e)
{
  bringToFront("Task Manager");//This lets the "task manager" window to be in the foreground and has the focus set to it
  SendKeys.Send(Keys.ShiftKey.ToString());
  SendKeys.Send(Keys.LWin.ToString());
  SendKeys.Send("{LEFT}");
}

试验2:

private void btnSendToSecondDisplay_Click(object sender, EventArgs e)
{
  bringToFront("Task Manager");//This lets the "task manager" window to be in the foreground and has the focus set to it
  SendKeys.Send("+"+Keys.LWin.ToString()+"{LEFT}");
}

试验3:

private void btnSendToSecondDisplay_Click(object sender, EventArgs e)
{
  bringToFront("Task Manager");//This lets the "task manager" window to be in the foreground and has the focus set to it
  SendKeys.Send("+"+Keys.LWin.ToString()+"{LEFT}");
}

试验4

private void btnSendToSecondDisplay_Click(object sender, EventArgs e)
{
  bringToFront("Task Manager");//This lets the "task manager" window to be in the foreground and has the focus set to it
  SendKeys.Send("{SHIFTDOWN}");
  SendKeys.Send("{APPSKEY}");
  SendKeys.Send("{LEFT}");
}

试验5

private void btnSendToSecondDisplay_Click(object sender, EventArgs e)
{
  bringToFront("Task Manager");//This lets the "task manager" window to be in the foreground and has the focus set to it
  SendKeys.Send("{SHIFTDOWN}{APPSKEY}{LEFT}");
}

试验6

private void btnSendToSecondDisplay_Click(object sender, EventArgs e)
{
  bringToFront("Task Manager");//This lets the "task manager" window to be in the foreground and has the focus set to it
  SendKeys.Send("+");
  SendKeys.Send(Keys.LWin.ToString());
  SendKeys.Send("{LEFT}");
}

1 个答案:

答案 0 :(得分:0)

来自MSDN

  

要指定在按下其他几个键的同时按住SHIFT,CTRL和ALT的任意组合,请将这些键的代码括在括号中。例如,要指定在按下E和C时按住SHIFT,请使用“+(EC)”。要指定在按下E时按住SHIFT,然后按C而不按SHIFT,请使用“+ EC”。

所以你的代码应该是这样的:

SendKeys.Send("+(^{ESC}{LEFT})");