C# 連點 SPACEBAR
說明
這個程式能夠模擬連續點擊空白鍵的效果
在程式中添加了多執行緒的效果
讓 UI 不會在連點的情況下
造成 UI 的卡頓
不過這個並不是驅動級別的方式
所以有些遊戲並不會偵測到連點的效果
程式碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MHWI_Steam_Engine
{
public partial class Form1 : Form
{
Thread Click_Thread;
ManualResetEvent shutdownEvent;
public class KeyBoard
{
public const byte vKeySpace = 0x20; // SPACEBAR 鍵
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
public static void keyPress(byte keyName)
{
KeyBoard.keybd_event(keyName, 0, 0, 0);
KeyBoard.keybd_event(keyName, 0, 2, 0);
}
}
public void Click()
{
while (true)
{
if (shutdownEvent.WaitOne(0)) break;
Thread.Sleep(1000);
KeyBoard.keyPress(KeyBoard.vKeySpace);
}
}
public Form1()
{
InitializeComponent();
}
private void Start_button_Click(object sender, EventArgs e)
{
shutdownEvent = new ManualResetEvent(false);
Click_Thread = new Thread(Click);
Click_Thread.IsBackground = true;
Click_Thread.Start();
}
private void Stop_button_Click(object sender, EventArgs e)
{
// trigger stop
shutdownEvent.Set();
Click_Thread.Join();
}
}
}