Results 1 to 6 of 6
  1. #1
    KappaMang's Avatar
    Join Date
    Mar 2016
    Gender
    male
    Posts
    242
    Reputation
    10
    Thanks
    16
    My Mood
    Asleep

    Keystates in a Windows Form App?

    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.

    Code:
    if (BhopChkBox.Checked && Keyboard.IsKeyDown(Keys.Space))
                    {
                        bHop.HOP(fProcess);
                    }
    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. :/

  2. #2
    Sammy's Avatar
    Join Date
    Mar 2016
    Gender
    male
    Location
    Vaero
    Posts
    1,102
    Reputation
    224
    Thanks
    228
    Is the process of bhop a loop? It would explain why.

  3. #3
    KappaMang's Avatar
    Join Date
    Mar 2016
    Gender
    male
    Posts
    242
    Reputation
    10
    Thanks
    16
    My Mood
    Asleep
    THIS CAN BE CLOSED I FINALLY FIXED MY PROBLEM *-*

  4. #4
    Sammy's Avatar
    Join Date
    Mar 2016
    Gender
    male
    Location
    Vaero
    Posts
    1,102
    Reputation
    224
    Thanks
    228
    Quote Originally Posted by KappaMang View Post
    THIS CAN BE CLOSED I FINALLY FIXED MY PROBLEM *-*
    Care to explain what you fixed?

  5. #5
    KappaMang's Avatar
    Join Date
    Mar 2016
    Gender
    male
    Posts
    242
    Reputation
    10
    Thanks
    16
    My Mood
    Asleep
    Quote Originally Posted by Sir Sam View Post
    Care to explain what you fixed?
    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:

    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);
                }
            }
    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.

  6. #6
    twas brillig's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Southeastern USA
    Posts
    54
    Reputation
    10
    Thanks
    77
    My Mood
    Amused
    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.

Similar Threads

  1. what do i save a windows form applications as?
    By g0t5k111z2 in forum Visual Basic Programming
    Replies: 3
    Last Post: 07-01-2010, 04:46 PM
  2. Windows form come up after inject?
    By Ragehax in forum C++/C Programming
    Replies: 0
    Last Post: 04-13-2010, 05:57 AM
  3. [Tutorial] How to change colors in DotNetBar for Windows Forms
    By Invidus in forum Visual Basic Programming
    Replies: 7
    Last Post: 02-27-2010, 11:20 PM
  4. [Help]About.vb Windows Form
    By LetItRock in forum Visual Basic Programming
    Replies: 12
    Last Post: 11-12-2009, 08:36 AM
  5. Windows Forms(C++) and etc.
    By zeco in forum C++/C Programming
    Replies: 3
    Last Post: 08-09-2009, 09:52 PM