Question

I have 2 screens connected to my computer. I also have a HotKey control that can trigger a function call in my application even when it is not focused.

I need to do the following. When I start my C# application, my mouse should be locked only to the current screen (meaning that it shouldn't be able to go on to the other screen). On pressing the HotKey, it should be get locked onto the second screen and not be able to move on the first screen. So basically the HotKey (essentially a function call) should allow toggling between the two screens and restricting mouse movement only to that screen.

Is there any way I can accomplish this?

Was it helpful?

Solution

You can use Cursor.Clip property. E.g.Cursor.Clip = Screen.PrimaryScreen.WorkingArea

Without WinForms you can use ClipCursor function:

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool ClipCursor(ref RECT rcClip);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top