[help]key trigger

Posts 1–12 of 12 · Page 1 of 1
[help]key trigger
hi, i'm almost done with my first c++ project, a glitch-tool
i just haven't found a way to trigger my program with a keyboard
can you help me?
Code:
if(GetAsyncKeyState(VK_NUMPAD0)&1)
{
    //code goes here
}
Yeah that's just about it
is this good (correct my errors plz)
Code:
#include <windows.h>

int main()
if(GetAsyncKeyState(VK_NUMPAD1)&1)
	bool Project = true
else 
	if (GetAsyncKeyState (VK_NUMPAD0)&1)
		bool Project = false
if Project = true
	{
		for(;;){
			Sleep(100);
			keybd_event(VkKeyScan('z'),0,0,0);
			keybd_event(VkKeyScan('s'),0,0,0);
		}
		return 0;
	}
if Project = false
	{	
		for(;;){
			Sleep(100);
			keybd_event(VkKeyScan('z'),0,0,0);
			keybd_event(VkKeyScan('s'),0,0,0);
		}
	}
Quote Originally Posted by woodz View Post
is this good (correct my errors plz)
The Problem isn't so much ur logic as it just seems you don't know how to write code. This will not even compile. You should be able to fix the compile errors u get for yourself. It's going to say something along the lines of:
"in function main int val is not returned."
That is because you did not put all of the lines of execution in brackets. Therefore only the first line will be executed o_O... and that line does not return an int. Also its incorrect. You did not put a semicolon on the line after ur if statement. The problem is you don't know how to program, and ur failure at these points reveals a weak grasp on the elementary concepts such as control, flow, and structure. However ur logic is there. I recommend reading the first chapter of any programming book and completing the first program, usually called: "hello world". It's a shame your going get stuck on little details when ur logic is very sound for someone just starting out. You have potential...
Quote Originally Posted by why06 View Post
The Problem isn't so much ur logic as it just seems you don't know how to write code. This will not even compile. You should be able to fix the compile errors u get for yourself. It's going to say something along the lines of:
"in function main int val is not returned."
That is because you did not put all of the lines of execution in brackets. Therefore only the first line will be executed o_O... and that line does not return an int. Also its incorrect. You did not put a semicolon on the line after ur if statement. The problem is you don't know how to program, and ur failure at these points reveals a weak grasp on the elementary concepts such as control, flow, and structure. However ur logic is there. I recommend reading the first chapter of any programming book and completing the first program, usually called: "hello world". It's a shame your going get stuck on little details when ur logic is very sound for someone just starting out. You have potential...
i did the hello world, i just need to reread my code next time to look for those errors.
thanx for the compliments btw
Quote Originally Posted by woodz View Post
is this good (correct my errors plz)
Code:
#include <windows.h>

int main()
if(GetAsyncKeyState(VK_NUMPAD1)&1)
	bool Project = true
else 
	if (GetAsyncKeyState (VK_NUMPAD0)&1)
		bool Project = false
if Project = true
	{
		for(;;){
			Sleep(100);
			keybd_event(VkKeyScan('z'),0,0,0);
			keybd_event(VkKeyScan('s'),0,0,0);
		}
		return 0;
	}
if Project = false
	{	
		for(;;){
			Sleep(100);
			keybd_event(VkKeyScan('z'),0,0,0);
			keybd_event(VkKeyScan('s'),0,0,0);
		}
	}
Fixed and added comments for you
Code:
#include <windows.h>

bool Running;

int main(){
	while (true){ //infinite loop
		if(GetAsyncKeyState(VK_NUMPAD1)&1)//if numpad1 is pressed start pressing keys
			Running = true;
		while (Running) { //as long as Running == true, will continue to press buttons
			keybd_event(VkKeyScan('z'),0,0,0);
			keybd_event(VkKeyScan('z'),0,KEYEVENTF_KEYUP,0);//lifts up z key
			keybd_event(VkKeyScan('s'),0,0,0);
			keybd_event(VkKeyScan('s'),0,KEYEVENTF_KEYUP,0); //lifts up s key
			Sleep(100);
			if (GetAsyncKeyState(VK_NUMPAD0)&1)
				Running = false; // if you press numpad0 it will stop pressing buttons
		}
	}
	return 1; //although this will never be reached because of the infinite loop, it is necessary...
}
Quote Originally Posted by danng4280 View Post
Fixed and added comments for you
Code:
#include <windows.h>

bool Running;

int main(){
	while (true){ //infinite loop
		if(GetAsyncKeyState(VK_NUMPAD1)&1)//if numpad1 is pressed start pressing keys
			Running = true;
		while (Running) { //as long as Running == true, will continue to press buttons
			keybd_event(VkKeyScan('z'),0,0,0);
			keybd_event(VkKeyScan('z'),0,KEYEVENTF_KEYUP,0);//lifts up z key
			keybd_event(VkKeyScan('s'),0,0,0);
			keybd_event(VkKeyScan('s'),0,KEYEVENTF_KEYUP,0); //lifts up s key
			Sleep(100);
			if (GetAsyncKeyState(VK_NUMPAD0)&1)
				Running = false; // if you press numpad0 it will stop pressing buttons
		}
	}
	return 1; //although this will never be reached because of the infinite loop, it is necessary...
}

intialize running as false o.O?
Quote Originally Posted by zhaoyun333 View Post
intialize running as false o.O?
Lol oops, I'm used to java where it is initialized as false nice catch
Code:
#include <windows.h>

bool Running;

int main(){
	Running = false;
	while (true){ //infinite loop
		if(GetAsyncKeyState(VK_NUMPAD1)&1)//if numpad1 is pressed start pressing keys
			Running = true;
		while (Running) { //as long as Running == true, will continue to press buttons
			keybd_event(VkKeyScan('z'),0,0,0);
			keybd_event(VkKeyScan('z'),0,KEYEVENTF_KEYUP,0);//lifts up z key
			keybd_event(VkKeyScan('s'),0,0,0);
			keybd_event(VkKeyScan('s'),0,KEYEVENTF_KEYUP,0); //lifts up s key
			Sleep(100);
			if (GetAsyncKeyState(VK_NUMPAD0)&1)
				Running = false; // if you press numpad0 it will stop pressing buttons
		}
	}
	return 1; //although this will never be reached because of the infinite loop, it is necessary...
}
i fixed it,
now there is this:

what do i do? (my first dll)
hit f7 instead of f5.... there's no need to debug it. Well there is but I would just test it by injecting it into ur game manually.
Oh god, that looks like a mix of C++, VB and brainphuck >.>
Do as why says(no idea what he says, but im sure it contains valuable information)
Posts 1–12 of 12 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us