Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been trying to send a focused window to the second monitor using the keyboard combination keys Shift+Win+LEFT using sendkeys in c#, but for some reason the window isn't moving to the second monitor. It works when I physically press on these keys on the keyboard but not pragmatically. Note I already know how to bring my desired window to foreground and it's working fine now I wanna send that desired window to the second monitor using the keyboard combination using c# Shift+Win+LEFT I don't want to use the SetWindowPos(proceso.MainWindowHandle, 0, monitor.Left, monitor.Top, monitor.Width, monitor.Height, 0);

here are my attempts that I've tried Thank you in advance looking forward for your help btw I'm still searching and trying.

What I have tried:

trial 1:
C#
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}");
}


trail 2:
C#
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}");
}


trial 3:
C#
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}");
}


trial 4:
C#
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}");
}


trial 5:
C#
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("+(^{ESC}){LEFT}");
}
Posted
Updated 17-Jan-18 1:16am

This SO post could be of help: Sending Windows key using SendKeys[^]
Someone suggested that the Windows key is the same as the Ctrl+Esc keys combination.
So maybe that would do the trick:
C#
SendKeys.Send("+(^{ESC}{LEFT})");

This is marginally distinct from your fifth trial, but that is what I understand from SendKeys.Send Method (String)[^] about the syntax for keys combinations.
If that does not work, then you could have a look to InputSimulator (Codeplex)[^] as suggested in SO post.
I cannot test it on my actual computer, sorry for that. Hope it will guide you towards right direction, though.
Kindly.
 
Share this answer
 
Comments
mocodeproject 17-Jan-18 0:54am    
Thank you for your reply, I've actually tried the
SendKeys.Send("+(^{ESC}{LEFT})");
but still no luck, I think the operating system isn't translating the
^{ESC}
to be the same as when actually pressing the windows start key on the keyboard because when I physically press on those key on the physical keyboard the foreground focused window doesn't move to the secondary monitor. I'm going to try the http://inputsimulator.codeplex.com/ link and see if the simulated keys fix this problem or not.
Thank you for your reply, I've actually tried the
C#
SendKeys.Send("+(^{ESC}{LEFT})");
but still no luck, I think the operating system isn't translating the
C#
^{ESC}
to be the same as when actually pressing the windows start key on the keyboard because when I physically press on those key on the physical keyboard the foreground focused window doesn't move to the secondary monitor. I'm going to try the http://inputsimulator.codeplex.com/ link and see if the simulated keys fix this problem or not.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900