keylogger c++ help

Hi
I have this question for you, I have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;
int main()
{

fstream plik;
HHOOK hKEYBOARDHOOK =0;
plik.open("keys.txt", std::ios::in | std::ios::out);

LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wPARAM, LPARAM lPARAM)
{

        KBDLLHOOKSTRUCT *pKbdLLHookStruct = (KBDLLHOOKSTRUCT *)lParam;
  if (nCode >= 0)
    {
        if (wParam == WM_KEYUP)
        {
            switch(pKbdLLHookStruct->vkCode)
            {

 case: VK_A out << "A"; break;
}

}

)


And the problem is that there I two errors:
1. C:\Documents and Settings\admin\Pulpit\to i tamto\key\main.cpp|13|error: a function-definition is not allowed here before '{' token|

2. C:\Documents and Settings\admin\Pulpit\to i tamto\key\main.cpp|28|error: expected '}' at end of input|

Does anyone know what could be causing this ?
For clarity, I'm sorry for the spelling mistakes but I'm Polish.
You can't define one function inside other one, you can only call one function from another, but here you have defined LowLevelKeyboarProc function inside main, so that is error. Define it outside of main, then try compiling again.

Also there is an error in line 23, VK_A must be before :

case VK_A : out <<"A"; break;
Last edited on
to help me with this? I am a beginner
You need to define your function outside of main():
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;

//--------------
//declare the function outside of main()
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wPARAM, LPARAM lPARAM);
//--------------


int main()
{

	fstream plik;
	HHOOK hKEYBOARDHOOK =0;
	plik.open("keys.txt", std::ios::in | std::ios::out);
	
	//--------------
	plik.close(); //close the file you opened before exiting your program
	//--------------
	
	return 0;
}

//--------------
//define the function outside of main()
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wPARAM, LPARAM lPARAM) 
{

  KBDLLHOOKSTRUCT *pKbdLLHookStruct = (KBDLLHOOKSTRUCT *)lParam;
  if (nCode >= 0)
    {
        if (wParam == WM_KEYUP)
        {
            switch(pKbdLLHookStruct->vkCode)
            {
		case VK_A: out << "A"; break;
	     }
	}
    }
}
//-------------- 


See: http://www.cplusplus.com/doc/tutorial/functions/
Thanks!
But the revised code after you came to me 4 errors:
1. C:\Documents and Settings\admin\Pulpit\to i tamto\key2\main.cpp|30|error: declaration of 'int wPARAM' shadows a parameter|

2. C:\Documents and Settings\admin\Pulpit\to i tamto\key2\main.cpp|34|error: 'wParam' was not declared in this scope|

3. C:\Documents and Settings\admin\Pulpit\to i tamto\key2\main.cpp|38|error: 'VK_A' cannot appear in a constant-expression|

4. C:\Documents and Settings\admin\Pulpit\to i tamto\key2\main.cpp|38|error: invalid operands of types 'int' and 'const char [2]' to binary 'operator<<'|

HELP !

as well as instructions for the future keylogging always done outside the function int main () right ?
1.
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wPARAM, LPARAM lPARAM)
...Should be...
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam)
2. -> See 1.
3. -> Try to substitute VK_A with 'A' (VK_A does not exist).
4. -> Try to substitute out << "A"; with cout << "A";


EDIT: The example above will print an 'A' to the console every time it is pressed.
Last edited on
THANKS VERY MUCH !!!!!!!!!!!!!!!!
I am grateful ! :D :D
A text file is just a set up when I finish all?
Will be fully written ?
ok there is :D
I UNDERSTAND that the keys will be completed only when the write their entire program right?
Because at the moment the console window after the compiler will not start. As to missing features ("system pause"), but I do not know
Topic archived. No new replies allowed.