Прежде всего, я очень плохо знаком с кодированием, но все равно спрошу. Я получил источник от друга для ключевого редактора игры, которая нам обоим нравится. Это был очень простой c тот, который нажимает только цифры. Я выяснил, как добавить другие нажатия клавиш, такие как Enter и Arrow up et c. Но когда я пытаюсь заставить его работать с обычными буквами, это не так. Я искал в Интернете все, я действительно пытался понять, что мне не хватает, я пытался выяснить это в течение последних 3 дней, но я понимаю, что мне не нужно подбирать опыт.
Так скажет ли мне какая-нибудь добрая душа, чего мне не хватает? Есть ли разница в использовании sendmessage WM_KEYDOWN для цифр или букв?
Почему не добавляются буквы, которые я добавляю?
Я даже пытался убить HackShield игры, думая, что он может заблокировать его, но это не помогло.
Как я уже сказал, это очень ново для меня, и просто пытаюсь понять это с помощью здравый смысл возлагал большие надежды ... Итак, коллеги-программисты, поделитесь своими знаниями со мной.
Если я пропустил что-то важное, пожалуйста, скажите мне.
Я удалил некоторые части, поэтому код не становится длинным.
С уважением, Эрик.
Gastly.cs
internal class Gastly
{
private IntPtr window;
public void _SendMessage (IntPtr handle, int Msg, int wParam, int lParam)
{
SendMessage(handle, Msg, wParam, lParam);
}
[DllImport("user32.dll", SetLastError = true)]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int processId);
public void KeyPress(string number)
{
if (number == "1") // **THIS WORKS** the key 1 gets pressed inside game
{
SendMessage(this.window, 0x100, (IntPtr)0x31, (IntPtr)0x101);
}
if (number == "w") // **THIS WORKS** the key 1 get pressed inside the game (Using the vkCode of 1 here, just testing)
{
SendMessage(this.window, 0x100, (IntPtr)0x31, (IntPtr)0x101);
}
if (number == "numlock")//**THIS WORKS** the key numlock gets pressed inside the game
{
SendMessage(this.window, 0x100, (IntPtr)0x90, (IntPtr)0x101);
}
if (number == "w") // **THIS DOES NOT WORK?!** As soon as i use a vkCode for a letter it gives me nothing inside the game
{
SendMessage(this.window, 0x100, (IntPtr)0x57, (IntPtr)0x101);
}
public void Kill()
{
int num;
int windowThreadProcessId = (int)GetWindowThreadProcessId(this.window, out num);
Process.GetProcessById(num).Kill();
}
public int MakeLParam(int LoWord, int HiWord) =>
(LoWord | (HiWord << 0x10));
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
public void setWindow(IntPtr window)
{
this.window = window;
}
public enum WMessages
{
WM_KEYDOWN = 0x100,
WM_KEYUP = 0x101
}
}
interceptkeys.cs
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace JustNull
{
class InterceptKeys
{
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;
private const int WM_ALTDOWN = 0x0104;
private static LowLevelKeyboardProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero;
public static void Start()
{
_hookID = SetHook(_proc);
}
public static void Stop()
{
UnhookWindowsHookEx(_hookID);
}
public static event KeyEventHandler OnKeyDown;
private static IntPtr SetHook(LowLevelKeyboardProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
GetModuleHandle(curModule.ModuleName), 0);
}
}
private delegate IntPtr LowLevelKeyboardProc(
int nCode, IntPtr wParam, IntPtr lParam);
private static IntPtr HookCallback(
int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_ALTDOWN))
{
var vkCode = (Keys)Marshal.ReadInt32(lParam);
OnKeyDown(null, new KeyEventArgs(vkCode));
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook,
LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
}
}
KageForm .cs
namespace JustNull
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
public class KageForm : Form
{
private IContainer components = null;
private Button f8button;
private Gastly gastly = new Gastly();
private TextBox handlerBox;
private int index;
private string instructions = "";
private RichTextBox instructionsDisplay;
private TextBox instructionsField;
private Jigglypuff jigglypuff = new Jigglypuff();
private Point point = new Point();
private bool running = false;
private Button startButton;
private Thread worker;
private bool choosing_key = false;
private Button button1;
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private bool chosen_key = false;
public KageForm()
{
this.InitializeComponent();
this.worker = new Thread(new ThreadStart(this.PerformMacro));
this.worker.IsBackground = true;
this.worker.Start();
this.index = Program.dittos.Count;
this.Text = "JustNull - " + this.index;
this.instructionsDisplay.Hide();
this.instructionsDisplay.Enabled = false;
JustNull.InterceptKeys.OnKeyDown += new KeyEventHandler(onGlobalKeypress);
JustNull.InterceptKeys.Start();
}
void onGlobalKeypress(object sender, KeyEventArgs e)
{
if (!chosen_key && !choosing_key)
return;
if (chosen_key && !choosing_key)
{
if (e.KeyCode.ToString().Equals(this.button1.Text))
{
PlayPause();
}
}
else if (!chosen_key && choosing_key)
{
this.button1.Text = e.KeyCode.ToString();
choosing_key = false;
chosen_key = true;
}
else if (chosen_key && choosing_key)
{
if (e.KeyCode.ToString().Equals(this.button1.Text))
return;
this.button1.Text = e.KeyCode.ToString();
choosing_key = false;
chosen_key = true;
}
}
void myKeyDown(object sender, KeyEventArgs e)
{
choosing_key = true;
}
private void Debug(string text)
{
this.startButton.Invoke((Action)(() => this.startButton.Text = text));
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void f8button_Click(object sender, EventArgs e)
{
RegisterHotKey(base.Handle, 1, 0, 0x77);
this.f8button.Enabled = false;
}
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
private IntPtr GetActiveWindow() =>
GetForegroundWindow();
}
public string GetInstructions() =>
this.instructionsField.Text;
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(KageForm));
this.startButton = new System.Windows.Forms.Button();
this.instructionsField = new System.Windows.Forms.TextBox();
this.handlerBox = new System.Windows.Forms.TextBox();
this.f8button = new System.Windows.Forms.Button();
this.instructionsDisplay = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// startButton
//
this.startButton.Enabled = false;
this.startButton.Location = new System.Drawing.Point(12, 12);
this.startButton.Name = "startButton";
this.startButton.Size = new System.Drawing.Size(215, 75);
this.startButton.TabIndex = 0;
this.startButton.Text = "Start";
this.startButton.UseVisualStyleBackColor = true;
this.startButton.Click += new System.EventHandler(this.startButton_Click);
//
// instructionsField
//
this.instructionsField.Location = new System.Drawing.Point(14, 120);
this.instructionsField.Multiline = true;
this.instructionsField.Name = "instructionsField";
this.instructionsField.Size = new System.Drawing.Size(214, 95);
this.instructionsField.TabIndex = 1;
this.instructionsField.TextChanged += new System.EventHandler(this.instructionsField_TextChanged);
//
// handlerBox
//
this.handlerBox.Enabled = false;
this.handlerBox.Location = new System.Drawing.Point(13, 234);
this.handlerBox.Name = "handlerBox";
this.handlerBox.Size = new System.Drawing.Size(169, 20);
this.handlerBox.TabIndex = 2;
this.handlerBox.TextChanged += new System.EventHandler(this.handlerBox_TextChanged);
//
// f8button
//
this.f8button.Location = new System.Drawing.Point(187, 234);
this.f8button.Name = "f8button";
this.f8button.Size = new System.Drawing.Size(40, 23);
this.f8button.TabIndex = 3;
this.f8button.Text = "F8";
this.f8button.UseVisualStyleBackColor = true;
this.f8button.Click += new System.EventHandler(this.f8button_Click);
//
// instructionsDisplay
//
this.instructionsDisplay.Location = new System.Drawing.Point(13, 120);
this.instructionsDisplay.Name = "instructionsDisplay";
this.instructionsDisplay.Size = new System.Drawing.Size(214, 95);
this.instructionsDisplay.TabIndex = 4;
this.instructionsDisplay.Text = "";
this.instructionsDisplay.TextChanged += new System.EventHandler(this.instructionsDisplay_TextChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(136, 270);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 5;
this.button1.UseVisualStyleBackColor = true;
this.button1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.myKeyDown);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 275);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(117, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Button to start program:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(93, 257);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(46, 13);
this.label2.TabIndex = 7;
this.label2.Text = "Optional";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 218);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(225, 13);
this.label3.TabIndex = 8;
this.label3.Text = "Smash that F8 button go to game and click F8";
this.label3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(37, 97);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(169, 13);
this.label4.TabIndex = 9;
this.label4.Text = "Charge your rage to this macro tab";
this.label4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// KageForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(239, 302);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.instructionsDisplay);
this.Controls.Add(this.f8button);
this.Controls.Add(this.handlerBox);
this.Controls.Add(this.instructionsField);
this.Controls.Add(this.startButton);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "KageForm";
this.Text = "JustNull";
this.Load += new System.EventHandler(this.KageForm_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
private void KageForm_Load(object sender, EventArgs e)
{
}
private void instructionsDisplay_TextChanged(object sender, EventArgs e)
{
}
private void instructionsField_TextChanged(object sender, EventArgs e)
{
this.instructions = this.instructionsField.Text.ToString();
}
private void Mock()
{
this.Debug("LOOOL");
}
private void newBtn_Click(object sender, EventArgs e)
{
Program.newDitto();
}
private void Pause()
{
this.startButton.Text = "Start";
this.running = false;
this.instructionsField.Show();
this.instructionsDisplay.Hide();
}
private void PerformMacro()
{
while (true)
{
if (this.running)
{
Action method = null;
this.instructions = this.GetInstructions();
string[] lines = this.instructions.Trim().Split(new char[] { '\n' });
int linecount = 0;
foreach (string str in lines)
{
linecount++;
if (method == null)
{
method = delegate {
this.instructionsDisplay.Clear();
int num = 0;
foreach (string tekstas in lines)
{
num++;
if (num == linecount)
{
int start = this.instructionsDisplay.TextLength;
this.instructionsDisplay.AppendText(tekstas);
int textLength = this.instructionsDisplay.TextLength;
this.instructionsDisplay.Select(start, textLength);
this.instructionsDisplay.SelectionColor = Color.Blue;
this.instructionsDisplay.ScrollToCaret();
this.instructionsDisplay.Select(0, 0);
}
else
{
this.instructionsDisplay.AppendText(tekstas);
}
}
};
}
this.instructionsDisplay.BeginInvoke(method);
if (this.running)
{
string[] strArray = str.Trim().Split(new char[] { ' ' });
if (strArray[0] == "keypress")
{
this.gastly.KeyPress(strArray[1]);
}
if (strArray[0] == "rightclick")
{
if (strArray.Length == 1)
{
this.gastly.RightClick(this.point);
}
else
{
this.gastly.RightClick(new Point(int.Parse(strArray[1]), int.Parse(strArray[2])));
}
}
if (strArray[0] == "leftclick")
{
if (strArray.Length == 1)
{
this.gastly.LeftClick(this.point);
}
else
{
this.gastly.LeftClick(new Point(int.Parse(strArray[1]), int.Parse(strArray[2])));
}
}
if (strArray[0] == "sartditto")
{
KageForm ditto = Program.dittos[int.Parse(strArray[1])];
ditto.BeginInvoke((Action)(() => ditto.Play()));
}
if (strArray[0] == "stopditto")
{
KageForm ditto = Program.dittos[int.Parse(strArray[1])];
ditto.BeginInvoke((Action)(() => ditto.Pause()));
}
if (strArray[0] == "afkcheck")
{
int x = int.Parse(strArray[1]);
int y = int.Parse(strArray[2]);
bool afk = true;
while (afk)
{
afk = this.jigglypuff.ExpectColor(new Point(x, y), strArray[3]);
if (afk == true)
{
KageForm ditto = Program.dittos[int.Parse(strArray[4])];
ditto.BeginInvoke((Action)(() => ditto.Play()));
}
else
{
afk = false;
}
}
}
if (strArray[0] == "wait")
{
int num = 0;
if (strArray.Length > 2)
{
int x = int.Parse(strArray[1]);
int y = int.Parse(strArray[2]);
if (strArray.Length == 5)
{
num = this.timeString(strArray[4]);
}
bool flag = true;
while (flag)
{
flag = this.jigglypuff.ExpectColor(new Point(x, y), strArray[3]);
Thread.Sleep(100);
if (strArray.Length == 5)
{
num -= 100;
if (num <= 0)
{
flag = false;
}
}
}
}
else
{
int num4 = this.timeString(strArray[1]) / 100;
for (int i = 0; (i < num4) && this.running; i++)
{
this.gastly.Wait(100);
}
}
}
if (strArray[0] == "closeclient")
{
this.gastly.Kill();
}
Thread.Sleep(100);
}
}
}
else
{
this.gastly.Wait(100);
}
}
}
private void Play()
{
string[] strArray = this.instructionsField.Text.Trim().Split(new char[] { '\n' });
List<string> list = new List<string>();
foreach (string str in strArray)
{
if (str.Contains("#"))
{
this.Text = this.Text.Replace("JustNull", str.Replace("#", ""));
}
else
{
list.Add(str);
}
}
this.instructionsField.Text = string.Join('\n'.ToString(), list.ToArray());
this.startButton.Text = "Stop";
this.running = true;
this.instructionsField.Hide();
this.instructionsDisplay.Show();
}
private void PlayPause()
{
if (this.running)
{
this.Pause();
}
else
{
this.Play();
}
}
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private void setGastly()
{
}
public void SetInstructions(string instruction)
{
this.instructionsField.Text = instruction;
}
private void startButton_Click(object sender, EventArgs e)
{
this.PlayPause();
}
private int timeString(string masked)
{
if (masked.Contains("y"))
{
masked = masked.Replace("y", "");
return (int.Parse(masked));
}
if (masked.Contains("s"))
{
masked = masked.Replace("s", "");
return (int.Parse(masked) * 0x3e8);
}
if (masked.Contains("m"))
{
masked = masked.Replace("m", "");
return (int.Parse(masked) * 0xea60);
}
return int.Parse(masked);
}
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
protected override void WndProc(ref Message m)
{
if ((m.Msg == 0x312) && (m.WParam.ToInt32() == 1))
{
this.getHwnd();
}
base.WndProc(ref m);
}
private void label1_Click(object sender, EventArgs e)
{
}
public delegate void Action();
private void handlerBox_TextChanged(object sender, EventArgs e)
{
if (!this.startButton.Enabled)
this.startButton.Enabled = true;
}
}
}
Я бы серьезно отнесся к тому парню, который дал бы мне решение изрядной суммы за твою временную работу ...!