Skip to content

Commit d9bbef0

Browse files
committed
Update 2212
Rename project to MouseSwitchER to avoid misunderstanding with switch game console Added clip cursor to screen function
1 parent 20f417e commit d9bbef0

15 files changed

+116
-39
lines changed

AboutPage.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AboutPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Threading.Tasks;
99
using System.Windows.Forms;
1010

11-
namespace MouseSwitch
11+
namespace MouseSwitcher
1212
{
1313
public partial class AboutPage : Form
1414
{
Lines changed: 26 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
using System.Threading.Tasks;
99
using System.Windows.Forms;
1010

11-
namespace MouseSwitch
11+
namespace MouseSwitcher
1212
{
1313
public partial class Config : Form
1414
{
1515
static Config me;
1616
Form1 parent;
1717
public Config(Form1 f)
1818
{
19-
if (me?.Visible==true) me.Close();
19+
if (me?.Visible == true) me.Close();
2020
me = this;
2121
parent = f;
2222
InitializeComponent();
@@ -28,6 +28,10 @@ private void Config_Load(object sender, EventArgs e)
2828
PrevKeyBox.Text = HotKeys.GetKeyName(parent.previous);
2929
NextKeyBox.Text = HotKeys.GetKeyName(parent.next);
3030
shownotify.Checked = parent.shownotifi;
31+
checkBox1.CheckState = parent.doclipcursor ?
32+
(parent.enhancedclip ? CheckState.Checked : CheckState.Indeterminate)
33+
:
34+
CheckState.Unchecked;
3135
}
3236

3337
private void PrevKeyBox_KeyDown(object sender, KeyEventArgs e)
@@ -99,5 +103,12 @@ private void shownotify_CheckedChanged(object sender, EventArgs e)
99103
parent.shownotifi = shownotify.Checked;
100104
parent.SaveConfig();
101105
}
106+
107+
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
108+
{
109+
parent.enhancedclip = checkBox1.CheckState == CheckState.Checked;
110+
parent.doclipcursor = parent.enhancedclip || checkBox1.CheckState == CheckState.Indeterminate;
111+
parent.SaveConfig();
112+
}
102113
}
103114
}
File renamed without changes.

ErrorReport.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ErrorReport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Threading.Tasks;
99
using System.Windows.Forms;
1010

11-
namespace MouseSwitch
11+
namespace MouseSwitcher
1212
{
1313
public partial class ErrorReport : Form
1414
{
Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using System.Linq;
77
using System.Runtime.InteropServices;
88
using System.Windows.Forms;
9-
using static MouseSwitch.HotKeys;
9+
using static MouseSwitcher.HotKeys;
1010

11-
namespace MouseSwitch
11+
namespace MouseSwitcher
1212
{
1313
public class Form1 : Form
1414
{
@@ -33,6 +33,9 @@ public class Form1 : Form
3333
private ToolStripMenuItem 关于AToolStripMenuItem;
3434
private ToolStripMenuItem 退出QToolStripMenuItem;
3535
public bool shownotifi = false;
36+
private Timer clipper;
37+
public bool doclipcursor = false;
38+
public bool enhancedclip = false;
3639

3740
public Form1()
3841
{
@@ -105,6 +108,7 @@ private bool LoadConfig()
105108
next = Keys.Right;
106109
modifier = HotkeyModifiers.Alt;
107110
shownotifi = true;
111+
doclipcursor = false;
108112
return true;
109113
}
110114
else
@@ -115,6 +119,12 @@ private bool LoadConfig()
115119
next = (Keys)jb.Value<int>("next_screen");
116120
modifier = (HotkeyModifiers)jb.Value<int>("modifier");
117121
shownotifi = jb.Value<bool>("notify_when_boot");
122+
if (jb["clip_cursor"] != null)
123+
{
124+
var clip_cursor_str = jb.Value<string>("clip_cursor").ToLower();
125+
doclipcursor = clip_cursor_str.Equals("true") || clip_cursor_str.Equals("enhanced");
126+
enhancedclip = clip_cursor_str.Equals("enhanced");
127+
}
118128
return false;
119129
}
120130
}
@@ -129,13 +139,20 @@ public void SaveConfig()
129139
jb.Add("next_screen", (int)next);
130140
jb.Add("modifier", (int)modifier);
131141
jb.Add("notify_when_boot", shownotifi);
142+
jb.Add("clip_cursor", doclipcursor ? (enhancedclip ? "enhanced" : "true") : "false");
132143
File.WriteAllText("config.json", jb.ToString());
133144
}
134145
}
135146

136147
[DllImport("user32")]
137148
private static extern int SetCursorPos(int x, int y);
138149

150+
[DllImport("user32")]
151+
private static extern bool ClipCursor(Rectangle lpRect);
152+
153+
[DllImport("user32")]
154+
private static extern bool ClipCursor();
155+
139156
public void MouseToPoint(Point p)
140157
{
141158
SetCursorPos(p.X, p.Y);
@@ -153,22 +170,16 @@ public void SetMouseAtCenterScreen(Screen screen)
153170

154171
private int MouseGoto(int ScreenID = 1)
155172
{
156-
int num = 0;
157173
Screen[] allScreens = Screen.AllScreens;
158-
foreach (Screen screen in allScreens)
159-
{
160-
num++;
161-
if (num == ScreenID)
162-
{
163-
SetMouseAtCenterScreen(screen);
164-
number.Text = num.ToString();
165-
base.Left = screen.WorkingArea.X;
166-
base.Top = screen.WorkingArea.Y;
167-
base.Opacity = 0.75;
168-
autohide.Start();
169-
break;
170-
}
171-
}
174+
Screen screen = allScreens[ScreenID - 1];
175+
if (doclipcursor) ClipCursor();
176+
SetMouseAtCenterScreen(screen);
177+
number.Text = (ScreenID).ToString();
178+
base.Left = screen.WorkingArea.X;
179+
base.Top = screen.WorkingArea.Y;
180+
base.Opacity = 0.75;
181+
if (doclipcursor) ClipCursor(screen.Bounds);
182+
autohide.Start();
172183
return allScreens.Count();
173184
}
174185

@@ -263,6 +274,21 @@ private void 关于AToolStripMenuItem_Click(object sender, EventArgs e)
263274
new AboutPage().ShowDialog();
264275
}
265276

277+
private void clipper_Tick(object sender, EventArgs e)
278+
{
279+
if (enhancedclip)
280+
{
281+
Screen[] allScreens = Screen.AllScreens;
282+
Screen screen = allScreens[NowAt - 1];
283+
ClipCursor(screen.Bounds);
284+
}
285+
}
286+
287+
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
288+
{
289+
290+
}
291+
266292
private void InitializeComponent()
267293
{
268294
this.components = new System.ComponentModel.Container();
@@ -276,6 +302,7 @@ private void InitializeComponent()
276302
this.设置SToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
277303
this.关于AToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
278304
this.退出QToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
305+
this.clipper = new System.Windows.Forms.Timer(this.components);
279306
this.contextMenuStrip1.SuspendLayout();
280307
this.SuspendLayout();
281308
//
@@ -326,6 +353,7 @@ private void InitializeComponent()
326353
this.退出QToolStripMenuItem});
327354
this.contextMenuStrip1.Name = "contextMenuStrip1";
328355
this.contextMenuStrip1.Size = new System.Drawing.Size(181, 92);
356+
this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening);
329357
//
330358
// 设置SToolStripMenuItem
331359
//
@@ -348,6 +376,12 @@ private void InitializeComponent()
348376
this.退出QToolStripMenuItem.Text = "退出(&Q)";
349377
this.退出QToolStripMenuItem.Click += new System.EventHandler(this.退出QToolStripMenuItem_Click);
350378
//
379+
// clipper
380+
//
381+
this.clipper.Enabled = true;
382+
this.clipper.Interval = 500;
383+
this.clipper.Tick += new System.EventHandler(this.clipper_Tick);
384+
//
351385
// Form1
352386
//
353387
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@
769769
//////////////////////////////////////////////////8=
770770
</value>
771771
</data>
772+
<metadata name="clipper.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
773+
<value>584, 17</value>
774+
</metadata>
772775
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
773776
<value>
774777
AAABAAEAYGAAAAEAIAColAAAFgAAACgAAABgAAAAwAAAAAEAIAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAA
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Runtime.InteropServices;
44
using System.Windows.Forms;
55

6-
namespace MouseSwitch
6+
namespace MouseSwitcher
77
{
88
public class HotKeys
99
{

0 commit comments

Comments
 (0)