-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
87 lines (70 loc) · 2.97 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MudFish
{
public partial class Form1 : Form
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
private static extern void SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll", EntryPoint = "GetForegroundWindow", SetLastError = true)]
private static extern IntPtr GetForegroundWindow();
public Config MudFishConfig=new Config();
public Form1()
{
InitializeComponent();
RefreshConfig();
}
private void btn_loopjump_Click(object sender, EventArgs e)
{
if (btn_loopjump.Text == "开始")
{
btn_loopjump.Text = "停止";
timer_jump.Enabled = true;
}
else {
btn_loopjump.Text = "开始";
timer_jump.Enabled = false;
}
}
//刷新配置
private void RefreshConfig() {
MudFishConfig.IntervalTime = Convert.ToInt32(nudIntervalTime.Value);
MudFishConfig.WndSwitchTime = Convert.ToInt32(nudWndSwitchTime.Value);
}
private void timer_jump_Tick(object sender, EventArgs e)
{
RefreshConfig();
timer_jump.Interval = MudFishConfig.IntervalTime*1000;
IntPtr hwndTargetWOW = FindWindow(null, "魔兽世界"); //查找魔兽窗口句柄
IntPtr hwndSource = GetForegroundWindow();//查找当前窗口句柄,方便返回。
if (hwndTargetWOW != IntPtr.Zero)
{
SetForegroundWindow(hwndTargetWOW); //将魔兽窗口设为当前活动窗口
System.Threading.Thread.Sleep(MudFishConfig.WndSwitchTime);
//给哥跳一下
SendKeys.SendWait(" ");
System.Threading.Thread.Sleep(MudFishConfig.WndSwitchTime);
}
else {
return;
}
//返回之前的窗口
if (hwndSource != IntPtr.Zero)
{
SetForegroundWindow(hwndSource);
}
}
}
}