Is the process of bhop a loop? It would explain why.
In my program, I need to access the keystate of the spacebar. My program is a windows form app, and I am pressing space in a different window. I've tried many different workarounds; nothing has worked. I know that the function I'm accessing is working, because when I remove the key check, I infinitely jump in game. I only want to jump if I am holding space bar.
The key state check may look weird because I use a custom class which I found online. I have tried System.Windows.Input, but that does not work either. :/Code:if (BhopChkBox.Checked && Keyboard.IsKeyDown(Keys.Space)) { bHop.HOP(fProcess); }
Is the process of bhop a loop? It would explain why.
THIS CAN BE CLOSED I FINALLY FIXED MY PROBLEM *-*
Originally I tried making a thread for my BHOP function but I kept messing it up (not used to C# much).
When I finally got the thread working, my function looked like this:
So the thread starts, it runs infinitely (while true), and if the bhop setting is checked and I am pressing space, it will actually do the code. IDK why it worked then, but it did.Code:public void HOP() { while (true) { if (BhopChkBox.Checked && Keyboard.IsKeyDown(System.Windows.Forms.Keys.Space)) { myPlayer.Read_BHOP(); if (myPlayer.m_fFlags == 257 || myPlayer.m_fFlags == 263) { myPlayer.fProcess.WriteInt("client.dll", (int)Offsets.Default.Jump, 1); Thread.Sleep(1); myPlayer.fProcess.WriteInt("client.dll", (int)Offsets.Default.Jump, 0); } } Thread.Sleep(1); } }
The problem is very simple. Your GUI is running on one thread throughout the life of its' execution. You are trying to manipulate memory and do other things on the same thread as the GUI. You should get in the habit of separating your GUI code from your "working" code. What you have here is not a "fix". You have a program with a race condition liable to happen at any given point in time which means your program will inevitably crash. The Thread.Sleep(1) is a big no-no in the community. It is highly frowned upon due to its unpredictable behavior.
Software Developer, Educator, and Gamer.