Making a Toggle

Posts 1–2 of 2 · Page 1 of 1
Making a Toggle
I was making a toggle for a rapid fire hack. I don't know how to make an ON and OFF (Single Key Toggle Of/Off) for it though. I tried googling and some were quite confusing. I'm just a beginner at C++.

Code:
#include <iostream>
#include <Windows.h>
using namespace std;

int main()
{
	//Variables
	static bool x = false;

	while (true){
		//Button Pressed (Home Key)
		if (GetAsyncKeyState(0x24) & 1){
			x = !x;
			cout << '\a' << endl;
			cout << "ON" << endl;
		}
	}
	cin.get();
	return 0;
}
I want to have a cmd that has the text saying ON and OFF also d:^)
You could just put an if-else statement inside your if statement.

Code:
		//Button Pressed (Home Key)
		if (GetAsyncKeyState(0x24) & 1){
			x = !x; // change the state of x

                        if ( x ) 
                            cout << "on" << endl;
                        else
                            cout << "off" << endl;
		}
Side note: it's typically bad practice to use "using namespace std;"

Side Side not: this is going to run indefinitely.
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us